From 8d651eff96f623cba3e75d5474a7e69736962db5 Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Sat, 27 May 2017 22:38:14 +0200 Subject: Added managing users feature. --- .../ApartmentManager/ApartmentManager.csproj | 14 +- ApartmentManager/ApartmentManager/AppShell.xaml.cs | 2 +- .../ApartmentManager/Handler/BmHandler.cs | 66 ++++++++ .../ApartmentManager/Handler/LoginHandler.cs | 1 + ApartmentManager/ApartmentManager/Model/User.cs | 11 +- .../Persistency/ImgurPhotoUploader.cs | 23 ++- .../ApartmentManager/Singletons/BmSingleton.cs | 1 + .../ApartmentManager/View/ApartmentDefectPage.xaml | 2 +- .../View/BmContractOwnersPage.xaml | 11 -- .../View/BmContractOwnersPage.xaml.cs | 30 ---- .../ApartmentManager/View/BmMainPage.xaml | 2 +- .../ApartmentManager/View/BmUsersPage.xaml | 173 +++++++++++++++++++++ .../ApartmentManager/View/BmUsersPage.xaml.cs | 30 ++++ .../ApartmentManager/ViewModel/BmViewModel.cs | 23 +++ 14 files changed, 323 insertions(+), 66 deletions(-) delete mode 100644 ApartmentManager/ApartmentManager/View/BmContractOwnersPage.xaml delete mode 100644 ApartmentManager/ApartmentManager/View/BmContractOwnersPage.xaml.cs create mode 100644 ApartmentManager/ApartmentManager/View/BmUsersPage.xaml create mode 100644 ApartmentManager/ApartmentManager/View/BmUsersPage.xaml.cs diff --git a/ApartmentManager/ApartmentManager/ApartmentManager.csproj b/ApartmentManager/ApartmentManager/ApartmentManager.csproj index 2a04477..2378b79 100644 --- a/ApartmentManager/ApartmentManager/ApartmentManager.csproj +++ b/ApartmentManager/ApartmentManager/ApartmentManager.csproj @@ -136,9 +136,6 @@ BmChangesPage.xaml - - BmContractOwnersPage.xaml - BmEditApartmentPage.xaml @@ -157,6 +154,9 @@ BmCreateApartmentPage.xaml + + BmUsersPage.xaml + LoginPage.xaml @@ -219,10 +219,6 @@ Designer MSBuild:Compile - - Designer - MSBuild:Compile - Designer MSBuild:Compile @@ -247,6 +243,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/ApartmentManager/ApartmentManager/AppShell.xaml.cs b/ApartmentManager/ApartmentManager/AppShell.xaml.cs index dbe9c89..7332ad7 100644 --- a/ApartmentManager/ApartmentManager/AppShell.xaml.cs +++ b/ApartmentManager/ApartmentManager/AppShell.xaml.cs @@ -79,7 +79,7 @@ namespace ApartmentManager { Symbol = Symbol.Comment, Label = "Contract owners", - DestPage = typeof(BmContractOwnersPage), + DestPage = typeof(BmUsersPage), IsSelected = false }, diff --git a/ApartmentManager/ApartmentManager/Handler/BmHandler.cs b/ApartmentManager/ApartmentManager/Handler/BmHandler.cs index 27dc827..2cbffea 100644 --- a/ApartmentManager/ApartmentManager/Handler/BmHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/BmHandler.cs @@ -76,6 +76,72 @@ namespace ApartmentManager.Handler } #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() diff --git a/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs b/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs index e41f5ed..e4d9721 100644 --- a/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs @@ -77,6 +77,7 @@ namespace ApartmentManager.Handler { BmViewModel bvm = new BmViewModel(); bvm.BmHandler.GetApartments(); + bvm.BmHandler.GetUsers(); bvm.BmHandler.GetResidents(); appShell.AppFrame.Navigate(typeof(BmMainPage)); } diff --git a/ApartmentManager/ApartmentManager/Model/User.cs b/ApartmentManager/ApartmentManager/Model/User.cs index f5da6fd..26a6b29 100644 --- a/ApartmentManager/ApartmentManager/Model/User.cs +++ b/ApartmentManager/ApartmentManager/Model/User.cs @@ -1,11 +1,6 @@ using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Linq; using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; -using Windows.UI.Xaml.Controls; using ApartmentManager.Annotations; namespace ApartmentManager.Model @@ -18,12 +13,12 @@ namespace ApartmentManager.Model public bool IsBm { get; set; } public string FirstName { get; set; } public string LastName { get; set; } - public DateTime BirthDate { get; set; } + public DateTimeOffset BirthDate { get; set; } public string Phone { get; set; } public string Email { get; set; } public string _picture { get; set; } - public DateTime? MoveInDate { get; set; } - public DateTime? MoveOutDate { get; set; } + public DateTimeOffset? MoveInDate { get; set; } + public DateTimeOffset? MoveOutDate { get; set; } public string Picture { diff --git a/ApartmentManager/ApartmentManager/Persistency/ImgurPhotoUploader.cs b/ApartmentManager/ApartmentManager/Persistency/ImgurPhotoUploader.cs index ed0041e..433058f 100644 --- a/ApartmentManager/ApartmentManager/Persistency/ImgurPhotoUploader.cs +++ b/ApartmentManager/ApartmentManager/Persistency/ImgurPhotoUploader.cs @@ -6,6 +6,7 @@ using System.IO; using System.Threading.Tasks; using Windows.Storage; using Windows.Storage.Pickers; +using Windows.UI.Popups; namespace ApartmentManager.Persistency { @@ -16,6 +17,7 @@ namespace ApartmentManager.Persistency /// public async static Task UploadPhotoAsync() { + try { //Create new file picker FileOpenPicker fp = new FileOpenPicker() { @@ -38,15 +40,22 @@ namespace ApartmentManager.Persistency //Get image file with picker StorageFile file = await fp.PickSingleFileAsync(); - //Upload to Imgur and return link - if (file != null) + //Upload to Imgur and return link + if (file != null) + { + var client = new ImgurClient("7b05a61ed8df74f", "ade6f79163e19f92f852bc553bbe399d7d4218fe"); + var endpoint = new ImageEndpoint(client); + IImage image = await endpoint.UploadImageStreamAsync(await file.OpenStreamForReadAsync()); + return image.Link; + } + return ""; + } + catch(Exception ex) { - var client = new ImgurClient("7b05a61ed8df74f", "ade6f79163e19f92f852bc553bbe399d7d4218fe"); - var endpoint = new ImageEndpoint(client); - IImage image = await endpoint.UploadImageStreamAsync(await file.OpenStreamForReadAsync()); - return image.Link; + var msg = new MessageDialog(ex.Message).ShowAsync(); + return ""; } - else return ""; } + } } \ No newline at end of file diff --git a/ApartmentManager/ApartmentManager/Singletons/BmSingleton.cs b/ApartmentManager/ApartmentManager/Singletons/BmSingleton.cs index 14c1100..737a1f3 100644 --- a/ApartmentManager/ApartmentManager/Singletons/BmSingleton.cs +++ b/ApartmentManager/ApartmentManager/Singletons/BmSingleton.cs @@ -15,6 +15,7 @@ namespace ApartmentManager.Singletons private BmSingleton() { + Users = new ObservableCollection(); Residents = new ObservableCollection(); } } diff --git a/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml b/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml index df052a6..001de31 100644 --- a/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml +++ b/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml @@ -15,7 +15,7 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +