From 4db2836f85399fb5e14272354a2cdc1058de1ef0 Mon Sep 17 00:00:00 2001 From: Donatas Adamonis Date: Wed, 31 May 2017 00:18:44 +0200 Subject: apartment defects done --- .../ApartmentManager/Handler/ApartmentHandler.cs | 51 ++---- .../Singletons/CatalogSingleton.cs | 10 +- .../ApartmentManager/View/ApartmentDefectPage.xaml | 194 ++++++++++----------- .../View/ApartmentDefectPage.xaml.cs | 9 +- .../View/ApartmentDefectViewPage.xaml | 27 ++- .../View/ApartmentDefectViewPage.xaml.cs | 5 + .../ApartmentManager/View/ApartmentNewDefect.xaml | 18 +- .../View/ApartmentNewDefect.xaml.cs | 5 + .../ApartmentManager/View/BmDefectsPage.xaml | 4 + .../ViewModel/ApartmentViewModel.cs | 6 +- 10 files changed, 167 insertions(+), 162 deletions(-) diff --git a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs index 4cfa4fd..41b9cda 100644 --- a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs @@ -170,24 +170,20 @@ namespace ApartmentManager.Handler Defect.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; var defectsFromDatabase = ApiClient.GetData("api/ApartmentDefects/" + Defect.ApartmentId); var defecttlist = JsonConvert.DeserializeObject>(defectsFromDatabase); + CatalogSingleton.Instance.Defects.Clear(); foreach (var defect in defecttlist) { - var picturesFromDatabase = ApiClient.GetData("api/DefectPicturesById/" + defect.DefectId); - if (picturesFromDatabase != "[]") - { - ApartmentViewModel.CatalogSingleton.DefectPictures = JsonConvert.DeserializeObject>(picturesFromDatabase); - defect.MainPicture = ApartmentViewModel.CatalogSingleton.DefectPictures[0].Picture; - } + defect.Pictures = JsonConvert.DeserializeObject>(ApiClient.GetData("api/DefectPicturesById/" + defect.DefectId)); + defect.Comments = JsonConvert.DeserializeObject>(ApiClient.GetData("api/DefectComments/" + defect.DefectId)); + CatalogSingleton.Instance.Defects.Add(defect); } - ApartmentViewModel.CatalogSingleton.Defects = defecttlist; - ApartmentViewModel.CatalogSingleton.DefectPictures.Clear(); } /////////////////////////////////////////////////////////////////////////////////////////////////// public void DeleteDefectPicture() { try { - ApartmentViewModel.CatalogSingleton.DefectPictures.Remove(ApartmentViewModel.SelectedDefectPicture); + ApartmentViewModel.NewDefect.Pictures.Remove(ApartmentViewModel.SelectedDefectPicture); } catch (Exception e) { @@ -198,8 +194,9 @@ namespace ApartmentManager.Handler { try { - ApartmentViewModel.SelectedDefectPicture.Picture = await ImgurPhotoUploader.UploadPhotoAsync(); - ApartmentViewModel.CatalogSingleton.DefectPictures.Add(ApartmentViewModel.SelectedDefectPicture); + if (ApartmentViewModel.NewDefect.Pictures == null) ApartmentViewModel.NewDefect.Pictures = new ObservableCollection(); + var picture = new DefectPicture() { Picture = await ImgurPhotoUploader.UploadPhotoAsync() }; + ApartmentViewModel.NewDefect.Pictures.Add(picture); } catch (Exception e) { @@ -218,7 +215,7 @@ namespace ApartmentManager.Handler var response = ApiClient.PostData("api/defects/", defect); var defectResponse = JsonConvert.DeserializeObject(response); defect.DefectId = defectResponse.DefectId; - foreach (var picture in ApartmentViewModel.CatalogSingleton.DefectPictures) + foreach (var picture in defect.Pictures) { picture.DefectId = defect.DefectId; ApiClient.PostData("api/defectpictures/", picture); @@ -238,26 +235,7 @@ namespace ApartmentManager.Handler return false; else return true; - } - /////////////////////////////////////////////////////////////////////////////////////////////////// - public void GetDefectInfo() - { - try - { - var defectFromDatabase = ApiClient.GetData("api/defects/" + ApartmentViewModel.NewDefect.DefectId); - ApartmentViewModel.CatalogSingleton.Defect = JsonConvert.DeserializeObject(defectFromDatabase); - var picturesFromDatabase = ApiClient.GetData("api/DefectPicturesById/" + ApartmentViewModel.NewDefect.DefectId); - ApartmentViewModel.CatalogSingleton.DefectPictures = JsonConvert.DeserializeObject>(picturesFromDatabase); - var defectComments = ApiClient.GetData("api/Defectcomments/" + ApartmentViewModel.NewDefect.DefectId); - ApartmentViewModel.CatalogSingleton.DefectComments = JsonConvert.DeserializeObject>(defectComments); - CatalogSingleton.Instance.DefectId = ApartmentViewModel.NewDefect.DefectId; - } - catch (Exception e) - { - new MessageDialog(e.Message).ShowAsync(); - } - - } + } /////////////////////////////////////////////////////////////////////////////////////////////////// public void CreateDefectComment() { @@ -265,19 +243,20 @@ namespace ApartmentManager.Handler { DefectComment Comment = new DefectComment(); Comment.Comment = ApartmentViewModel.NewDefectComment.Comment; - Comment.DefectId = CatalogSingleton.Instance.Defect.DefectId; + Comment.DefectId = CatalogSingleton.Instance.SelectedDefect.DefectId; Comment.Name = UserSingleton.Instance.CurrentUser.FirstName + " " + UserSingleton.Instance.CurrentUser.LastName; Comment.Date = DateTimeOffset.Now; if (!string.IsNullOrEmpty(Comment.Comment)) { ApiClient.PostData("api/Defectcomments/", Comment); } - var response = ApiClient.GetData("api/Defectcomments/" + CatalogSingleton.Instance.DefectId); + var response = ApiClient.GetData("api/Defectcomments/" + CatalogSingleton.Instance.SelectedDefect.DefectId); var commentlist = JsonConvert.DeserializeObject>(response); - CatalogSingleton.Instance.DefectComments.Clear(); + + CatalogSingleton.Instance.SelectedDefect.Comments.Clear(); foreach (var comment in commentlist) { - CatalogSingleton.Instance.DefectComments.Add(comment); + CatalogSingleton.Instance.SelectedDefect.Comments.Add(comment); } } catch (Exception e) diff --git a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs index 6baa647..a05c01a 100644 --- a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs +++ b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs @@ -18,17 +18,13 @@ namespace ApartmentManager.Singletons public ObservableCollection Residents { get; set; } ////////// For Defects ////////// public ObservableCollection Defects { get; set; } - public ObservableCollection DefectPictures { get; set; } - public ObservableCollection DefectComments { get; set; } - public Defect Defect { get; set; } - public int DefectId { get; set; } + public Defect SelectedDefect { get; set; } ////////// Constructor ////////// private CatalogSingleton() - { - DefectComments = new ObservableCollection(); + { Residents = new ObservableCollection(); Defects = new ObservableCollection(); - DefectPictures = new ObservableCollection(); + SelectedDefect = new Defect(); } } } diff --git a/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml b/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml index 7b4a853..f2f0755 100644 --- a/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml +++ b/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml @@ -6,141 +6,131 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="using:ApartmentManager.View" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:interactivity="using:Microsoft.Xaml.Interactivity" + xmlns:core="using:Microsoft.Xaml.Interactions.Core" mc:Ignorable="d"> - + + + + + + + + + + + + + + - - + + + + + - - - - - - - - - - - - - - - - - - + Text="Apartment Defects"> + + + + + + + + + + + + + + + + + + + + + Margin="0,0,10,0" + FontSize="30" + FontWeight="Bold" + Text="Name :"> + + Margin="0,0,10,0" + FontSize="30" + Text="{Binding Name}"> + + Width="800" + Height="108" + Margin="0,0,10,0" + FontSize="20" + Text="{Binding Description}" + TextWrapping="Wrap"> + - + + Margin="0,0,10,0" + FontSize="25" + FontWeight="Bold" + Text="Status :"> + + Margin="0,0,10,0" + FontSize="25" + Text="{Binding Status}"> + + Margin="700,0,10,0" + HorizontalAlignment="Left" + FontSize="25" + FontWeight="Bold" + Text="Date Submitted :"> + + - - - - - - - - - -