From ab9b9a75ec6abfd85f7ccae6aee08ec9e9e35497 Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Sat, 27 May 2017 15:06:12 +0200 Subject: Added apartment management functionality. --- ApartmentManager/ApartmentManager.sln | 6 +- .../ApartmentManager/ApartmentManager.csproj | 60 +++++---- ApartmentManager/ApartmentManager/AppShell.xaml.cs | 28 ++++- .../ApartmentManager/Handler/BmHandler.cs | 75 ++++++++++++ .../ApartmentManager/Model/Apartment.cs | 45 +++---- .../ApartmentManager/Singletons/BmSingleton.cs | 18 +++ .../ApartmentManager/View/BmApartmentsPage.xaml | 134 +++++++++++++++++++++ .../ApartmentManager/View/BmApartmentsPage.xaml.cs | 29 +++++ .../View/BmCreateApartmentPage.xaml | 81 +++++++++++++ .../View/BmCreateApartmentPage.xaml.cs | 15 +++ .../ApartmentManager/View/BmEditApartmentPage.xaml | 87 +++++++++++++ .../View/BmEditApartmentPage.xaml.cs | 15 +++ .../ApartmentManager/ViewModel/BmViewModel.cs | 61 ++++++++++ 13 files changed, 602 insertions(+), 52 deletions(-) create mode 100644 ApartmentManager/ApartmentManager/Handler/BmHandler.cs create mode 100644 ApartmentManager/ApartmentManager/Singletons/BmSingleton.cs create mode 100644 ApartmentManager/ApartmentManager/View/BmApartmentsPage.xaml create mode 100644 ApartmentManager/ApartmentManager/View/BmApartmentsPage.xaml.cs create mode 100644 ApartmentManager/ApartmentManager/View/BmCreateApartmentPage.xaml create mode 100644 ApartmentManager/ApartmentManager/View/BmCreateApartmentPage.xaml.cs create mode 100644 ApartmentManager/ApartmentManager/View/BmEditApartmentPage.xaml create mode 100644 ApartmentManager/ApartmentManager/View/BmEditApartmentPage.xaml.cs create mode 100644 ApartmentManager/ApartmentManager/ViewModel/BmViewModel.cs diff --git a/ApartmentManager/ApartmentManager.sln b/ApartmentManager/ApartmentManager.sln index 3cb16cf..86bb4ee 100644 --- a/ApartmentManager/ApartmentManager.sln +++ b/ApartmentManager/ApartmentManager.sln @@ -1,9 +1,12 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26403.7 +VisualStudioVersion = 15.0.26430.6 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApartmentManager", "ApartmentManager\ApartmentManager.csproj", "{95401ED6-D03C-417D-8897-81B5454D2426}" + ProjectSection(ProjectDependencies) = postProject + {D777744A-9676-4193-BD59-6F30C724C87A} = {D777744A-9676-4193-BD59-6F30C724C87A} + EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HousingWebApi", "HousingWebApi\HousingWebApi.csproj", "{D777744A-9676-4193-BD59-6F30C724C87A}" EndProject @@ -42,7 +45,6 @@ Global {95401ED6-D03C-417D-8897-81B5454D2426}.Release|x86.Build.0 = Release|x86 {95401ED6-D03C-417D-8897-81B5454D2426}.Release|x86.Deploy.0 = Release|x86 {D777744A-9676-4193-BD59-6F30C724C87A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D777744A-9676-4193-BD59-6F30C724C87A}.Debug|Any CPU.Build.0 = Debug|Any CPU {D777744A-9676-4193-BD59-6F30C724C87A}.Debug|ARM.ActiveCfg = Debug|Any CPU {D777744A-9676-4193-BD59-6F30C724C87A}.Debug|ARM.Build.0 = Debug|Any CPU {D777744A-9676-4193-BD59-6F30C724C87A}.Debug|x64.ActiveCfg = Debug|Any CPU diff --git a/ApartmentManager/ApartmentManager/ApartmentManager.csproj b/ApartmentManager/ApartmentManager/ApartmentManager.csproj index 81f44b5..2a04477 100644 --- a/ApartmentManager/ApartmentManager/ApartmentManager.csproj +++ b/ApartmentManager/ApartmentManager/ApartmentManager.csproj @@ -100,15 +100,14 @@ - - + - + @@ -119,7 +118,7 @@ - + @@ -134,23 +133,29 @@ ApartmentPage.xaml - - BoardMemberManageApartment.xaml + + BmChangesPage.xaml - - BoardMembersDefectsPage.xaml + + BmContractOwnersPage.xaml - - BoardMembersMainPage.xaml + + BmEditApartmentPage.xaml - - BoardMemberCreateApartmentPage.xaml + + BmResidentsPage.xaml - - DefectsPicturesBoard.xaml + + BmApartmentsPage.xaml - - InfoForBoardMembers.xaml + + BmDefectsPage.xaml + + + BmMainPage.xaml + + + BmCreateApartmentPage.xaml LoginPage.xaml @@ -210,27 +215,35 @@ 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 @@ -261,6 +274,9 @@ 5.3.3 + + 2.0.0 + diff --git a/ApartmentManager/ApartmentManager/AppShell.xaml.cs b/ApartmentManager/ApartmentManager/AppShell.xaml.cs index b1a88c6..dbe9c89 100644 --- a/ApartmentManager/ApartmentManager/AppShell.xaml.cs +++ b/ApartmentManager/ApartmentManager/AppShell.xaml.cs @@ -63,15 +63,23 @@ namespace ApartmentManager { Symbol = Symbol.Home, Label = "Home", - DestPage = typeof(BoardMembersMainPage), + DestPage = typeof(BmMainPage), IsSelected = true }, new NavMenuItem() { Symbol = Symbol.Comment, - Label = "Defects", - DestPage = typeof(BoardMembersDefectsPage), + Label = "Apartments", + DestPage = typeof(BmApartmentsPage), + IsSelected = false + }, + + new NavMenuItem() + { + Symbol = Symbol.Comment, + Label = "Contract owners", + DestPage = typeof(BmContractOwnersPage), IsSelected = false }, @@ -79,15 +87,23 @@ namespace ApartmentManager { Symbol = Symbol.Bookmarks, Label = "Residents", - DestPage = typeof(InfoForBoardMembers), + DestPage = typeof(BmResidentsPage), IsSelected = false }, new NavMenuItem() { Symbol = Symbol.Bookmarks, - Label = "Apartments", - DestPage = typeof(BoardMembersMainPage), + Label = "Defects", + DestPage = typeof(BmDefectsPage), + IsSelected = false + }, + + new NavMenuItem() + { + Symbol = Symbol.Bookmarks, + Label = "Changes", + DestPage = typeof(BmChangesPage), IsSelected = false } }); diff --git a/ApartmentManager/ApartmentManager/Handler/BmHandler.cs b/ApartmentManager/ApartmentManager/Handler/BmHandler.cs new file mode 100644 index 0000000..2b6b5b0 --- /dev/null +++ b/ApartmentManager/ApartmentManager/Handler/BmHandler.cs @@ -0,0 +1,75 @@ +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; + +namespace ApartmentManager.Handler +{ + public class BmHandler + { + private BmViewModel _vm; + + public BmHandler(BmViewModel 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/Model/Apartment.cs b/ApartmentManager/ApartmentManager/Model/Apartment.cs index 74fe410..a32c081 100644 --- a/ApartmentManager/ApartmentManager/Model/Apartment.cs +++ b/ApartmentManager/ApartmentManager/Model/Apartment.cs @@ -1,37 +1,38 @@ -namespace ApartmentManager.Model +using ApartmentManager.Annotations; +using System.ComponentModel; +using System.Runtime.CompilerServices; + +namespace ApartmentManager.Model { - public class Apartment + public class Apartment : INotifyPropertyChanged { public int ApartmentId { get; set; } - public double? Size { get; set; } - public int? NumberOfRooms { get; set; } - public double? MonthlyCharge { get; set; } - public int? Floor { get; set; } + public double Size { get; set; } + public int NumberOfRooms { get; set; } + public double MonthlyCharge { get; set; } + public int Floor { get; set; } public string Address { get; set; } - public string PlanPicture { get; set; } + private string _planPicture; public Apartment() { } - public Apartment(int apartmentId, double? size, int? numberOfRooms, double? monthlyCharge, int? floor, string address) + public string PlanPicture { - ApartmentId = apartmentId; - Size = size; - NumberOfRooms = numberOfRooms; - MonthlyCharge = monthlyCharge; - Floor = floor; - Address = address; + get => _planPicture; + set + { + _planPicture = value; + OnPropertyChanged(nameof(PlanPicture)); + } } - //public override string ToString() - //{ - // return string.Format( - // "Apartment No: {0} Size: {1} NoOfRooms: {2} MonthlyCharge: {3} Floor: {4} Address: {5}", - // ApartmentNumber, Size, NumberOfRooms, MonthlyCharge, Floor, Address); - //} + public event PropertyChangedEventHandler PropertyChanged; - public override string ToString() + [NotifyPropertyChangedInvocator] + protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { - return string.Format($"Apartment number: {ApartmentId}, Size: {Size} Number of rooms: {NumberOfRooms}, Monthly charge: {MonthlyCharge}, Floor: {Floor}, Address: {Address}"); + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } } } diff --git a/ApartmentManager/ApartmentManager/Singletons/BmSingleton.cs b/ApartmentManager/ApartmentManager/Singletons/BmSingleton.cs new file mode 100644 index 0000000..966390c --- /dev/null +++ b/ApartmentManager/ApartmentManager/Singletons/BmSingleton.cs @@ -0,0 +1,18 @@ +using ApartmentManager.Model; +using System.Collections.ObjectModel; + +namespace ApartmentManager.Singletons +{ + public class BmSingleton + { + private static BmSingleton _instance; + public static BmSingleton Instance => _instance ?? (_instance = new BmSingleton()); + + public ObservableCollection Apartments { get; set; } + public ObservableCollection Users { get; set; } + public ObservableCollection Residents { get; set; } + public ObservableCollection Defects { get; set; } + + private BmSingleton() { } + } +} diff --git a/ApartmentManager/ApartmentManager/View/BmApartmentsPage.xaml b/ApartmentManager/ApartmentManager/View/BmApartmentsPage.xaml new file mode 100644 index 0000000..ffc28c2 --- /dev/null +++ b/ApartmentManager/ApartmentManager/View/BmApartmentsPage.xaml @@ -0,0 +1,134 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +