From 7653784bc7231825fde33f5d2f5c23740a27c215 Mon Sep 17 00:00:00 2001 From: Donatas Adamonis Date: Wed, 14 Jun 2017 21:36:14 +0200 Subject: changes --- .../ApartmentManager/Handler/ApartmentHandler.cs | 12 +++++++----- .../ApartmentManager/Handler/BmApartmentsHandler.cs | 3 ++- .../ApartmentManager/Handler/BmChangesHandler.cs | 4 ++-- .../ApartmentManager/Handler/BmDefectsHandler.cs | 4 ++-- .../ApartmentManager/Handler/BmResidentsHandler.cs | 4 ++-- .../ApartmentManager/Handler/BmUsersHandler.cs | 4 ++-- .../ApartmentManager/Handler/LoginHandler.cs | 18 ++++++++++++++++++ .../ApartmentManager/Singletons/BmSingleton.cs | 9 ++++++++- .../ApartmentManager/Singletons/CatalogSingleton.cs | 3 +++ .../View/Board member pages/BmUsersPage.xaml | 2 +- 10 files changed, 47 insertions(+), 16 deletions(-) diff --git a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs index b89680c..086785a 100644 --- a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs @@ -25,10 +25,10 @@ namespace ApartmentManager.Handler public ApartmentHandler(ApartmentViewModel apartmenViewModel) { ApartmentViewModel = apartmenViewModel; - if (CatalogSingleton.Instance.Apartment == null) GetApartment(); - if (CatalogSingleton.Instance.Residents == null) GetApartmentResidents(); - if (CatalogSingleton.Instance.Defects == null) GetApartmentDefects(); - if (CatalogSingleton.Instance.Changes == null) GetApartmentChanges(); + GetApartment(); + if (CatalogSingleton.Instance.Residents.Count==0) GetApartmentResidents(); + if (CatalogSingleton.Instance.Defects.Count == 0) GetApartmentDefects(); + if (CatalogSingleton.Instance.Changes.Count == 0) GetApartmentChanges(); } @@ -58,7 +58,7 @@ namespace ApartmentManager.Handler { var residentsFromDatabase = ApiClient.GetData("api/ApartmentResidents/" + UserSingleton.Instance.CurrentUser.ApartmentId); var residentlist = JsonConvert.DeserializeObject>(residentsFromDatabase); - CatalogSingleton.Instance.Residents = new ObservableCollection(); + CatalogSingleton.Instance.Residents.Clear(); foreach (var resident in residentlist) { CatalogSingleton.Instance.Residents.Add(resident); @@ -175,6 +175,7 @@ namespace ApartmentManager.Handler var defectsFromDatabase = ApiClient.GetData("api/ApartmentDefects/" + Defect.ApartmentId); var defecttlist = JsonConvert.DeserializeObject>(defectsFromDatabase); CatalogSingleton.Instance.Defects = new ObservableCollection(); + CatalogSingleton.Instance.Defects.Clear(); foreach (var defect in defecttlist) { defect.Pictures = JsonConvert.DeserializeObject>(ApiClient.GetData("api/DefectPicturesById/" + defect.DefectId)); @@ -278,6 +279,7 @@ namespace ApartmentManager.Handler var changesFromDatabase = ApiClient.GetData("api/ChangesByApartmentId/" + change.ApartmentId); var changeslist = JsonConvert.DeserializeObject>(changesFromDatabase); CatalogSingleton.Instance.Changes = new ObservableCollection(); + CatalogSingleton.Instance.Changes.Clear(); foreach (var apartmentChange in changeslist) { apartmentChange.Documents = JsonConvert.DeserializeObject>(ApiClient.GetData("api/DocumentsByChangeId/" + apartmentChange.ChangeId)); diff --git a/ApartmentManager/ApartmentManager/Handler/BmApartmentsHandler.cs b/ApartmentManager/ApartmentManager/Handler/BmApartmentsHandler.cs index 349f29c..de74491 100644 --- a/ApartmentManager/ApartmentManager/Handler/BmApartmentsHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/BmApartmentsHandler.cs @@ -16,11 +16,12 @@ namespace ApartmentManager.Handler public BmApartmentsHandler(BmApartmentsViewModel vm) { _vm = vm; - if (BmSingleton.Instance.Apartments == null) GetApartments(); + if (BmSingleton.Instance.Apartments.Count==0) GetApartments(); } public void GetApartments() { + BmSingleton.Instance.Apartments.Clear(); BmSingleton.Instance.Apartments = JsonConvert.DeserializeObject>(ApiClient.GetData("api/Apartments/")); } diff --git a/ApartmentManager/ApartmentManager/Handler/BmChangesHandler.cs b/ApartmentManager/ApartmentManager/Handler/BmChangesHandler.cs index 87ea656..35b67e5 100644 --- a/ApartmentManager/ApartmentManager/Handler/BmChangesHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/BmChangesHandler.cs @@ -17,13 +17,13 @@ namespace ApartmentManager.Handler public BmChangesHandler(BmChangesViewModel vm) { _vm = vm; - if (BmSingleton.Instance.Changes == null) GetChanges(); + if (BmSingleton.Instance.Changes.Count == 0) GetChanges(); } public void GetChanges() { var changes = JsonConvert.DeserializeObject>(ApiClient.GetData("api/Changes/")); - BmSingleton.Instance.Changes = new ObservableCollection(); + BmSingleton.Instance.Changes.Clear(); foreach (var change in changes) { change.Documents = JsonConvert.DeserializeObject>(ApiClient.GetData("api/DocumentsByChangeId/" + change.ChangeId)); diff --git a/ApartmentManager/ApartmentManager/Handler/BmDefectsHandler.cs b/ApartmentManager/ApartmentManager/Handler/BmDefectsHandler.cs index 27a9680..34a68f5 100644 --- a/ApartmentManager/ApartmentManager/Handler/BmDefectsHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/BmDefectsHandler.cs @@ -17,13 +17,13 @@ namespace ApartmentManager.Handler public BmDefectsHandler(BmDefectsViewModel vm) { _vm = vm; - if (BmSingleton.Instance.Defects == null) GetDefects(); + if (BmSingleton.Instance.Defects.Count == 0) GetDefects(); } public void GetDefects() { var defects = JsonConvert.DeserializeObject>(ApiClient.GetData("api/Defects/")); - BmSingleton.Instance.Defects = new ObservableCollection(); + BmSingleton.Instance.Defects.Clear(); foreach (var defect in defects) { defect.Pictures = JsonConvert.DeserializeObject>(ApiClient.GetData("api/DefectPicturesById/" + defect.DefectId)); diff --git a/ApartmentManager/ApartmentManager/Handler/BmResidentsHandler.cs b/ApartmentManager/ApartmentManager/Handler/BmResidentsHandler.cs index 1e43f4d..45fbb01 100644 --- a/ApartmentManager/ApartmentManager/Handler/BmResidentsHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/BmResidentsHandler.cs @@ -16,13 +16,13 @@ namespace ApartmentManager.Handler public BmResidentsHandler(BmResidentsViewModel vm) { _vm = vm; - if (BmSingleton.Instance.Residents == null) GetResidents(); + if (BmSingleton.Instance.Residents.Count == 0) GetResidents(); } public void GetResidents() { var residents = JsonConvert.DeserializeObject>(ApiClient.GetData("api/Residents/")); - BmSingleton.Instance.Residents = new ObservableCollection(); + BmSingleton.Instance.Residents.Clear(); foreach (var resident in residents) BmSingleton.Instance.Residents.Add(resident); } diff --git a/ApartmentManager/ApartmentManager/Handler/BmUsersHandler.cs b/ApartmentManager/ApartmentManager/Handler/BmUsersHandler.cs index cf07594..19a34ce 100644 --- a/ApartmentManager/ApartmentManager/Handler/BmUsersHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/BmUsersHandler.cs @@ -20,13 +20,13 @@ namespace ApartmentManager.Handler public BmUsersHandler(BmUsersViewModel vm) { _vm = vm; - if (BmSingleton.Instance.Users == null) GetUsers(); + if (BmSingleton.Instance.Users.Count == 0) GetUsers(); } public void GetUsers() { var users = JsonConvert.DeserializeObject>(ApiClient.GetData("api/Users/")); - BmSingleton.Instance.Users = new ObservableCollection(); + BmSingleton.Instance.Users.Clear(); foreach (var user in users) BmSingleton.Instance.Users.Add(user); } diff --git a/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs b/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs index 02e6009..f31a948 100644 --- a/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs @@ -2,6 +2,7 @@ using ApartmentManager.Persistency; using Newtonsoft.Json; using System; +using System.Collections.ObjectModel; using ApartmentManager.ViewModel; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; @@ -46,6 +47,23 @@ namespace ApartmentManager.Handler public void LogOut() { + if (UserSingleton.Instance.CurrentUser.IsBm) + { + BmSingleton.Instance.Apartments = new ObservableCollection(); + BmSingleton.Instance.Users = new ObservableCollection(); + BmSingleton.Instance.Residents = new ObservableCollection(); + BmSingleton.Instance.Defects = new ObservableCollection(); + BmSingleton.Instance.Changes = new ObservableCollection(); + } + else + { + CatalogSingleton.Instance.SelectedChange = new Change(); + CatalogSingleton.Instance.Apartment = new Apartment(); + CatalogSingleton.Instance.Changes = new ObservableCollection(); + CatalogSingleton.Instance.Defects = new ObservableCollection(); + CatalogSingleton.Instance.Residents = new ObservableCollection(); + CatalogSingleton.Instance.SelectedDefect = new Defect(); + } UserSingleton.Instance.CurrentUser = null; NavigateToLoginPage(); } diff --git a/ApartmentManager/ApartmentManager/Singletons/BmSingleton.cs b/ApartmentManager/ApartmentManager/Singletons/BmSingleton.cs index 255c4ce..410b938 100644 --- a/ApartmentManager/ApartmentManager/Singletons/BmSingleton.cs +++ b/ApartmentManager/ApartmentManager/Singletons/BmSingleton.cs @@ -14,6 +14,13 @@ namespace ApartmentManager.Singletons public ObservableCollection Defects { get; set; } public ObservableCollection Changes { get; set; } - private BmSingleton() { } + private BmSingleton() + { + Apartments = new ObservableCollection(); + Users = new ObservableCollection(); + Residents = new ObservableCollection(); + Defects = new ObservableCollection(); + Changes = new ObservableCollection(); + } } } diff --git a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs index f32dd7a..90e8ee0 100644 --- a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs +++ b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs @@ -25,6 +25,9 @@ namespace ApartmentManager.Singletons ////////// Constructor ////////// private CatalogSingleton() { + Residents = new ObservableCollection(); + Defects = new ObservableCollection(); + Changes = new ObservableCollection(); SelectedDefect = new Defect(); SelectedChange = new Change(); } diff --git a/ApartmentManager/ApartmentManager/View/Board member pages/BmUsersPage.xaml b/ApartmentManager/ApartmentManager/View/Board member pages/BmUsersPage.xaml index f5b5f3e..0f084ea 100644 --- a/ApartmentManager/ApartmentManager/View/Board member pages/BmUsersPage.xaml +++ b/ApartmentManager/ApartmentManager/View/Board member pages/BmUsersPage.xaml @@ -128,7 +128,7 @@ Command="{Binding UploadUserPhotoCommand}" Content="Upload Picture" /> - + -- cgit v1.2.3