From 37a52792914cd9778df623b368ed6522badf9f91 Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Sun, 4 Jun 2017 18:46:24 +0200 Subject: Moved getting data method calls to handlers. --- .../ApartmentManager/ApartmentManager.csproj | 99 +++++++++++----------- .../ApartmentManager/Handler/ApartmentHandler.cs | 40 +++++---- .../Handler/BmApartmentsHandler.cs | 1 + .../ApartmentManager/Handler/BmChangesHandler.cs | 23 ++--- .../ApartmentManager/Handler/BmDefectsHandler.cs | 3 +- .../ApartmentManager/Handler/BmResidentsHandler.cs | 7 +- .../ApartmentManager/Handler/BmUsersHandler.cs | 3 +- .../ApartmentManager/Handler/LoginHandler.cs | 15 ---- .../ApartmentManager/Singletons/BmSingleton.cs | 11 +-- .../Singletons/CatalogSingleton.cs | 9 +- .../ViewModel/ApartmentViewModel.cs | 10 +-- .../ViewModel/BmChangesViewModel.cs | 4 +- 12 files changed, 104 insertions(+), 121 deletions(-) diff --git a/ApartmentManager/ApartmentManager/ApartmentManager.csproj b/ApartmentManager/ApartmentManager/ApartmentManager.csproj index d9da403..dd57ae5 100644 --- a/ApartmentManager/ApartmentManager/ApartmentManager.csproj +++ b/ApartmentManager/ApartmentManager/ApartmentManager.csproj @@ -18,6 +18,7 @@ {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} true ApartmentManager_TemporaryKey.pfx + B7E9DDD60132C6D61DA845D26A66BC87426041DD true @@ -108,7 +109,7 @@ - + @@ -131,67 +132,67 @@ - + ApartmentChangesPage.xaml - + ApartmentChangesViewPage.xaml - + ApartmentDefectPage.xaml - + ApartmentDefectViewPage.xaml - + ApartmentNewChangePage.xaml - + ApartmentNewDefect.xaml - + ApartmentPage.xaml - + BmChangesPage.xaml - + BmCreateChangePage.xaml - + BmCreateDefectPage.xaml - + BmEditApartmentPage.xaml - + BmEditChangePage.xaml - + BmEditDefectPage.xaml - + BmResidentsPage.xaml - + BmApartmentsPage.xaml - + BmDefectsPage.xaml - + BmMainPage.xaml - + BmCreateApartmentPage.xaml - + BmSingleChangePage.xaml - + BmSingleDefectPage.xaml - + BmUsersPage.xaml @@ -200,10 +201,10 @@ PersonalInfoPage.xaml - + ApartmentPlanPage.xaml - + ApartmentResidentsPage.xaml @@ -232,87 +233,87 @@ MSBuild:Compile Designer - + Designer MSBuild:Compile - + Designer MSBuild:Compile - + Designer MSBuild:Compile - + Designer MSBuild:Compile - + Designer MSBuild:Compile - + Designer MSBuild:Compile - + Designer MSBuild:Compile - + Designer MSBuild:Compile - + Designer MSBuild:Compile - + Designer MSBuild:Compile - + Designer MSBuild:Compile - + Designer MSBuild:Compile - + Designer MSBuild:Compile - + Designer MSBuild:Compile - + Designer MSBuild:Compile - + Designer MSBuild:Compile - + Designer MSBuild:Compile - + Designer MSBuild:Compile - + Designer MSBuild:Compile - + Designer MSBuild:Compile - + Designer MSBuild:Compile @@ -324,11 +325,11 @@ Designer MSBuild:Compile - + Designer MSBuild:Compile - + Designer MSBuild:Compile @@ -352,7 +353,9 @@ Designer - + + + 14.0 diff --git a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs index b5ea6d2..b89680c 100644 --- a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs @@ -25,6 +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(); } @@ -36,9 +40,9 @@ namespace ApartmentManager.Handler { try { - string serializedApartment = ApiClient.GetData("api/Apartments/" + ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId); + string serializedApartment = ApiClient.GetData("api/Apartments/" + UserSingleton.Instance.CurrentUser.ApartmentId); Apartment apartment = JsonConvert.DeserializeObject(serializedApartment); - ApartmentViewModel.CatalogSingleton.Apartment = apartment; + CatalogSingleton.Instance.Apartment = apartment; } catch (Exception e) { @@ -54,10 +58,10 @@ namespace ApartmentManager.Handler { var residentsFromDatabase = ApiClient.GetData("api/ApartmentResidents/" + UserSingleton.Instance.CurrentUser.ApartmentId); var residentlist = JsonConvert.DeserializeObject>(residentsFromDatabase); - ApartmentViewModel.CatalogSingleton.Residents.Clear(); + CatalogSingleton.Instance.Residents = new ObservableCollection(); foreach (var resident in residentlist) { - ApartmentViewModel.CatalogSingleton.Residents.Add(resident); + CatalogSingleton.Instance.Residents.Add(resident); } } catch (Exception e) @@ -167,10 +171,10 @@ namespace ApartmentManager.Handler public void GetApartmentDefects() { Defect Defect = new Defect(); - Defect.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; + Defect.ApartmentId = UserSingleton.Instance.CurrentUser.ApartmentId; var defectsFromDatabase = ApiClient.GetData("api/ApartmentDefects/" + Defect.ApartmentId); var defecttlist = JsonConvert.DeserializeObject>(defectsFromDatabase); - CatalogSingleton.Instance.Defects.Clear(); + CatalogSingleton.Instance.Defects = new ObservableCollection(); foreach (var defect in defecttlist) { defect.Pictures = JsonConvert.DeserializeObject>(ApiClient.GetData("api/DefectPicturesById/" + defect.DefectId)); @@ -269,16 +273,16 @@ namespace ApartmentManager.Handler /// public void GetApartmentChanges() { - ApartmentChange change = new ApartmentChange(); - change.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; - var changesFromDatabase = ApiClient.GetData("api/ApartmentChangesByid/" + change.ApartmentId); - var changeslist = JsonConvert.DeserializeObject>(changesFromDatabase); - CatalogSingleton.Instance.ApartmentChanges.Clear(); + Change change = new Change(); + change.ApartmentId = UserSingleton.Instance.CurrentUser.ApartmentId; + var changesFromDatabase = ApiClient.GetData("api/ChangesByApartmentId/" + change.ApartmentId); + var changeslist = JsonConvert.DeserializeObject>(changesFromDatabase); + CatalogSingleton.Instance.Changes = new ObservableCollection(); foreach (var apartmentChange in changeslist) { - apartmentChange.Documents = JsonConvert.DeserializeObject>(ApiClient.GetData("api/ChangeDocumentsById/" + apartmentChange.ChangeId)); - apartmentChange.Comments = JsonConvert.DeserializeObject>(ApiClient.GetData("api/ChangeCommentsById/" + apartmentChange.ChangeId)); - CatalogSingleton.Instance.ApartmentChanges.Add(apartmentChange); + apartmentChange.Documents = JsonConvert.DeserializeObject>(ApiClient.GetData("api/DocumentsByChangeId/" + apartmentChange.ChangeId)); + apartmentChange.Comments = JsonConvert.DeserializeObject>(ApiClient.GetData("api/CommentsByChangeId/" + apartmentChange.ChangeId)); + CatalogSingleton.Instance.Changes.Add(apartmentChange); } } public void CreateChangeComment() @@ -294,7 +298,7 @@ namespace ApartmentManager.Handler { var asd =ApiClient.PostData("api/ChangeComments/", Comment); } - var response = ApiClient.GetData("api/ChangeCommentsById/" + CatalogSingleton.Instance.SelectedChange.ChangeId); + var response = ApiClient.GetData("api/CommentsByChangeId/" + CatalogSingleton.Instance.SelectedChange.ChangeId); var commentlist = JsonConvert.DeserializeObject>(response); CatalogSingleton.Instance.SelectedChange.Comments.Clear(); @@ -336,12 +340,12 @@ namespace ApartmentManager.Handler { try { - ApartmentChange change = ApartmentViewModel.NewChange; + Change change = ApartmentViewModel.NewChange; change.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; change.Status = "New"; change.UploadDate = DateTime.Now; - var response = ApiClient.PostData("api/ApartmentChanges/", change); - var changeResponse = JsonConvert.DeserializeObject(response); + var response = ApiClient.PostData("api/Changes/", change); + var changeResponse = JsonConvert.DeserializeObject(response); change.ChangeId = changeResponse.ChangeId; if (change.Documents !=null) { diff --git a/ApartmentManager/ApartmentManager/Handler/BmApartmentsHandler.cs b/ApartmentManager/ApartmentManager/Handler/BmApartmentsHandler.cs index 48a60e2..349f29c 100644 --- a/ApartmentManager/ApartmentManager/Handler/BmApartmentsHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/BmApartmentsHandler.cs @@ -16,6 +16,7 @@ namespace ApartmentManager.Handler public BmApartmentsHandler(BmApartmentsViewModel vm) { _vm = vm; + if (BmSingleton.Instance.Apartments == null) GetApartments(); } public void GetApartments() diff --git a/ApartmentManager/ApartmentManager/Handler/BmChangesHandler.cs b/ApartmentManager/ApartmentManager/Handler/BmChangesHandler.cs index a32bbc2..87ea656 100644 --- a/ApartmentManager/ApartmentManager/Handler/BmChangesHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/BmChangesHandler.cs @@ -17,17 +17,18 @@ namespace ApartmentManager.Handler public BmChangesHandler(BmChangesViewModel vm) { _vm = vm; + if (BmSingleton.Instance.Changes == null) GetChanges(); } public void GetChanges() { - var changes = JsonConvert.DeserializeObject>(ApiClient.GetData("api/ApartmentChanges/")); - BmSingleton.Instance.ApartmentChanges.Clear(); + var changes = JsonConvert.DeserializeObject>(ApiClient.GetData("api/Changes/")); + BmSingleton.Instance.Changes = new ObservableCollection(); foreach (var change in changes) { - change.Documents = JsonConvert.DeserializeObject>(ApiClient.GetData("api/ChangeDocumentsById/" + change.ChangeId)); - change.Comments = JsonConvert.DeserializeObject>(ApiClient.GetData("api/ChangeCommentsById/" + change.ChangeId)); - BmSingleton.Instance.ApartmentChanges.Add(change); + change.Documents = JsonConvert.DeserializeObject>(ApiClient.GetData("api/DocumentsByChangeId/" + change.ChangeId)); + change.Comments = JsonConvert.DeserializeObject>(ApiClient.GetData("api/CommentsByChangeId/" + change.ChangeId)); + BmSingleton.Instance.Changes.Add(change); } } @@ -38,14 +39,14 @@ namespace ApartmentManager.Handler _vm.ChangeTemplate.Status = "New"; _vm.ChangeTemplate.UploadDate = DateTime.Now; if (_vm.ChangeTemplate.Documents == null) _vm.ChangeTemplate.Documents = new ObservableCollection(); - var response = JsonConvert.DeserializeObject(ApiClient.PostData("api/ApartmentChanges/", _vm.ChangeTemplate)); + var response = JsonConvert.DeserializeObject(ApiClient.PostData("api/Changes/", _vm.ChangeTemplate)); foreach (var changeDocument in _vm.ChangeTemplate.Documents) { changeDocument.ChangeId = response.ChangeId; ApiClient.PostData("api/ChangeDocuments/", changeDocument); } GetChanges(); - _vm.ChangeTemplate = new ApartmentChange(); + _vm.ChangeTemplate = new Change(); } catch (Exception e) { @@ -56,7 +57,7 @@ namespace ApartmentManager.Handler { try { - ApiClient.PutData("api/ApartmentChanges/" + _vm.ChangeTemplate.ChangeId, _vm.ChangeTemplate); + ApiClient.PutData("api/Changes/" + _vm.ChangeTemplate.ChangeId, _vm.ChangeTemplate); var deletedChangeDocuments = new List(_vm.DeletedChangeDocuments); var addedChangeDocuments = new List(_vm.AddedChangeDocuments); @@ -82,8 +83,8 @@ namespace ApartmentManager.Handler { try { - ApiClient.DeleteData("api/ApartmentChanges/" + _vm.ChangeTemplate.ChangeId); - BmSingleton.Instance.ApartmentChanges.Remove(_vm.ChangeTemplate); + ApiClient.DeleteData("api/Changes/" + _vm.ChangeTemplate.ChangeId); + BmSingleton.Instance.Changes.Remove(_vm.ChangeTemplate); GetChanges(); } catch (Exception e) @@ -94,7 +95,7 @@ namespace ApartmentManager.Handler public void ClearChangeTemplate() { - _vm.ChangeTemplate = new ApartmentChange(); + _vm.ChangeTemplate = new Change(); } public async void UploadChangeDocument() diff --git a/ApartmentManager/ApartmentManager/Handler/BmDefectsHandler.cs b/ApartmentManager/ApartmentManager/Handler/BmDefectsHandler.cs index 919d026..27a9680 100644 --- a/ApartmentManager/ApartmentManager/Handler/BmDefectsHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/BmDefectsHandler.cs @@ -17,12 +17,13 @@ namespace ApartmentManager.Handler public BmDefectsHandler(BmDefectsViewModel vm) { _vm = vm; + if (BmSingleton.Instance.Defects == null) GetDefects(); } public void GetDefects() { var defects = JsonConvert.DeserializeObject>(ApiClient.GetData("api/Defects/")); - BmSingleton.Instance.Defects.Clear(); + BmSingleton.Instance.Defects = new ObservableCollection(); 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 7e93393..1e43f4d 100644 --- a/ApartmentManager/ApartmentManager/Handler/BmResidentsHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/BmResidentsHandler.cs @@ -4,11 +4,7 @@ using ApartmentManager.Singletons; using ApartmentManager.ViewModel; using Newtonsoft.Json; using System; -using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Windows.UI.Popups; namespace ApartmentManager.Handler @@ -20,12 +16,13 @@ namespace ApartmentManager.Handler public BmResidentsHandler(BmResidentsViewModel vm) { _vm = vm; + if (BmSingleton.Instance.Residents == null) GetResidents(); } public void GetResidents() { var residents = JsonConvert.DeserializeObject>(ApiClient.GetData("api/Residents/")); - BmSingleton.Instance.Residents.Clear(); + BmSingleton.Instance.Residents = new ObservableCollection(); 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 5fe3a92..cf07594 100644 --- a/ApartmentManager/ApartmentManager/Handler/BmUsersHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/BmUsersHandler.cs @@ -20,12 +20,13 @@ namespace ApartmentManager.Handler public BmUsersHandler(BmUsersViewModel vm) { _vm = vm; + if (BmSingleton.Instance.Users == null) GetUsers(); } public void GetUsers() { var users = JsonConvert.DeserializeObject>(ApiClient.GetData("api/Users/")); - BmSingleton.Instance.Users.Clear(); + BmSingleton.Instance.Users = new ObservableCollection(); 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 9360f97..02e6009 100644 --- a/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs @@ -75,25 +75,10 @@ namespace ApartmentManager.Handler // suppressing the initial entrance animation. if (UserSingleton.Instance.CurrentUser.IsBm) { - BmApartmentsViewModel bavm = new BmApartmentsViewModel(); - BmUsersViewModel buvm = new BmUsersViewModel(); - BmResidentsViewModel brvm = new BmResidentsViewModel(); - BmDefectsViewModel bdvm = new BmDefectsViewModel(); - BmChangesViewModel bcvm = new BmChangesViewModel(); - bavm.BmApartmentsHandler.GetApartments(); - buvm.BmUsersHandler.GetUsers(); - brvm.BmResidentsHandler.GetResidents(); - bdvm.BmDefectsHandler.GetDefects(); - bcvm.BmChangesHandler.GetChanges(); appShell.AppFrame.Navigate(typeof(BmMainPage)); } else { - ApartmentViewModel avm = new ApartmentViewModel(); - avm.ApartmentHandler.GetApartmentResidents(); - avm.ApartmentHandler.GetApartment(); - avm.ApartmentHandler.GetApartmentDefects(); - avm.ApartmentHandler.GetApartmentChanges(); appShell.AppFrame.Navigate(typeof(ApartmentPage)); } } diff --git a/ApartmentManager/ApartmentManager/Singletons/BmSingleton.cs b/ApartmentManager/ApartmentManager/Singletons/BmSingleton.cs index c12f852..255c4ce 100644 --- a/ApartmentManager/ApartmentManager/Singletons/BmSingleton.cs +++ b/ApartmentManager/ApartmentManager/Singletons/BmSingleton.cs @@ -12,15 +12,8 @@ namespace ApartmentManager.Singletons public ObservableCollection Users { get; set; } public ObservableCollection Residents { get; set; } public ObservableCollection Defects { get; set; } - public ObservableCollection ApartmentChanges { get; set; } + public ObservableCollection Changes { get; set; } - private BmSingleton() - { - Apartments = new ObservableCollection(); - Users = new ObservableCollection(); - Residents = new ObservableCollection(); - Defects = new ObservableCollection(); - ApartmentChanges = new ObservableCollection(); - } + private BmSingleton() { } } } diff --git a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs index ee101c6..f32dd7a 100644 --- a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs +++ b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs @@ -18,18 +18,15 @@ namespace ApartmentManager.Singletons public ObservableCollection Residents { get; set; } ////////// For Defects ////////// public ObservableCollection Defects { get; set; } - public ApartmentChange SelectedChange { get; set; } + public Change SelectedChange { get; set; } ////////// For Defects ////////// - public ObservableCollection ApartmentChanges { get; set; } + public ObservableCollection Changes { get; set; } public Defect SelectedDefect { get; set; } ////////// Constructor ////////// private CatalogSingleton() { - ApartmentChanges = new ObservableCollection(); - Residents = new ObservableCollection(); - Defects = new ObservableCollection(); SelectedDefect = new Defect(); - SelectedChange = new ApartmentChange(); + SelectedChange = new Change(); } } } diff --git a/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs b/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs index bb126b4..dad1ad8 100644 --- a/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs +++ b/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs @@ -31,7 +31,7 @@ namespace ApartmentManager.ViewModel private DefectComment _newDefectComment; //// For Changes/// private ChangeComment _newChangeComment; - private ApartmentChange _newApartmentChange; + private Change _newChange; private ChangeDocument _selectedChangeDocument; ////////// Resident relay commands////////// public ICommand CreateResidentCommand { get; set; } @@ -64,7 +64,7 @@ namespace ApartmentManager.ViewModel NewChangeComment = new ChangeComment(); SelectedChangeDocument = new ChangeDocument(); - NewChange = new ApartmentChange(); + NewChange = new Change(); ////////// Handler ////////// ApartmentHandler = new ApartmentHandler(this); ////////// Singletons ////////// @@ -136,12 +136,12 @@ namespace ApartmentManager.ViewModel OnPropertyChanged(); } } - public ApartmentChange NewChange + public Change NewChange { - get => _newApartmentChange; + get => _newChange; set { - _newApartmentChange = value; + _newChange = value; OnPropertyChanged(); } } diff --git a/ApartmentManager/ApartmentManager/ViewModel/BmChangesViewModel.cs b/ApartmentManager/ApartmentManager/ViewModel/BmChangesViewModel.cs index 68aa14d..990b367 100644 --- a/ApartmentManager/ApartmentManager/ViewModel/BmChangesViewModel.cs +++ b/ApartmentManager/ApartmentManager/ViewModel/BmChangesViewModel.cs @@ -26,7 +26,7 @@ namespace ApartmentManager.ViewModel public ICommand DeleteChangeDocumentTempCommand { get; } public ICommand CreateChangeCommentCommand { get; } - private static ApartmentChange _changeTemplate = new ApartmentChange(); + private static Change _changeTemplate = new Change(); private static ChangeDocument _selectedChangeDocument = new ChangeDocument(); private static List _deletedChangeDocuments = new List(); private static List _addedChangeDocuments = new List(); @@ -47,7 +47,7 @@ namespace ApartmentManager.ViewModel CreateChangeCommentCommand = new RelayCommand(BmChangesHandler.CreateChangeComment); } - public ApartmentChange ChangeTemplate + public Change ChangeTemplate { get => _changeTemplate; set -- cgit v1.2.3