From 2077ff4bef13d2cca7d1a51302d8edfc547597eb Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Tue, 30 May 2017 12:25:28 +0200 Subject: Splitted BmViewModel and BmHandler into separate classes. --- .../ApartmentManager/ApartmentManager.csproj | 10 +- .../Handler/BmApartmentsHandler.cs | 75 +++++ .../ApartmentManager/Handler/BmDefectsHandler.cs | 142 +++++++++ .../ApartmentManager/Handler/BmHandler.cs | 331 --------------------- .../ApartmentManager/Handler/BmResidentsHandler.cs | 84 ++++++ .../ApartmentManager/Handler/BmUsersHandler.cs | 88 ++++++ .../ApartmentManager/Handler/LoginHandler.cs | 13 +- .../ApartmentManager/View/BmApartmentsPage.xaml | 4 +- .../View/BmCreateApartmentPage.xaml | 2 +- .../ApartmentManager/View/BmCreateDefectPage.xaml | 2 +- .../ApartmentManager/View/BmDefectsPage.xaml | 4 +- .../ApartmentManager/View/BmEditApartmentPage.xaml | 2 +- .../ApartmentManager/View/BmEditDefectPage.xaml | 2 +- .../ApartmentManager/View/BmMainPage.xaml | 3 - .../ApartmentManager/View/BmResidentsPage.xaml | 2 +- .../ApartmentManager/View/BmSingleDefectPage.xaml | 2 +- .../ApartmentManager/View/BmUsersPage.xaml | 2 +- .../ViewModel/BmApartmentsViewModel.cs | 59 ++++ .../ViewModel/BmDefectsViewModel.cs | 106 +++++++ .../ViewModel/BmResidentsViewModel.cs | 54 ++++ .../ApartmentManager/ViewModel/BmUsersViewModel.cs | 54 ++++ .../ApartmentManager/ViewModel/BmViewModel.cs | 180 ----------- 22 files changed, 689 insertions(+), 532 deletions(-) create mode 100644 ApartmentManager/ApartmentManager/Handler/BmApartmentsHandler.cs create mode 100644 ApartmentManager/ApartmentManager/Handler/BmDefectsHandler.cs delete mode 100644 ApartmentManager/ApartmentManager/Handler/BmHandler.cs create mode 100644 ApartmentManager/ApartmentManager/Handler/BmResidentsHandler.cs create mode 100644 ApartmentManager/ApartmentManager/Handler/BmUsersHandler.cs create mode 100644 ApartmentManager/ApartmentManager/ViewModel/BmApartmentsViewModel.cs create mode 100644 ApartmentManager/ApartmentManager/ViewModel/BmDefectsViewModel.cs create mode 100644 ApartmentManager/ApartmentManager/ViewModel/BmResidentsViewModel.cs create mode 100644 ApartmentManager/ApartmentManager/ViewModel/BmUsersViewModel.cs delete mode 100644 ApartmentManager/ApartmentManager/ViewModel/BmViewModel.cs diff --git a/ApartmentManager/ApartmentManager/ApartmentManager.csproj b/ApartmentManager/ApartmentManager/ApartmentManager.csproj index 0f22d96..44f97b5 100644 --- a/ApartmentManager/ApartmentManager/ApartmentManager.csproj +++ b/ApartmentManager/ApartmentManager/ApartmentManager.csproj @@ -100,7 +100,10 @@ - + + + + @@ -117,7 +120,10 @@ - + + + + diff --git a/ApartmentManager/ApartmentManager/Handler/BmApartmentsHandler.cs b/ApartmentManager/ApartmentManager/Handler/BmApartmentsHandler.cs new file mode 100644 index 0000000..48a60e2 --- /dev/null +++ b/ApartmentManager/ApartmentManager/Handler/BmApartmentsHandler.cs @@ -0,0 +1,75 @@ +using ApartmentManager.Model; +using ApartmentManager.Persistency; +using ApartmentManager.Singletons; +using ApartmentManager.ViewModel; +using Newtonsoft.Json; +using System; +using System.Collections.ObjectModel; +using Windows.UI.Popups; + +namespace ApartmentManager.Handler +{ + public class BmApartmentsHandler + { + private BmApartmentsViewModel _vm; + + public BmApartmentsHandler(BmApartmentsViewModel vm) + { + _vm = vm; + } + + public void GetApartments() + { + BmSingleton.Instance.Apartments = JsonConvert.DeserializeObject>(ApiClient.GetData("api/Apartments/")); + } + + public void CreateApartment() + { + try + { + ApiClient.PostData("api/Apartments/", _vm.ApartmentTemplate); + GetApartments(); + _vm.ApartmentTemplate = new Apartment(); + } + catch (Exception e) + { + var msg = new MessageDialog(e.Message).ShowAsync(); + } + } + public void UpdateApartment() + { + try + { + ApiClient.PutData("api/Apartments/" + _vm.ApartmentTemplate.ApartmentId, _vm.ApartmentTemplate); + GetApartments(); + } + catch (Exception e) + { + var msg = new MessageDialog(e.Message).ShowAsync(); + } + } + public void DeleteApartment() + { + try + { + ApiClient.DeleteData("api/Apartments/" + _vm.ApartmentTemplate.ApartmentId); + BmSingleton.Instance.Apartments.Remove(_vm.ApartmentTemplate); + GetApartments(); + } + catch (Exception e) + { + var msg = new MessageDialog(e.Message).ShowAsync(); + } + } + + public async void UploadApartmentPlan() + { + _vm.ApartmentTemplate.PlanPicture = await ImgurPhotoUploader.UploadPhotoAsync(); + } + + public void ClearApartmentTemplate() + { + _vm.ApartmentTemplate = new Apartment(); + } + } +} diff --git a/ApartmentManager/ApartmentManager/Handler/BmDefectsHandler.cs b/ApartmentManager/ApartmentManager/Handler/BmDefectsHandler.cs new file mode 100644 index 0000000..919d026 --- /dev/null +++ b/ApartmentManager/ApartmentManager/Handler/BmDefectsHandler.cs @@ -0,0 +1,142 @@ +using ApartmentManager.Model; +using ApartmentManager.Persistency; +using ApartmentManager.Singletons; +using ApartmentManager.ViewModel; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using Windows.UI.Popups; + +namespace ApartmentManager.Handler +{ + public class BmDefectsHandler + { + private BmDefectsViewModel _vm; + + public BmDefectsHandler(BmDefectsViewModel vm) + { + _vm = vm; + } + + public void GetDefects() + { + var defects = JsonConvert.DeserializeObject>(ApiClient.GetData("api/Defects/")); + BmSingleton.Instance.Defects.Clear(); + foreach (var defect in defects) + { + defect.Pictures = JsonConvert.DeserializeObject>(ApiClient.GetData("api/DefectPicturesById/" + defect.DefectId)); + defect.Comments = JsonConvert.DeserializeObject>(ApiClient.GetData("api/DefectComments/" + defect.DefectId)); + BmSingleton.Instance.Defects.Add(defect); + } + } + + public void CreateDefect() + { + try + { + _vm.DefectTemplate.Status = "New"; + _vm.DefectTemplate.UploadDate = DateTime.Now; + var response = JsonConvert.DeserializeObject(ApiClient.PostData("api/Defects/", _vm.DefectTemplate)); + foreach (var defectPicture in _vm.DefectTemplate.Pictures) + { + defectPicture.DefectId = response.DefectId; + ApiClient.PostData("api/DefectPictures", defectPicture); + } + GetDefects(); + _vm.DefectTemplate = new Defect(); + } + catch (Exception e) + { + var msg = new MessageDialog(e.Message).ShowAsync(); + } + } + public void UpdateDefect() + { + try + { + ApiClient.PutData("api/Defects/" + _vm.DefectTemplate.DefectId, _vm.DefectTemplate); + var deletedDefectPictures = new List(_vm.DeletedDefectPictures); + var addedDefectPictures = new List(_vm.AddedDefectPictures); + + foreach (var defectPicture in deletedDefectPictures) + { + ApiClient.DeleteData("api/DefectPictures/" + defectPicture.Pictureid); + _vm.DeletedDefectPictures.Remove(defectPicture); + } + foreach (var defectPicture in addedDefectPictures) + { + defectPicture.DefectId = _vm.DefectTemplate.DefectId; + ApiClient.PostData("api/DefectPictures", defectPicture); + _vm.AddedDefectPictures.Remove(defectPicture); + } + GetDefects(); + } + catch (Exception e) + { + var msg = new MessageDialog(e.Message).ShowAsync(); + } + } + public void DeleteDefect() + { + try + { + ApiClient.DeleteData("api/Defects/" + _vm.DefectTemplate.DefectId); + BmSingleton.Instance.Defects.Remove(_vm.DefectTemplate); + GetDefects(); + } + catch (Exception e) + { + var msg = new MessageDialog(e.Message).ShowAsync(); + } + } + + public void ClearDefectTemplate() + { + _vm.DefectTemplate = new Defect(); + } + + public async void UploadDefectPicture() + { + if (_vm.DefectTemplate.Pictures == null) _vm.DefectTemplate.Pictures = new ObservableCollection(); + var picture = new DefectPicture() { Picture = await ImgurPhotoUploader.UploadPhotoAsync() }; + _vm.DefectTemplate.Pictures.Add(picture); + _vm.AddedDefectPictures.Add(picture); + } + + public void DeleteDefectPicture() + { + _vm.DefectTemplate.Pictures.Remove(_vm.SelectedDefectPicture); + } + + public void DeleteDefectPictureTemp() + { + _vm.DeletedDefectPictures.Add(_vm.SelectedDefectPicture); + _vm.DefectTemplate.Pictures.Remove(_vm.SelectedDefectPicture); + } + + public void CreateDefectComment() + { + try + { + var comment = new DefectComment() + { + Comment = _vm.NewDefectComment.Comment, + DefectId = _vm.DefectTemplate.DefectId, + Name = UserSingleton.Instance.CurrentUser.FirstName + " " + UserSingleton.Instance.CurrentUser.LastName, + Date = DateTimeOffset.Now + }; + if (!string.IsNullOrEmpty(comment.Comment)) + { + ApiClient.PostData("api/DefectComments/", comment); + _vm.DefectTemplate.Comments.Add(comment); + _vm.NewDefectComment = new DefectComment(); + } + } + catch (Exception e) + { + var msg = new MessageDialog(e.Message).ShowAsync(); + } + } + } +} diff --git a/ApartmentManager/ApartmentManager/Handler/BmHandler.cs b/ApartmentManager/ApartmentManager/Handler/BmHandler.cs deleted file mode 100644 index 8709180..0000000 --- a/ApartmentManager/ApartmentManager/Handler/BmHandler.cs +++ /dev/null @@ -1,331 +0,0 @@ -using System; -using System.Collections.ObjectModel; -using Windows.UI.Popups; -using ApartmentManager.Model; -using ApartmentManager.Persistency; -using ApartmentManager.ViewModel; -using Newtonsoft.Json; -using ApartmentManager.Singletons; -using System.Collections.Generic; - -namespace ApartmentManager.Handler -{ - public class BmHandler - { - private BmViewModel _vm; - - public BmHandler(BmViewModel vm) - { - _vm = vm; - } - - - #region APARTMENTS - - public void GetApartments() - { - BmSingleton.Instance.Apartments = JsonConvert.DeserializeObject>(ApiClient.GetData("api/Apartments/")); - } - - public void CreateApartment() - { - try - { - ApiClient.PostData("api/Apartments/", _vm.ApartmentTemplate); - GetApartments(); - _vm.ApartmentTemplate = new Apartment(); - } - catch (Exception e) - { - var msg = new MessageDialog(e.Message).ShowAsync(); - } - } - public void UpdateApartment() - { - try - { - ApiClient.PutData("api/Apartments/" + _vm.ApartmentTemplate.ApartmentId, _vm.ApartmentTemplate); - GetApartments(); - } - catch (Exception e) - { - var msg = new MessageDialog(e.Message).ShowAsync(); - } - } - public void DeleteApartment() - { - try - { - ApiClient.DeleteData("api/Apartments/" + _vm.ApartmentTemplate.ApartmentId); - BmSingleton.Instance.Apartments.Remove(_vm.ApartmentTemplate); - GetApartments(); - } - catch (Exception e) - { - var msg = new MessageDialog(e.Message).ShowAsync(); - } - } - - public async void UploadApartmentPlan() - { - _vm.ApartmentTemplate.PlanPicture = await ImgurPhotoUploader.UploadPhotoAsync(); - } - - public void ClearApartmentTemplate() - { - _vm.ApartmentTemplate = new Apartment(); - } - #endregion - - #region USERS - - public void GetUsers() - { - var users = JsonConvert.DeserializeObject>(ApiClient.GetData("api/Users/")); - BmSingleton.Instance.Users.Clear(); - foreach (var user in users) BmSingleton.Instance.Users.Add(user); - } - - public void CreateUser() - { - try - { - ApiClient.PostData("api/Users/", _vm.UserTemplate); - GetUsers(); - _vm.UserTemplate = new User(); - } - catch (Exception e) - { - var msg = new MessageDialog(e.Message).ShowAsync(); - } - } - public void UpdateUser() - { - try - { - ApiClient.PutData("api/Users/" + _vm.UserTemplate.Username, _vm.UserTemplate); - GetUsers(); - } - catch (Exception e) - { - var msg = new MessageDialog(e.Message).ShowAsync(); - } - } - public void DeleteUser() - { - try - { - ApiClient.DeleteData("api/Users/" + _vm.UserTemplate.Username); - BmSingleton.Instance.Users.Remove(_vm.UserTemplate); - GetUsers(); - } - catch (Exception e) - { - var msg = new MessageDialog(e.Message).ShowAsync(); - } - } - - public async void UploadUserPhoto() - { - var picture = await ImgurPhotoUploader.UploadPhotoAsync(); - if (picture != "") - { - _vm.UserTemplate.Picture = picture; - var tmp = _vm.UserTemplate; - _vm.UserTemplate = new User(); - _vm.UserTemplate = tmp; - } - } - - public void ClearUserTemplate() - { - _vm.UserTemplate = new User(); - } - #endregion - - #region RESIDENTS - - public void GetResidents() - { - var residents = JsonConvert.DeserializeObject>(ApiClient.GetData("api/Residents/")); - BmSingleton.Instance.Residents.Clear(); - foreach (var resident in residents) BmSingleton.Instance.Residents.Add(resident); - } - - public void CreateResident() - { - try - { - ApiClient.PostData("api/Residents/", _vm.ResidentTemplate); - GetResidents(); - _vm.ResidentTemplate = new Resident(); - } - catch (Exception e) - { - var msg = new MessageDialog(e.Message).ShowAsync(); - } - } - public void UpdateResident() - { - try - { - ApiClient.PutData("api/Residents/" + _vm.ResidentTemplate.ResidentId, _vm.ResidentTemplate); - GetResidents(); - } - catch (Exception e) - { - var msg = new MessageDialog(e.Message).ShowAsync(); - } - } - public void DeleteResident() - { - try - { - ApiClient.DeleteData("api/Residents/" + _vm.ResidentTemplate.ResidentId); - BmSingleton.Instance.Residents.Remove(_vm.ResidentTemplate); - GetResidents(); - } - catch (Exception e) - { - var msg = new MessageDialog(e.Message).ShowAsync(); - } - } - - public async void UploadResidentPhoto() - { - _vm.ResidentTemplate.Picture = await ImgurPhotoUploader.UploadPhotoAsync(); - var tmp = _vm.ResidentTemplate; - _vm.ResidentTemplate = new Resident(); - _vm.ResidentTemplate = tmp; - } - - public void ClearResidentTemplate() - { - _vm.ResidentTemplate = new Resident(); - } - #endregion - - #region DEFECTS - - public void GetDefects() - { - var defects = JsonConvert.DeserializeObject>(ApiClient.GetData("api/Defects/")); - BmSingleton.Instance.Defects.Clear(); - foreach (var defect in defects) - { - defect.Pictures = JsonConvert.DeserializeObject>(ApiClient.GetData("api/DefectPicturesById/" + defect.DefectId)); - defect.Comments = JsonConvert.DeserializeObject>(ApiClient.GetData("api/DefectComments/" + defect.DefectId)); - BmSingleton.Instance.Defects.Add(defect); - } - } - - public void CreateDefect() - { - try - { - _vm.DefectTemplate.Status = "New"; - _vm.DefectTemplate.UploadDate = DateTime.Now; - var response = JsonConvert.DeserializeObject(ApiClient.PostData("api/Defects/", _vm.DefectTemplate)); - foreach(var defectPicture in _vm.DefectTemplate.Pictures) - { - defectPicture.DefectId = response.DefectId; - ApiClient.PostData("api/DefectPictures", defectPicture); - } - GetDefects(); - _vm.DefectTemplate = new Defect(); - } - catch (Exception e) - { - var msg = new MessageDialog(e.Message).ShowAsync(); - } - } - public void UpdateDefect() - { - try - { - ApiClient.PutData("api/Defects/" + _vm.DefectTemplate.DefectId, _vm.DefectTemplate); - var deletedDefectPictures = new List(_vm.DeletedDefectPictures); - var addedDefectPictures = new List(_vm.AddedDefectPictures); - - foreach (var defectPicture in deletedDefectPictures) - { - ApiClient.DeleteData("api/DefectPictures/" + defectPicture.Pictureid); - _vm.DeletedDefectPictures.Remove(defectPicture); - } - foreach (var defectPicture in addedDefectPictures) - { - defectPicture.DefectId = _vm.DefectTemplate.DefectId; - ApiClient.PostData("api/DefectPictures", defectPicture); - addedDefectPictures.Remove(defectPicture); - } - GetDefects(); - } - catch (Exception e) - { - var msg = new MessageDialog(e.Message).ShowAsync(); - } - } - public void DeleteDefect() - { - try - { - ApiClient.DeleteData("api/Defects/" + _vm.DefectTemplate.DefectId); - BmSingleton.Instance.Defects.Remove(_vm.DefectTemplate); - GetDefects(); - } - catch (Exception e) - { - var msg = new MessageDialog(e.Message).ShowAsync(); - } - } - - public void ClearDefectTemplate() - { - _vm.DefectTemplate = new Defect(); - } - - public async void UploadDefectPicture() - { - if (_vm.DefectTemplate.Pictures == null) _vm.DefectTemplate.Pictures = new ObservableCollection(); - var picture = new DefectPicture() { Picture = await ImgurPhotoUploader.UploadPhotoAsync() }; - _vm.DefectTemplate.Pictures.Add(picture); - _vm.AddedDefectPictures.Add(picture); - } - - public void DeleteDefectPicture() - { - _vm.DefectTemplate.Pictures.Remove(_vm.SelectedDefectPicture); - } - - public void DeleteDefectPictureTemp() - { - _vm.DeletedDefectPictures.Add(_vm.SelectedDefectPicture); - _vm.DefectTemplate.Pictures.Remove(_vm.SelectedDefectPicture); - } - - public void CreateDefectComment() - { - try - { - var comment = new DefectComment() - { - Comment = _vm.NewDefectComment.Comment, - DefectId = _vm.DefectTemplate.DefectId, - Name = UserSingleton.Instance.CurrentUser.FirstName + " " + UserSingleton.Instance.CurrentUser.LastName, - Date = DateTimeOffset.Now - }; - if (!string.IsNullOrEmpty(comment.Comment)) - { - ApiClient.PostData("api/DefectComments/", comment); - _vm.DefectTemplate.Comments.Add(comment); - _vm.NewDefectComment = new DefectComment(); - } - } - catch (Exception e) - { - new MessageDialog(e.Message).ShowAsync(); - } - } - #endregion - } -} diff --git a/ApartmentManager/ApartmentManager/Handler/BmResidentsHandler.cs b/ApartmentManager/ApartmentManager/Handler/BmResidentsHandler.cs new file mode 100644 index 0000000..7e93393 --- /dev/null +++ b/ApartmentManager/ApartmentManager/Handler/BmResidentsHandler.cs @@ -0,0 +1,84 @@ +using ApartmentManager.Model; +using ApartmentManager.Persistency; +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 +{ + public class BmResidentsHandler + { + private BmResidentsViewModel _vm; + + public BmResidentsHandler(BmResidentsViewModel vm) + { + _vm = vm; + } + + public void GetResidents() + { + var residents = JsonConvert.DeserializeObject>(ApiClient.GetData("api/Residents/")); + BmSingleton.Instance.Residents.Clear(); + foreach (var resident in residents) BmSingleton.Instance.Residents.Add(resident); + } + + public void CreateResident() + { + try + { + ApiClient.PostData("api/Residents/", _vm.ResidentTemplate); + GetResidents(); + _vm.ResidentTemplate = new Resident(); + } + catch (Exception e) + { + var msg = new MessageDialog(e.Message).ShowAsync(); + } + } + public void UpdateResident() + { + try + { + ApiClient.PutData("api/Residents/" + _vm.ResidentTemplate.ResidentId, _vm.ResidentTemplate); + GetResidents(); + } + catch (Exception e) + { + var msg = new MessageDialog(e.Message).ShowAsync(); + } + } + public void DeleteResident() + { + try + { + ApiClient.DeleteData("api/Residents/" + _vm.ResidentTemplate.ResidentId); + BmSingleton.Instance.Residents.Remove(_vm.ResidentTemplate); + GetResidents(); + } + catch (Exception e) + { + var msg = new MessageDialog(e.Message).ShowAsync(); + } + } + + public async void UploadResidentPhoto() + { + _vm.ResidentTemplate.Picture = await ImgurPhotoUploader.UploadPhotoAsync(); + var tmp = _vm.ResidentTemplate; + _vm.ResidentTemplate = new Resident(); + _vm.ResidentTemplate = tmp; + } + + public void ClearResidentTemplate() + { + _vm.ResidentTemplate = new Resident(); + } + } +} diff --git a/ApartmentManager/ApartmentManager/Handler/BmUsersHandler.cs b/ApartmentManager/ApartmentManager/Handler/BmUsersHandler.cs new file mode 100644 index 0000000..5fe3a92 --- /dev/null +++ b/ApartmentManager/ApartmentManager/Handler/BmUsersHandler.cs @@ -0,0 +1,88 @@ +using ApartmentManager.Model; +using ApartmentManager.Persistency; +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 +{ + public class BmUsersHandler + { + private BmUsersViewModel _vm; + + public BmUsersHandler(BmUsersViewModel vm) + { + _vm = vm; + } + + public void GetUsers() + { + var users = JsonConvert.DeserializeObject>(ApiClient.GetData("api/Users/")); + BmSingleton.Instance.Users.Clear(); + foreach (var user in users) BmSingleton.Instance.Users.Add(user); + } + + public void CreateUser() + { + try + { + ApiClient.PostData("api/Users/", _vm.UserTemplate); + GetUsers(); + _vm.UserTemplate = new User(); + } + catch (Exception e) + { + var msg = new MessageDialog(e.Message).ShowAsync(); + } + } + public void UpdateUser() + { + try + { + ApiClient.PutData("api/Users/" + _vm.UserTemplate.Username, _vm.UserTemplate); + GetUsers(); + } + catch (Exception e) + { + var msg = new MessageDialog(e.Message).ShowAsync(); + } + } + public void DeleteUser() + { + try + { + ApiClient.DeleteData("api/Users/" + _vm.UserTemplate.Username); + BmSingleton.Instance.Users.Remove(_vm.UserTemplate); + GetUsers(); + } + catch (Exception e) + { + var msg = new MessageDialog(e.Message).ShowAsync(); + } + } + + public async void UploadUserPhoto() + { + var picture = await ImgurPhotoUploader.UploadPhotoAsync(); + if (picture != "") + { + _vm.UserTemplate.Picture = picture; + var tmp = _vm.UserTemplate; + _vm.UserTemplate = new User(); + _vm.UserTemplate = tmp; + } + } + + public void ClearUserTemplate() + { + _vm.UserTemplate = new User(); + } + } +} diff --git a/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs b/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs index 4f93cc1..7db0ba4 100644 --- a/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs @@ -75,11 +75,14 @@ namespace ApartmentManager.Handler // suppressing the initial entrance animation. if (UserSingleton.Instance.CurrentUser.IsBm) { - BmViewModel bvm = new BmViewModel(); - bvm.BmHandler.GetApartments(); - bvm.BmHandler.GetUsers(); - bvm.BmHandler.GetResidents(); - bvm.BmHandler.GetDefects(); + BmApartmentsViewModel bavm = new BmApartmentsViewModel(); + BmUsersViewModel buvm = new BmUsersViewModel(); + BmResidentsViewModel brvm = new BmResidentsViewModel(); + BmDefectsViewModel bdvm = new BmDefectsViewModel(); + bavm.BmApartmentsHandler.GetApartments(); + buvm.BmUsersHandler.GetUsers(); + brvm.BmResidentsHandler.GetResidents(); + bdvm.BmDefectsHandler.GetDefects(); appShell.AppFrame.Navigate(typeof(BmMainPage)); } else diff --git a/ApartmentManager/ApartmentManager/View/BmApartmentsPage.xaml b/ApartmentManager/ApartmentManager/View/BmApartmentsPage.xaml index 5dcff9e..78907a0 100644 --- a/ApartmentManager/ApartmentManager/View/BmApartmentsPage.xaml +++ b/ApartmentManager/ApartmentManager/View/BmApartmentsPage.xaml @@ -40,7 +40,7 @@ - + @@ -53,7 +53,7 @@ Icon="Add" Label="Create Apartment"> - + diff --git a/ApartmentManager/ApartmentManager/View/BmCreateApartmentPage.xaml b/ApartmentManager/ApartmentManager/View/BmCreateApartmentPage.xaml index 785310e..3c63754 100644 --- a/ApartmentManager/ApartmentManager/View/BmCreateApartmentPage.xaml +++ b/ApartmentManager/ApartmentManager/View/BmCreateApartmentPage.xaml @@ -11,7 +11,7 @@ mc:Ignorable="d"> - + diff --git a/ApartmentManager/ApartmentManager/View/BmCreateDefectPage.xaml b/ApartmentManager/ApartmentManager/View/BmCreateDefectPage.xaml index 8ac885b..e667583 100644 --- a/ApartmentManager/ApartmentManager/View/BmCreateDefectPage.xaml +++ b/ApartmentManager/ApartmentManager/View/BmCreateDefectPage.xaml @@ -11,7 +11,7 @@ mc:Ignorable="d"> - + diff --git a/ApartmentManager/ApartmentManager/View/BmDefectsPage.xaml b/ApartmentManager/ApartmentManager/View/BmDefectsPage.xaml index 5dabf95..46150d3 100644 --- a/ApartmentManager/ApartmentManager/View/BmDefectsPage.xaml +++ b/ApartmentManager/ApartmentManager/View/BmDefectsPage.xaml @@ -40,7 +40,7 @@ - + @@ -53,7 +53,7 @@ Icon="Add" Label="Create Apartment"> - + diff --git a/ApartmentManager/ApartmentManager/View/BmEditApartmentPage.xaml b/ApartmentManager/ApartmentManager/View/BmEditApartmentPage.xaml index e69ea48..46ea641 100644 --- a/ApartmentManager/ApartmentManager/View/BmEditApartmentPage.xaml +++ b/ApartmentManager/ApartmentManager/View/BmEditApartmentPage.xaml @@ -10,7 +10,7 @@ xmlns:vm="using:ApartmentManager.ViewModel" mc:Ignorable="d"> - + diff --git a/ApartmentManager/ApartmentManager/View/BmEditDefectPage.xaml b/ApartmentManager/ApartmentManager/View/BmEditDefectPage.xaml index 840f59d..5089904 100644 --- a/ApartmentManager/ApartmentManager/View/BmEditDefectPage.xaml +++ b/ApartmentManager/ApartmentManager/View/BmEditDefectPage.xaml @@ -11,7 +11,7 @@ mc:Ignorable="d"> - + diff --git a/ApartmentManager/ApartmentManager/View/BmMainPage.xaml b/ApartmentManager/ApartmentManager/View/BmMainPage.xaml index adf2364..2fd5ab2 100644 --- a/ApartmentManager/ApartmentManager/View/BmMainPage.xaml +++ b/ApartmentManager/ApartmentManager/View/BmMainPage.xaml @@ -9,9 +9,6 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:vm="using:ApartmentManager.ViewModel" mc:Ignorable="d"> - - - - + diff --git a/ApartmentManager/ApartmentManager/View/BmSingleDefectPage.xaml b/ApartmentManager/ApartmentManager/View/BmSingleDefectPage.xaml index 28976bd..2e7a935 100644 --- a/ApartmentManager/ApartmentManager/View/BmSingleDefectPage.xaml +++ b/ApartmentManager/ApartmentManager/View/BmSingleDefectPage.xaml @@ -9,7 +9,7 @@ mc:Ignorable="d"> - + diff --git a/ApartmentManager/ApartmentManager/View/BmUsersPage.xaml b/ApartmentManager/ApartmentManager/View/BmUsersPage.xaml index a57d14d..77c60f7 100644 --- a/ApartmentManager/ApartmentManager/View/BmUsersPage.xaml +++ b/ApartmentManager/ApartmentManager/View/BmUsersPage.xaml @@ -39,7 +39,7 @@ - + diff --git a/ApartmentManager/ApartmentManager/ViewModel/BmApartmentsViewModel.cs b/ApartmentManager/ApartmentManager/ViewModel/BmApartmentsViewModel.cs new file mode 100644 index 0000000..5d51d3f --- /dev/null +++ b/ApartmentManager/ApartmentManager/ViewModel/BmApartmentsViewModel.cs @@ -0,0 +1,59 @@ +using ApartmentManager.Annotations; +using ApartmentManager.Common; +using ApartmentManager.Handler; +using ApartmentManager.Model; +using ApartmentManager.Singletons; +using System.ComponentModel; +using System.Runtime.CompilerServices; +using System.Windows.Input; + +namespace ApartmentManager.ViewModel +{ + public class BmApartmentsViewModel : INotifyPropertyChanged + { + public BmSingleton BmSingleton { get; } = BmSingleton.Instance; + public BmApartmentsHandler BmApartmentsHandler { get; } + + public int[] FloorNumbers { get; } = new int[] { 0, 1, 2, 3, 4 }; + public int SelectedFloor { get; set; } + + public ICommand CreateApartmentCommand { get; } + public ICommand DeleteApartmentCommand { get; } + public ICommand UpdateApartmentCommand { get; } + public ICommand UploadApartmentPlanCommand { get; } + public ICommand ClearApartmentTemplateCommand { get; } + public ICommand GetApartmentsCommand { get; } + + private static Apartment _apartmentTemplate = new Apartment(); + + public BmApartmentsViewModel() + { + BmApartmentsHandler = new BmApartmentsHandler(this); + + CreateApartmentCommand = new RelayCommand(BmApartmentsHandler.CreateApartment); + DeleteApartmentCommand = new RelayCommand(BmApartmentsHandler.DeleteApartment); + UpdateApartmentCommand = new RelayCommand(BmApartmentsHandler.UpdateApartment); + UploadApartmentPlanCommand = new RelayCommand(BmApartmentsHandler.UploadApartmentPlan); + ClearApartmentTemplateCommand = new RelayCommand(BmApartmentsHandler.ClearApartmentTemplate); + GetApartmentsCommand = new RelayCommand(BmApartmentsHandler.GetApartments); + } + + public Apartment ApartmentTemplate + { + get => _apartmentTemplate; + set + { + _apartmentTemplate = value; + OnPropertyChanged(); + } + } + + public event PropertyChangedEventHandler PropertyChanged; + + [NotifyPropertyChangedInvocator] + protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + } +} diff --git a/ApartmentManager/ApartmentManager/ViewModel/BmDefectsViewModel.cs b/ApartmentManager/ApartmentManager/ViewModel/BmDefectsViewModel.cs new file mode 100644 index 0000000..b6abe7e --- /dev/null +++ b/ApartmentManager/ApartmentManager/ViewModel/BmDefectsViewModel.cs @@ -0,0 +1,106 @@ +using System.ComponentModel; +using System.Runtime.CompilerServices; +using System.Windows.Input; +using ApartmentManager.Annotations; +using ApartmentManager.Common; +using ApartmentManager.Model; +using ApartmentManager.Singletons; +using ApartmentManager.Handler; +using System.Collections.Generic; + +namespace ApartmentManager.ViewModel +{ + public class BmDefectsViewModel : INotifyPropertyChanged + { + public BmSingleton BmSingleton { get; } = BmSingleton.Instance; + public BmDefectsHandler BmDefectsHandler { get; } + + public ICommand CreateDefectCommand { get; } + public ICommand DeleteDefectCommand { get; } + public ICommand UpdateDefectCommand { get; } + public ICommand ClearDefectTemplateCommand { get; } + public ICommand GetDefectsCommand { get; } + public ICommand UploadDefectPictureCommand { get; } + public ICommand UploadDefectPictureTempCommand { get; } + public ICommand DeleteDefectPictureCommand { get; } + public ICommand DeleteDefectPictureTempCommand { get; } + public ICommand CreateDefectCommentCommand { get; } + + private static Defect _defectTemplate = new Defect(); + private static DefectPicture _selectedDefectPicture = new DefectPicture(); + private static List _deletedDefectPictures = new List(); + private static List _addedDefectPictures = new List(); + private static DefectComment _newDefectComment = new DefectComment(); + + public BmDefectsViewModel() + { + BmDefectsHandler = new BmDefectsHandler(this); + + CreateDefectCommand = new RelayCommand(BmDefectsHandler.CreateDefect); + DeleteDefectCommand = new RelayCommand(BmDefectsHandler.DeleteDefect); + UpdateDefectCommand = new RelayCommand(BmDefectsHandler.UpdateDefect); + ClearDefectTemplateCommand = new RelayCommand(BmDefectsHandler.ClearDefectTemplate); + UploadDefectPictureCommand = new RelayCommand(BmDefectsHandler.UploadDefectPicture); + DeleteDefectPictureCommand = new RelayCommand(BmDefectsHandler.DeleteDefectPicture); + DeleteDefectPictureTempCommand = new RelayCommand(BmDefectsHandler.DeleteDefectPictureTemp); + GetDefectsCommand = new RelayCommand(BmDefectsHandler.GetDefects); + CreateDefectCommentCommand = new RelayCommand(BmDefectsHandler.CreateDefectComment); + } + + public Defect DefectTemplate + { + get => _defectTemplate; + set + { + _defectTemplate = value; + OnPropertyChanged(); + } + } + + public DefectPicture SelectedDefectPicture + { + get => _selectedDefectPicture; + set + { + _selectedDefectPicture = value; + OnPropertyChanged(); + } + } + + public List DeletedDefectPictures + { + get => _deletedDefectPictures; + set + { + _deletedDefectPictures = value; + } + } + + public List AddedDefectPictures + { + get => _addedDefectPictures; + set + { + _addedDefectPictures = value; + } + } + + public DefectComment NewDefectComment + { + get => _newDefectComment; + set + { + _newDefectComment = value; + OnPropertyChanged(); + } + } + + public event PropertyChangedEventHandler PropertyChanged; + + [NotifyPropertyChangedInvocator] + protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + } +} diff --git a/ApartmentManager/ApartmentManager/ViewModel/BmResidentsViewModel.cs b/ApartmentManager/ApartmentManager/ViewModel/BmResidentsViewModel.cs new file mode 100644 index 0000000..ce18bf7 --- /dev/null +++ b/ApartmentManager/ApartmentManager/ViewModel/BmResidentsViewModel.cs @@ -0,0 +1,54 @@ +using ApartmentManager.Annotations; +using ApartmentManager.Common; +using ApartmentManager.Handler; +using ApartmentManager.Model; +using ApartmentManager.Singletons; +using System.ComponentModel; +using System.Runtime.CompilerServices; +using System.Windows.Input; + +namespace ApartmentManager.ViewModel +{ + public class BmResidentsViewModel : INotifyPropertyChanged + { + public BmSingleton BmSingleton { get; } = BmSingleton.Instance; + public BmResidentsHandler BmResidentsHandler { get; } + + public ICommand CreateResidentCommand { get; } + public ICommand DeleteResidentCommand { get; } + public ICommand UpdateResidentCommand { get; } + public ICommand UploadResidentPhotoCommand { get; } + public ICommand ClearResidentTemplateCommand { get; } + + private static Resident _residentTemplate = new Resident(); + + public BmResidentsViewModel() + { + BmResidentsHandler = new BmResidentsHandler(this); + + CreateResidentCommand = new RelayCommand(BmResidentsHandler.CreateResident); + DeleteResidentCommand = new RelayCommand(BmResidentsHandler.DeleteResident); + UpdateResidentCommand = new RelayCommand(BmResidentsHandler.UpdateResident); + UploadResidentPhotoCommand = new RelayCommand(BmResidentsHandler.UploadResidentPhoto); + ClearResidentTemplateCommand = new RelayCommand(BmResidentsHandler.ClearResidentTemplate); + } + public Resident ResidentTemplate + { + get => _residentTemplate; + set + { + _residentTemplate = value; + OnPropertyChanged(); + } + } + + public event PropertyChangedEventHandler PropertyChanged; + + [NotifyPropertyChangedInvocator] + protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + } +} + diff --git a/ApartmentManager/ApartmentManager/ViewModel/BmUsersViewModel.cs b/ApartmentManager/ApartmentManager/ViewModel/BmUsersViewModel.cs new file mode 100644 index 0000000..8f6e1ac --- /dev/null +++ b/ApartmentManager/ApartmentManager/ViewModel/BmUsersViewModel.cs @@ -0,0 +1,54 @@ +using ApartmentManager.Annotations; +using ApartmentManager.Common; +using ApartmentManager.Handler; +using ApartmentManager.Model; +using ApartmentManager.Singletons; +using System.ComponentModel; +using System.Runtime.CompilerServices; +using System.Windows.Input; + +namespace ApartmentManager.ViewModel +{ + public class BmUsersViewModel : INotifyPropertyChanged + { + public BmSingleton BmSingleton { get; } = BmSingleton.Instance; + public BmUsersHandler BmUsersHandler { get; } + + public ICommand CreateUserCommand { get; } + public ICommand DeleteUserCommand { get; } + public ICommand UpdateUserCommand { get; } + public ICommand UploadUserPhotoCommand { get; } + public ICommand ClearUserTemplateCommand { get; } + + private static User _userTemplate = new User(); + + public BmUsersViewModel() + { + BmUsersHandler = new BmUsersHandler(this); + + CreateUserCommand = new RelayCommand(BmUsersHandler.CreateUser); + DeleteUserCommand = new RelayCommand(BmUsersHandler.DeleteUser); + UpdateUserCommand = new RelayCommand(BmUsersHandler.UpdateUser); + UploadUserPhotoCommand = new RelayCommand(BmUsersHandler.UploadUserPhoto); + ClearUserTemplateCommand = new RelayCommand(BmUsersHandler.ClearUserTemplate); + } + + public User UserTemplate + { + get => _userTemplate; + set + { + _userTemplate = value; + OnPropertyChanged(); + } + } + + public event PropertyChangedEventHandler PropertyChanged; + + [NotifyPropertyChangedInvocator] + protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + } +} diff --git a/ApartmentManager/ApartmentManager/ViewModel/BmViewModel.cs b/ApartmentManager/ApartmentManager/ViewModel/BmViewModel.cs deleted file mode 100644 index 736ca7c..0000000 --- a/ApartmentManager/ApartmentManager/ViewModel/BmViewModel.cs +++ /dev/null @@ -1,180 +0,0 @@ -using System.ComponentModel; -using System.Runtime.CompilerServices; -using System.Windows.Input; -using ApartmentManager.Annotations; -using ApartmentManager.Common; -using ApartmentManager.Model; -using ApartmentManager.Singletons; -using ApartmentManager.Handler; -using System.Collections.Generic; - -namespace ApartmentManager.ViewModel -{ - public class BmViewModel : INotifyPropertyChanged - { - public BmSingleton BmSingleton { get; } = BmSingleton.Instance; - public BmHandler BmHandler { get; } - - public int[] FloorNumbers { get; } = new int[] { 0, 1, 2, 3, 4 }; - public int SelectedFloor { get; set; } - - public ICommand CreateApartmentCommand { get; } - public ICommand DeleteApartmentCommand { get; } - public ICommand UpdateApartmentCommand { get; } - public ICommand UploadApartmentPlanCommand { get; } - public ICommand ClearApartmentTemplateCommand { get; } - public ICommand GetApartmentsCommand { get; } - - public ICommand CreateUserCommand { get; } - public ICommand DeleteUserCommand { get; } - public ICommand UpdateUserCommand { get; } - public ICommand UploadUserPhotoCommand { get; } - public ICommand ClearUserTemplateCommand { get; } - - public ICommand CreateResidentCommand { get; } - public ICommand DeleteResidentCommand { get; } - public ICommand UpdateResidentCommand { get; } - public ICommand UploadResidentPhotoCommand { get; } - public ICommand ClearResidentTemplateCommand { get; } - - public ICommand CreateDefectCommand { get; } - public ICommand DeleteDefectCommand { get; } - public ICommand UpdateDefectCommand { get; } - public ICommand ClearDefectTemplateCommand { get; } - public ICommand GetDefectsCommand { get; } - public ICommand UploadDefectPictureCommand { get; } - public ICommand UploadDefectPictureTempCommand { get; } - public ICommand DeleteDefectPictureCommand { get; } - public ICommand DeleteDefectPictureTempCommand { get; } - public ICommand CreateDefectCommentCommand { get; } - - private static Apartment _apartmentTemplate = new Apartment(); - private static User _userTemplate = new User(); - private static Resident _residentTemplate = new Resident(); - private static Defect _defectTemplate = new Defect(); - private static DefectPicture _selectedDefectPicture = new DefectPicture(); - private static List _deletedDefectPictures = new List(); - private static List _addedDefectPictures = new List(); - private static DefectComment _newDefectComment = new DefectComment(); - - public BmViewModel() - { - BmHandler = new BmHandler(this); - - CreateApartmentCommand = new RelayCommand(BmHandler.CreateApartment); - DeleteApartmentCommand = new RelayCommand(BmHandler.DeleteApartment); - UpdateApartmentCommand = new RelayCommand(BmHandler.UpdateApartment); - UploadApartmentPlanCommand = new RelayCommand(BmHandler.UploadApartmentPlan); - ClearApartmentTemplateCommand = new RelayCommand(BmHandler.ClearApartmentTemplate); - GetApartmentsCommand = new RelayCommand(BmHandler.GetApartments); - - CreateUserCommand = new RelayCommand(BmHandler.CreateUser); - DeleteUserCommand = new RelayCommand(BmHandler.DeleteUser); - UpdateUserCommand = new RelayCommand(BmHandler.UpdateUser); - UploadUserPhotoCommand = new RelayCommand(BmHandler.UploadUserPhoto); - ClearUserTemplateCommand = new RelayCommand(BmHandler.ClearUserTemplate); - - CreateResidentCommand = new RelayCommand(BmHandler.CreateResident); - DeleteResidentCommand = new RelayCommand(BmHandler.DeleteResident); - UpdateResidentCommand = new RelayCommand(BmHandler.UpdateResident); - UploadResidentPhotoCommand = new RelayCommand(BmHandler.UploadResidentPhoto); - ClearResidentTemplateCommand = new RelayCommand(BmHandler.ClearResidentTemplate); - - CreateDefectCommand = new RelayCommand(BmHandler.CreateDefect); - DeleteDefectCommand = new RelayCommand(BmHandler.DeleteDefect); - UpdateDefectCommand = new RelayCommand(BmHandler.UpdateDefect); - ClearDefectTemplateCommand = new RelayCommand(BmHandler.ClearDefectTemplate); - UploadDefectPictureCommand = new RelayCommand(BmHandler.UploadDefectPicture); - DeleteDefectPictureCommand = new RelayCommand(BmHandler.DeleteDefectPicture); - DeleteDefectPictureTempCommand = new RelayCommand(BmHandler.DeleteDefectPictureTemp); - GetDefectsCommand = new RelayCommand(BmHandler.GetDefects); - CreateDefectCommentCommand = new RelayCommand(BmHandler.CreateDefectComment); - } - - public Apartment ApartmentTemplate - { - get => _apartmentTemplate; - set - { - _apartmentTemplate = value; - OnPropertyChanged(); - } - } - - public User UserTemplate - { - get => _userTemplate; - set - { - _userTemplate = value; - OnPropertyChanged(); - } - } - - public Resident ResidentTemplate - { - get => _residentTemplate; - set - { - _residentTemplate = value; - OnPropertyChanged(); - } - } - - public Defect DefectTemplate - { - get => _defectTemplate; - set - { - _defectTemplate = value; - OnPropertyChanged(); - } - } - - public DefectPicture SelectedDefectPicture - { - get => _selectedDefectPicture; - set - { - _selectedDefectPicture = value; - OnPropertyChanged(); - } - } - - public List DeletedDefectPictures - { - get => _deletedDefectPictures; - set - { - _deletedDefectPictures = value; - } - } - - public List AddedDefectPictures - { - get => _addedDefectPictures; - set - { - _addedDefectPictures = value; - } - } - - public DefectComment NewDefectComment - { - get => _newDefectComment; - set - { - _newDefectComment = value; - OnPropertyChanged(); - } - } - - public event PropertyChangedEventHandler PropertyChanged; - - [NotifyPropertyChangedInvocator] - protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) - { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - } - } -} -- cgit v1.2.3