From 763d01f938ccc1b2b3c35ad7ad45bc3626113a3e Mon Sep 17 00:00:00 2001 From: Donatas Adamonis Date: Tue, 23 May 2017 22:56:20 +0200 Subject: defects --- .../ApartmentManager/ApartmentManager.csproj | 1 + .../ApartmentManager/Handler/ApartmentHandler.cs | 79 ++++++++++++++++++---- ApartmentManager/ApartmentManager/Model/Defect.cs | 5 +- .../ApartmentManager/Model/DefectPicture.cs | 15 ++++ .../Singletons/CatalogSingleton.cs | 7 +- .../ApartmentManager/View/ApartmentDefectPage.xaml | 13 ++-- .../ApartmentManager/View/ApartmentNewDefect.xaml | 14 +++- .../ViewModel/ApartmentViewModel.cs | 14 +++- .../Controllers/DefectPicturesController.cs | 10 ++- 9 files changed, 128 insertions(+), 30 deletions(-) create mode 100644 ApartmentManager/ApartmentManager/Model/DefectPicture.cs diff --git a/ApartmentManager/ApartmentManager/ApartmentManager.csproj b/ApartmentManager/ApartmentManager/ApartmentManager.csproj index f267a50..ac7b1f7 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 aa5f415..388cbaa 100644 --- a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs @@ -28,6 +28,18 @@ namespace ApartmentManager.Handler /// /// APARTMENT HANDLERS /// + + public void GetApartment() + { + string serializedApartment = ApiClient.GetData("api/Apartments/" + ApartmentViewModel.ApartmentNumber); + + Apartment apartment = JsonConvert.DeserializeObject(serializedApartment); + ApartmentViewModel.CatalogSingleton.Apartment = apartment; + } + + /// + /// RESIDENT HANDLERS + /// public void GetApartmentResidents() { Resident resident = new Resident(); @@ -44,17 +56,7 @@ namespace ApartmentManager.Handler } } - public void GetApartment() - { - string serializedApartment = ApiClient.GetData("api/Apartments/" + ApartmentViewModel.ApartmentNumber); - - Apartment apartment = JsonConvert.DeserializeObject(serializedApartment); - ApartmentViewModel.CatalogSingleton.Apartment = apartment; - } - /// - /// RESIDENT HANDLERS - /// public void CreateResident() { try @@ -162,8 +164,6 @@ namespace ApartmentManager.Handler { } } - - /// /// USER HANDLERS /// @@ -181,18 +181,71 @@ namespace ApartmentManager.Handler { } } + public void UpdateUser() { try { 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) { new MessageDialog(e.Message).ShowAsync(); } } + /// + /// Defect HANDLERS + /// + public void GetApartmentDefects() + { + Defect defect = new Defect(); + defect.ApartmentId = ApartmentViewModel.ApartmentNumber; + + var residentsFromDatabase = ApiClient.GetData("api/ApartmentDefects/" + defect.ApartmentId); + IEnumerable defecttlist = JsonConvert.DeserializeObject>(residentsFromDatabase); + + foreach (var qwe in defecttlist) + { + var picturesFromDatabase = ApiClient.GetData("api/DefectPictures/" + qwe.DefectId); + IEnumerable picturetlist = JsonConvert.DeserializeObject>(picturesFromDatabase); + ApartmentViewModel.CatalogSingleton.DefectPictures.Clear(); + foreach (var asd in picturetlist) + { + + ApartmentViewModel.CatalogSingleton.DefectPictures.Add(asd); + } + qwe.MainPicture = ApartmentViewModel.CatalogSingleton.DefectPictures[0].Picture; + + } + + ApartmentViewModel.CatalogSingleton.Defects.Clear(); + ApartmentViewModel.NewResident = new Resident(); + foreach (var defect2 in defecttlist) + { + + ApartmentViewModel.CatalogSingleton.Defects.Add(defect2); + } + } + + public void DeleteDefectPicture() + { + ApartmentViewModel.CatalogSingleton.DefectPictures.Remove(ApartmentViewModel.SelectedDefectPicture); + } + public async void UploadDefectPhoto() + { + try + { + ApartmentViewModel.SelectedDefectPicture.Picture = await ImgurPhotoUploader.UploadPhotoAsync(); + ApartmentViewModel.CatalogSingleton.DefectPictures.Add(ApartmentViewModel.SelectedDefectPicture); + var tmp = ApartmentViewModel.UserSingleton.CurrentUser; + ApartmentViewModel.UserSingleton.CurrentUser = new User(); + ApartmentViewModel.UserSingleton.CurrentUser = tmp; + } + catch (Exception e) + { + } + } } } diff --git a/ApartmentManager/ApartmentManager/Model/Defect.cs b/ApartmentManager/ApartmentManager/Model/Defect.cs index afb29e2..ea305e6 100644 --- a/ApartmentManager/ApartmentManager/Model/Defect.cs +++ b/ApartmentManager/ApartmentManager/Model/Defect.cs @@ -7,13 +7,14 @@ namespace ApartmentManager.Model public int DefectId { get; set; } public int ApartmentId { get; set; } public string Name { get; set; } - public DateTime? UploadDate { get; set; } + public DateTime UploadDate { get; set; } public string Description { get; set; } public string Status { get; set; } + public string MainPicture { get; set; } public Defect() { } - public Defect(int defectId, int apartmentId, string name, DateTime? uploadDate, string description, string status) + public Defect(int defectId, int apartmentId, string name, DateTime uploadDate, string description, string status) { DefectId = defectId; ApartmentId = apartmentId; diff --git a/ApartmentManager/ApartmentManager/Model/DefectPicture.cs b/ApartmentManager/ApartmentManager/Model/DefectPicture.cs new file mode 100644 index 0000000..ec502f5 --- /dev/null +++ b/ApartmentManager/ApartmentManager/Model/DefectPicture.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ApartmentManager.Model +{ + public class DefectPicture + { + public int Pictureid { get; set; } + public int DefectId { get; set; } + public string Picture { get; set; } + } +} diff --git a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs index 95f2323..f158063 100644 --- a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs +++ b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs @@ -14,14 +14,13 @@ namespace ApartmentManager.Singletons public Apartment Apartment { get; set; } public ObservableCollection Residents { get; set; } public ObservableCollection Defects { get; set; } + public ObservableCollection DefectPictures { get; set; } + private CatalogSingleton() { Residents = new ObservableCollection(); Defects = new ObservableCollection(); - Defects.Add(new Defect(1, 1, "Broken Pipe", new DateTime(1988, 8, 8), "description", "status")); - Defects.Add(new Defect(1, 1, "Broken Pipe", new DateTime(1988, 8, 8), "description", "status")); - Defects.Add(new Defect(1, 1, "Broken Pipe", new DateTime(1988, 8, 8), "description", "status")); - Defects.Add(new Defect(1, 1, "Broken Pipe", new DateTime(1988, 8, 8), "description", "status")); + DefectPictures = new ObservableCollection(); } } } diff --git a/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml b/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml index c73065f..5cff9d2 100644 --- a/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml +++ b/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml @@ -31,7 +31,7 @@ - + @@ -49,11 +49,16 @@ - + - - + + + + + + + diff --git a/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml b/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml index 770a132..9b22dc9 100644 --- a/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml +++ b/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml @@ -19,13 +19,21 @@ - - + + + + + + + + + +