From 45a5a28f5331b1610917ba1ba229f050a3debf6d Mon Sep 17 00:00:00 2001 From: Donatas Adamonis Date: Wed, 10 May 2017 10:35:24 +0200 Subject: Editing Residents listview --- .../ApartmentManager/ApartmentManager.csproj | 9 +- .../ApartmentManager/Handler/ApartmentHandler.cs | 143 +++++++++++++++++++++ .../ApartmentManager/Handler/ResidentsHandler.cs | 134 ------------------- .../Singletons/CatalogSingleton.cs | 14 +- .../ApartmentManager/Singletons/UserSingleton.cs | 2 +- .../ApartmentManager/View/ApartmentNewDefect.xaml | 48 +++++++ .../View/ApartmentNewDefect.xaml.cs | 30 +++++ .../ApartmentManager/View/ApartmentPage.xaml | 85 +++++++----- .../View/ApartmentResidentsPage.xaml | 71 +++++++++- .../View/ApartmentResidentsPage.xaml.cs | 3 +- .../ViewModel/ApartmenViewModel.cs | 18 ++- .../Controllers/ResidentsController.cs | 38 +++--- ApartmentManager/HousingWebApi/DataModel.cs | 29 ++++- .../HousingWebApi/HousingWebAPI.csproj | 5 +- ApartmentManager/HousingWebApi/Models/Apartment.cs | 3 + ApartmentManager/HousingWebApi/Models/Defect.cs | 12 +- ApartmentManager/HousingWebApi/Models/Resident.cs | 4 +- ApartmentManager/HousingWebApi/Web.config | 6 +- 18 files changed, 428 insertions(+), 226 deletions(-) create mode 100644 ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs delete mode 100644 ApartmentManager/ApartmentManager/Handler/ResidentsHandler.cs create mode 100644 ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml create mode 100644 ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml.cs diff --git a/ApartmentManager/ApartmentManager/ApartmentManager.csproj b/ApartmentManager/ApartmentManager/ApartmentManager.csproj index 0bf5485..8d1bb2b 100644 --- a/ApartmentManager/ApartmentManager/ApartmentManager.csproj +++ b/ApartmentManager/ApartmentManager/ApartmentManager.csproj @@ -102,7 +102,7 @@ - + @@ -119,6 +119,9 @@ + + ApartmentNewDefect.xaml + ApartmentPage.xaml @@ -179,6 +182,10 @@ MSBuild:Compile Designer + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs new file mode 100644 index 0000000..7c27686 --- /dev/null +++ b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs @@ -0,0 +1,143 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Windows.UI.Popups; +using ApartmentManager.Model; +using ApartmentManager.Persistency; +using ApartmentManager.ViewModel; +using Newtonsoft.Json; + +namespace ApartmentManager.Handler +{ + public class ApartmentHandler + { + public ApartmentViewModel ApartmentViewModel { get; set; } + + public ApartmentHandler(ApartmentViewModel apartmenViewModel) + { + ApartmentViewModel = apartmenViewModel; + } + public void GetApartmentResidents() + { + Resident resident = new Resident(); + resident.ApartmentNr = ApartmentViewModel.ApartmentNumber; + + var residentsFromDatabase = ApiClient.GetData("api/ApartmentResidents/" + resident.ApartmentNr); + IEnumerable residentlist = JsonConvert.DeserializeObject>(residentsFromDatabase); + + ApartmentViewModel.CatalogSingleton.Residents.Clear(); + ApartmentViewModel.NewResident = new Resident(); + foreach (var resident2 in residentlist) + { + ApartmentViewModel.CatalogSingleton.Residents.Add(resident2); + } + + } + public void GetApartment() + { + string serializedApartment = ApiClient.GetData("api/Apartments/" + ApartmentViewModel.ApartmentNumber); + + Apartment apartment= JsonConvert.DeserializeObject(serializedApartment); + ApartmentViewModel.CatalogSingleton.Apartment = apartment; + + + } + + public void CreateResident() + { + try + { + Resident resident = new Resident(); + + resident.ApartmentNr = ApartmentViewModel.ApartmentNumber; + resident.FirstName = ApartmentViewModel.NewResident.FirstName; + resident.LastName = ApartmentViewModel.NewResident.LastName; + resident.BirthDate = ApartmentViewModel.NewResident.BirthDate; + resident.Email = ApartmentViewModel.NewResident.Email; + resident.Picture = ApartmentViewModel.NewResident.Picture; + resident.Phone = ApartmentViewModel.NewResident.Phone; + + ApiClient.PostData("api/residents/", resident); + + var residentsFromDatabase = ApiClient.GetData("api/ApartmentResidents/" + resident.ApartmentNr); + IEnumerable residentlist = JsonConvert.DeserializeObject>(residentsFromDatabase); + + ApartmentViewModel.CatalogSingleton.Residents.Clear(); + ApartmentViewModel.NewResident = new Resident(); + foreach (var resident2 in residentlist) + { + ApartmentViewModel.CatalogSingleton.Residents.Add(resident2); + } + } + catch (Exception e) + { + new MessageDialog(e.Message).ShowAsync(); + } + } + + public void DeleteResident() + { + try + { + Resident resident = new Resident(); + resident.ResidentNr = ApartmentViewModel.NewResident.ResidentNr; + resident.ApartmentNr = ApartmentViewModel.ApartmentNumber; + resident.FirstName = ApartmentViewModel.NewResident.FirstName; + resident.LastName = ApartmentViewModel.NewResident.LastName; + resident.BirthDate = ApartmentViewModel.NewResident.BirthDate; + resident.Email = ApartmentViewModel.NewResident.Email; + resident.Picture = ApartmentViewModel.NewResident.Picture; + resident.Phone = ApartmentViewModel.NewResident.Phone; + + ApiClient.DeleteData("api/residents/" + resident.ResidentNr); + + var residentsFromDatabase = ApiClient.GetData("api/ApartmentResidents/" + resident.ApartmentNr); + IEnumerable residentlist = JsonConvert.DeserializeObject>(residentsFromDatabase); + + ApartmentViewModel.CatalogSingleton.Residents.Clear(); + ApartmentViewModel.NewResident = new Resident(); + foreach (var resident2 in residentlist) + { + ApartmentViewModel.CatalogSingleton.Residents.Add(resident2); + } + } + catch (Exception e) + { + new MessageDialog(e.Message).ShowAsync(); + } + } + public void UpdateResident() + { + try + { + Resident resident = new Resident(); + resident.ResidentNr = ApartmentViewModel.NewResident.ResidentNr; + resident.ApartmentNr = ApartmentViewModel.ApartmentNumber; + resident.FirstName = ApartmentViewModel.NewResident.FirstName; + resident.LastName = ApartmentViewModel.NewResident.LastName; + resident.BirthDate = ApartmentViewModel.NewResident.BirthDate; + resident.Email = ApartmentViewModel.NewResident.Email; + resident.Picture = ApartmentViewModel.NewResident.Picture; + resident.Phone = ApartmentViewModel.NewResident.Phone; + + ApiClient.PutData("api/residents/" + resident.ResidentNr,resident); + var residentsFromDatabase = ApiClient.GetData("api/ApartmentResidents/" + resident.ApartmentNr); + IEnumerable residentlist = JsonConvert.DeserializeObject>(residentsFromDatabase); + + ApartmentViewModel.CatalogSingleton.Residents.Clear(); + ApartmentViewModel.NewResident = new Resident(); + foreach (var resident2 in residentlist) + { + ApartmentViewModel.CatalogSingleton.Residents.Add(resident2); + } + } + catch (Exception e) + { + new MessageDialog(e.Message).ShowAsync(); + } + } + } +} diff --git a/ApartmentManager/ApartmentManager/Handler/ResidentsHandler.cs b/ApartmentManager/ApartmentManager/Handler/ResidentsHandler.cs deleted file mode 100644 index d406880..0000000 --- a/ApartmentManager/ApartmentManager/Handler/ResidentsHandler.cs +++ /dev/null @@ -1,134 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Windows.UI.Popups; -using ApartmentManager.Model; -using ApartmentManager.Persistency; -using ApartmentManager.ViewModel; -using Newtonsoft.Json; - -namespace ApartmentManager.Handler -{ - public class ResidentsHandler - { - public ApartmentViewModel ApartmentViewModel { get; set; } - - public ResidentsHandler(ApartmentViewModel apartmenViewModel) - { - ApartmentViewModel = apartmenViewModel; - } - public void GetApartmentResidents() - { - Resident resident = new Resident(); - resident.ApartmentNr = ApartmentViewModel.ApartmentNumber; - - var residentsFromDatabase = ApiClient.GetData("api/ApartmentResidents/" + resident.ApartmentNr); - IEnumerable residentlist = JsonConvert.DeserializeObject>(residentsFromDatabase); - - ApartmentViewModel.CatalogSingleton.Residents.Clear(); - ApartmentViewModel.NewResident = new Resident(); - foreach (var resident2 in residentlist) - { - ApartmentViewModel.CatalogSingleton.Residents.Add(resident2); - } - - } - - public void CreateResident() - { - try - { - Resident resident = new Resident(); - - resident.ApartmentNr = ApartmentViewModel.ApartmentNumber; - resident.FirstName = ApartmentViewModel.NewResident.FirstName; - resident.LastName = ApartmentViewModel.NewResident.LastName; - resident.BirthDate = ApartmentViewModel.NewResident.BirthDate; - resident.Email = ApartmentViewModel.NewResident.Email; - resident.Picture = ApartmentViewModel.NewResident.Picture; - resident.Phone = ApartmentViewModel.NewResident.Phone; - - ApiClient.PostData("api/residents/", resident); - - var residentsFromDatabase = ApiClient.GetData("api/ApartmentResidents/" + resident.ApartmentNr); - IEnumerable residentlist = JsonConvert.DeserializeObject>(residentsFromDatabase); - - ApartmentViewModel.CatalogSingleton.Residents.Clear(); - ApartmentViewModel.NewResident = new Resident(); - foreach (var resident2 in residentlist) - { - ApartmentViewModel.CatalogSingleton.Residents.Add(resident2); - } - } - catch (Exception e) - { - new MessageDialog(e.Message).ShowAsync(); - } - } - - public void DeleteResident() - { - try - { - Resident resident = new Resident(); - resident.ResidentNr = ApartmentViewModel.NewResident.ResidentNr; - resident.ApartmentNr = ApartmentViewModel.ApartmentNumber; - resident.FirstName = ApartmentViewModel.NewResident.FirstName; - resident.LastName = ApartmentViewModel.NewResident.LastName; - resident.BirthDate = ApartmentViewModel.NewResident.BirthDate; - resident.Email = ApartmentViewModel.NewResident.Email; - resident.Picture = ApartmentViewModel.NewResident.Picture; - resident.Phone = ApartmentViewModel.NewResident.Phone; - - ApiClient.DeleteData("api/residents/" + resident.ResidentNr); - - var residentsFromDatabase = ApiClient.GetData("api/ApartmentResidents/" + resident.ApartmentNr); - IEnumerable residentlist = JsonConvert.DeserializeObject>(residentsFromDatabase); - - ApartmentViewModel.CatalogSingleton.Residents.Clear(); - ApartmentViewModel.NewResident = new Resident(); - foreach (var resident2 in residentlist) - { - ApartmentViewModel.CatalogSingleton.Residents.Add(resident2); - } - } - catch (Exception e) - { - new MessageDialog(e.Message).ShowAsync(); - } - } - public void UpdateResident() - { - try - { - Resident resident = new Resident(); - resident.ResidentNr = ApartmentViewModel.NewResident.ResidentNr; - resident.ApartmentNr = ApartmentViewModel.ApartmentNumber; - resident.FirstName = ApartmentViewModel.NewResident.FirstName; - resident.LastName = ApartmentViewModel.NewResident.LastName; - resident.BirthDate = ApartmentViewModel.NewResident.BirthDate; - resident.Email = ApartmentViewModel.NewResident.Email; - resident.Picture = ApartmentViewModel.NewResident.Picture; - resident.Phone = ApartmentViewModel.NewResident.Phone; - - ApiClient.PutData("api/residents/" + resident.ResidentNr,resident); - var residentsFromDatabase = ApiClient.GetData("api/ApartmentResidents/" + resident.ApartmentNr); - IEnumerable residentlist = JsonConvert.DeserializeObject>(residentsFromDatabase); - - ApartmentViewModel.CatalogSingleton.Residents.Clear(); - ApartmentViewModel.NewResident = new Resident(); - foreach (var resident2 in residentlist) - { - ApartmentViewModel.CatalogSingleton.Residents.Add(resident2); - } - } - catch (Exception e) - { - new MessageDialog(e.Message).ShowAsync(); - } - } - } -} diff --git a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs index 3a4c706..f2a45be 100644 --- a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs +++ b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs @@ -13,17 +13,13 @@ namespace ApartmentManager.Model public static CatalogSingleton Instance => instance; - public ObservableCollection User { get; set; } - public ObservableCollection Apartment { get; set; } + + public Apartment Apartment { get; set; } public ObservableCollection Residents { get; set; } private CatalogSingleton() - { - User = new ObservableCollection(); - User.Add(new User("Bibis", "Kiausiai", "3214568", new DateTime(2017, 1, 5, 2, 27, 0), "Bibis@mail.com", 1)); - Apartment = new ObservableCollection(); - Apartment.Add(new Apartment(1,"30 Square meters",2,"200",0,"adresas")); - Residents = new ObservableCollection(); - + { + + Residents.Add(new Resident("Donis","banana",12345,new DateTime(1990,07,26,0,0,0,0), "Donis@donis.lt",1,1)); } } } diff --git a/ApartmentManager/ApartmentManager/Singletons/UserSingleton.cs b/ApartmentManager/ApartmentManager/Singletons/UserSingleton.cs index aa09cf2..24150c9 100644 --- a/ApartmentManager/ApartmentManager/Singletons/UserSingleton.cs +++ b/ApartmentManager/ApartmentManager/Singletons/UserSingleton.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace ApartmentManager.Model { - class UserSingleton + public class UserSingleton { private static UserSingleton instance; public static User CurrentUser; diff --git a/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml b/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml new file mode 100644 index 0000000..b67aad6 --- /dev/null +++ b/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -89,7 +91,7 @@ - + @@ -94,9 +94,9 @@ - + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml b/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml index b67aad6..c6332e1 100644 --- a/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml +++ b/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml @@ -1,12 +1,17 @@  + + + + @@ -16,29 +21,29 @@ - - + + + + + +