From 8e8f14bcd7e7a6d30535e65e4b73506fb353c535 Mon Sep 17 00:00:00 2001 From: Donatas Adamonis Date: Wed, 24 May 2017 22:26:50 +0200 Subject: begining of comments --- .../ApartmentManager/ApartmentManager.csproj | 1 + .../ApartmentManager/Handler/ApartmentHandler.cs | 52 +++++++-------- .../ApartmentManager/Model/DefectComments.cs | 18 +++++ ApartmentManager/ApartmentManager/Model/User.cs | 9 +-- .../ApartmentManager/Persistency/ApiClient.cs | 15 ++--- .../Singletons/CatalogSingleton.cs | 7 +- .../View/ApartmentDefectPage.xaml.cs | 3 +- .../View/ApartmentDefectViewPage.xaml | 78 +++++++++++++++------- .../ApartmentManager/View/ApartmentNewDefect.xaml | 2 +- .../View/ApartmentResidentsPage.xaml | 4 +- .../ViewModel/ApartmentViewModel.cs | 10 +-- 11 files changed, 128 insertions(+), 71 deletions(-) create mode 100644 ApartmentManager/ApartmentManager/Model/DefectComments.cs diff --git a/ApartmentManager/ApartmentManager/ApartmentManager.csproj b/ApartmentManager/ApartmentManager/ApartmentManager.csproj index e6f14f6..81f44b5 100644 --- a/ApartmentManager/ApartmentManager/ApartmentManager.csproj +++ b/ApartmentManager/ApartmentManager/ApartmentManager.csproj @@ -105,6 +105,7 @@ + diff --git a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs index e59d75f..52310cc 100644 --- a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs @@ -65,7 +65,7 @@ namespace ApartmentManager.Handler Resident resident = new Resident(); resident = ApartmentViewModel.NewResident; resident.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; - + ApiClient.PostData("api/residents/", resident); var residentsFromDatabase = ApiClient.GetData("api/ApartmentResidents/" + resident.ApartmentId); @@ -91,7 +91,7 @@ namespace ApartmentManager.Handler Resident resident = new Resident(); resident = ApartmentViewModel.NewResident; resident.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; - + ApiClient.DeleteData("api/residents/" + resident.ResidentId); var residentsFromDatabase = ApiClient.GetData("api/ApartmentResidents/" + resident.ApartmentId); @@ -116,7 +116,7 @@ namespace ApartmentManager.Handler { Resident resident = new Resident(); resident = ApartmentViewModel.NewResident; - resident.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; + resident.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; ApiClient.PutData("api/residents/" + resident.ResidentId, resident); var residentsFromDatabase = ApiClient.GetData("api/ApartmentResidents/" + resident.ApartmentId); @@ -157,7 +157,7 @@ namespace ApartmentManager.Handler try { ApartmentViewModel.UserSingleton.CurrentUser.Picture = await ImgurPhotoUploader.UploadPhotoAsync(); - + } catch (Exception e) { @@ -170,7 +170,7 @@ namespace ApartmentManager.Handler { User user = new User(); user = ApartmentViewModel.UserSingleton.CurrentUser; - ApiClient.PutData("api/users/" + user.Username, user); + ApiClient.PutData("api/users/" + user.Username, user); } catch (Exception e) { @@ -202,7 +202,7 @@ namespace ApartmentManager.Handler } qwe.MainPicture = ApartmentViewModel.CatalogSingleton.DefectPictures[0].Picture; } - + } @@ -224,9 +224,9 @@ namespace ApartmentManager.Handler try { ApartmentViewModel.SelectedDefectPicture = new DefectPicture(); - + ApartmentViewModel.SelectedDefectPicture.Picture = await ImgurPhotoUploader.UploadPhotoAsync(); - ApartmentViewModel.CatalogSingleton.DefectPictures.Add(ApartmentViewModel.SelectedDefectPicture); + ApartmentViewModel.CatalogSingleton.DefectPictures.Add(ApartmentViewModel.SelectedDefectPicture); } catch (Exception e) { @@ -234,23 +234,23 @@ namespace ApartmentManager.Handler } /////////////////////////////////////////////////////////////////////////////////////////////////// public void CreateDefect() - { - Defect defect = new Defect(); - defect = ApartmentViewModel.NewDefect; - defect.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; - defect.Status = "New"; - defect.UploadDate = DateTime.Now; - - ApiClient.PostData("api/defects/", defect); - defect.DefectId = ApartmentViewModel.ServerResponse; - foreach (var picture in ApartmentViewModel.CatalogSingleton.DefectPictures) - { - picture.DefectId = defect.DefectId; - ApiClient.PostData("api/defectpictures/", picture); - } + { + Defect defect = new Defect(); + defect = ApartmentViewModel.NewDefect; + defect.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; + defect.Status = "New"; + defect.UploadDate = DateTime.Now; + + var response = ApiClient.PostData("api/defects/", defect); + var defectResponse = JsonConvert.DeserializeObject(response); + defect.DefectId = defectResponse.DefectId; - GetApartmentDefects(); - + foreach (var picture in ApartmentViewModel.CatalogSingleton.DefectPictures) + { + picture.DefectId = defect.DefectId; + ApiClient.PostData("api/defectpictures/", picture); + } + GetApartmentDefects(); } /////////////////////////////////////////////////////////////////////////////////////////////////// public bool CreateDefect_CanExecute() @@ -276,13 +276,13 @@ namespace ApartmentManager.Handler if (picturesFromDatabase != "[]") { IEnumerable picturetlist = - JsonConvert.DeserializeObject>(picturesFromDatabase); + JsonConvert.DeserializeObject>(picturesFromDatabase); foreach (var asd in picturetlist) { ApartmentViewModel.CatalogSingleton.DefectPictures2.Add(asd); } - } + } } /////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/ApartmentManager/ApartmentManager/Model/DefectComments.cs b/ApartmentManager/ApartmentManager/Model/DefectComments.cs new file mode 100644 index 0000000..a1e6d1e --- /dev/null +++ b/ApartmentManager/ApartmentManager/Model/DefectComments.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ApartmentManager.Model +{ + public class DefectComments + { + + public int CommentId { get; set; } + public int DefectId { get; set; } + public string Comment { get; set; } + public string Name { get; set; } + public DateTimeOffset Date { get; set; } + } +} diff --git a/ApartmentManager/ApartmentManager/Model/User.cs b/ApartmentManager/ApartmentManager/Model/User.cs index 8543833..e7e43ec 100644 --- a/ApartmentManager/ApartmentManager/Model/User.cs +++ b/ApartmentManager/ApartmentManager/Model/User.cs @@ -10,7 +10,7 @@ using ApartmentManager.Annotations; namespace ApartmentManager.Model { - public class User: INotifyPropertyChanged + public class User : INotifyPropertyChanged { public string Username { get; set; } public int ApartmentId { get; set; } @@ -21,13 +21,14 @@ namespace ApartmentManager.Model public DateTime BirthDate { get; set; } public string Phone { get; set; } public string Email { get; set; } - private string _picture { get; set; } + public string _picture { get; set; } public DateTime? MoveInDate { get; set; } public DateTime? MoveOutDate { get; set; } + public User() { } - public User(string FirstName, string LastName, string Phone, DateTime BirthDate, string Email, int ApartmentNr) + public User(string FirstName, string LastName, string Phone, DateTime BirthDate, string Email) { this.FirstName = FirstName; this.LastName = LastName; @@ -38,7 +39,7 @@ namespace ApartmentManager.Model public string Picture { - get { return _picture; } + get => _picture; set { _picture = value; diff --git a/ApartmentManager/ApartmentManager/Persistency/ApiClient.cs b/ApartmentManager/ApartmentManager/Persistency/ApiClient.cs index 78a5a55..b99f582 100644 --- a/ApartmentManager/ApartmentManager/Persistency/ApiClient.cs +++ b/ApartmentManager/ApartmentManager/Persistency/ApiClient.cs @@ -57,7 +57,7 @@ namespace ApartmentManager.Persistency } } - public static void PostData(string url, object objectToPost) + public static string PostData(string url, object objectToPost) { HttpClientHandler handler = new HttpClientHandler() { UseDefaultCredentials = true }; using (var client = new HttpClient(handler)) @@ -69,15 +69,14 @@ namespace ApartmentManager.Persistency { string serializedData = JsonConvert.SerializeObject(objectToPost); StringContent content = new StringContent(serializedData, Encoding.UTF8, "application/json"); - var response = new HttpResponseMessage(); - response = client.PostAsync(url, content).Result; - var def = JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync().Result); - //var response = client.PostAsync(url, content).Result.Headers.Location.AbsolutePath.Remove(0,13); - ApartmentViewModel.ServerResponse = def.DefectId; + + var response = client.PostAsync(url, content).Result; + string result = response.Content.ReadAsStringAsync().Result; + return result; } catch (Exception) { - + return null; } } } @@ -92,7 +91,7 @@ namespace ApartmentManager.Persistency client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); try { - var response = client.DeleteAsync(url).Result; + var response =client.DeleteAsync(url).Result; } catch (Exception) { diff --git a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs index 050987d..a14c7d5 100644 --- a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs +++ b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs @@ -19,11 +19,16 @@ namespace ApartmentManager.Singletons public ObservableCollection defects { get; set; } public ObservableCollection DefectPictures { get; set; } public ObservableCollection DefectPictures2 { get; set; } + public ObservableCollection DefectComments { get; set; } public Defect Defect { get; set; } private CatalogSingleton() { - + DefectComments = new ObservableCollection(); + DefectComments.Add(new DefectComments( ){Date = DateTimeOffset.Now, Comment = "Comment",CommentId = 1,DefectId = 1,Name = "Name"} ); + DefectComments.Add(new DefectComments() { Date = DateTimeOffset.Now, Comment = "Comment", CommentId = 1, DefectId = 1, Name = "Name" }); + DefectComments.Add(new DefectComments() { Date = DateTimeOffset.Now, Comment = "Comment", CommentId = 1, DefectId = 1, Name = "Name" }); + DefectComments.Add(new DefectComments() { Date = DateTimeOffset.Now, Comment = "Comment", CommentId = 1, DefectId = 1, Name = "Name" }); Residents = new ObservableCollection(); defects = new ObservableCollection(); DefectPictures = new ObservableCollection(); diff --git a/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml.cs b/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml.cs index ee53458..21bc90e 100644 --- a/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml.cs +++ b/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml.cs @@ -38,8 +38,7 @@ namespace ApartmentManager.View private void NavigateDefect(object sender, RoutedEventArgs e) { - vm.DefectInfo.Execute(null); - //vm.ApartmentHandler.GetDefectInfo(); + vm.DefectInfo.Execute(null); Frame.Navigate(typeof(ApartmentDefectViewPagexaml)); } } diff --git a/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPage.xaml b/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPage.xaml index 0da2b73..2c7e322 100644 --- a/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPage.xaml +++ b/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPage.xaml @@ -13,37 +13,69 @@ - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + - - - - - - - - - - - + diff --git a/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml b/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml index fa4862e..c68a36d 100644 --- a/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml +++ b/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml @@ -40,7 +40,7 @@ - +