From 4002c584ed0b214fb45411da529aacb3451e8b51 Mon Sep 17 00:00:00 2001 From: pekopa Date: Wed, 24 May 2017 12:33:51 +0200 Subject: Add files via upload Use cases completely remade. Absolutely everything. Literally! --- Use cases.odt | Bin 6884 -> 8082 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/Use cases.odt b/Use cases.odt index 5085eae..c66e8bc 100644 Binary files a/Use cases.odt and b/Use cases.odt differ -- cgit v1.2.3 From 47b566edf0a16f0d2593cbb81e04fedaab83118d Mon Sep 17 00:00:00 2001 From: Donatas Adamonis Date: Wed, 24 May 2017 18:47:38 +0200 Subject: code optimization --- ApartmentManager/ApartmentManager/App.xaml.cs | 2 +- ApartmentManager/ApartmentManager/AppShell.xaml.cs | 1 + .../ApartmentManager/Handler/ApartmentHandler.cs | 93 +++++++++------------- .../ApartmentManager/Handler/LoginHandler.cs | 6 +- ApartmentManager/ApartmentManager/Model/User.cs | 26 +++++- .../ApartmentManager/Persistency/ApiClient.cs | 9 ++- .../Singletons/CatalogSingleton.cs | 27 ++++++- .../View/ApartmentNewDefect.xaml.cs | 6 +- .../ViewModel/ApartmentViewModel.cs | 14 ++-- .../ViewModel/BoardMemberViewModel.cs | 1 + .../ApartmentManager/ViewModel/LoginViewModel.cs | 10 ++- 11 files changed, 122 insertions(+), 73 deletions(-) diff --git a/ApartmentManager/ApartmentManager/App.xaml.cs b/ApartmentManager/ApartmentManager/App.xaml.cs index 297bf9d..140776a 100644 --- a/ApartmentManager/ApartmentManager/App.xaml.cs +++ b/ApartmentManager/ApartmentManager/App.xaml.cs @@ -30,7 +30,7 @@ namespace ApartmentManager public App() { this.InitializeComponent(); - this.Suspending += OnSuspending; + this.Suspending += OnSuspending; } /// diff --git a/ApartmentManager/ApartmentManager/AppShell.xaml.cs b/ApartmentManager/ApartmentManager/AppShell.xaml.cs index dec5cf7..b1a88c6 100644 --- a/ApartmentManager/ApartmentManager/AppShell.xaml.cs +++ b/ApartmentManager/ApartmentManager/AppShell.xaml.cs @@ -6,6 +6,7 @@ using System.Linq; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Navigation; +using ApartmentManager.Singletons; namespace ApartmentManager { diff --git a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs index 095ee73..e59d75f 100644 --- a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs @@ -12,6 +12,7 @@ using Newtonsoft.Json; using Windows.Storage; using ApartmentManager.Common; using Windows.Storage.Pickers; +using ApartmentManager.View; namespace ApartmentManager.Handler { @@ -31,7 +32,7 @@ namespace ApartmentManager.Handler public void GetApartment() { - string serializedApartment = ApiClient.GetData("api/Apartments/" + ApartmentViewModel.ApartmentNumber); + string serializedApartment = ApiClient.GetData("api/Apartments/" + ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId); Apartment apartment = JsonConvert.DeserializeObject(serializedApartment); ApartmentViewModel.CatalogSingleton.Apartment = apartment; @@ -43,7 +44,7 @@ namespace ApartmentManager.Handler public void GetApartmentResidents() { Resident resident = new Resident(); - resident.ApartmentId = ApartmentViewModel.ApartmentNumber; + resident.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; var residentsFromDatabase = ApiClient.GetData("api/ApartmentResidents/" + resident.ApartmentId); IEnumerable residentlist = JsonConvert.DeserializeObject>(residentsFromDatabase); @@ -56,20 +57,15 @@ namespace ApartmentManager.Handler } } - + /////////////////////////////////////////////////////////////////////////////////////////////////// public void CreateResident() { try { Resident resident = new Resident(); - resident.ApartmentId = ApartmentViewModel.ApartmentNumber; - resident.FirstName = ApartmentViewModel.NewResident.FirstName; - resident.LastName = ApartmentViewModel.NewResident.LastName; - resident.BirthDate = ApartmentViewModel.NewResident.BirthDate; - resident.Email = ApartmentViewModel.NewResident.Email; - resident.Picture = ApartmentViewModel.NewResident.Picture; - resident.Phone = ApartmentViewModel.NewResident.Phone; - + resident = ApartmentViewModel.NewResident; + resident.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; + ApiClient.PostData("api/residents/", resident); var residentsFromDatabase = ApiClient.GetData("api/ApartmentResidents/" + resident.ApartmentId); @@ -87,21 +83,15 @@ namespace ApartmentManager.Handler new MessageDialog(e.Message).ShowAsync(); } } - + /////////////////////////////////////////////////////////////////////////////////////////////////// public void DeleteResident() { try { Resident resident = new Resident(); - resident.ResidentId = ApartmentViewModel.NewResident.ResidentId; - resident.ApartmentId = ApartmentViewModel.ApartmentNumber; - resident.FirstName = ApartmentViewModel.NewResident.FirstName; - resident.LastName = ApartmentViewModel.NewResident.LastName; - resident.BirthDate = ApartmentViewModel.NewResident.BirthDate; - resident.Email = ApartmentViewModel.NewResident.Email; - resident.Picture = ApartmentViewModel.NewResident.Picture; - resident.Phone = ApartmentViewModel.NewResident.Phone; - + resident = ApartmentViewModel.NewResident; + resident.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; + ApiClient.DeleteData("api/residents/" + resident.ResidentId); var residentsFromDatabase = ApiClient.GetData("api/ApartmentResidents/" + resident.ApartmentId); @@ -119,20 +109,14 @@ namespace ApartmentManager.Handler new MessageDialog(e.Message).ShowAsync(); } } - + /////////////////////////////////////////////////////////////////////////////////////////////////// public void UpdateResident() { try { Resident resident = new Resident(); - resident.ResidentId = ApartmentViewModel.NewResident.ResidentId; - resident.ApartmentId = ApartmentViewModel.ApartmentNumber; - resident.FirstName = ApartmentViewModel.NewResident.FirstName; - resident.LastName = ApartmentViewModel.NewResident.LastName; - resident.BirthDate = ApartmentViewModel.NewResident.BirthDate; - resident.Email = ApartmentViewModel.NewResident.Email; - resident.Picture = ApartmentViewModel.NewResident.Picture; - resident.Phone = ApartmentViewModel.NewResident.Phone; + resident = ApartmentViewModel.NewResident; + resident.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; ApiClient.PutData("api/residents/" + resident.ResidentId, resident); var residentsFromDatabase = ApiClient.GetData("api/ApartmentResidents/" + resident.ApartmentId); @@ -150,7 +134,7 @@ namespace ApartmentManager.Handler new MessageDialog(e.Message).ShowAsync(); } } - + /////////////////////////////////////////////////////////////////////////////////////////////////// public async void UploadResidentPhoto() { try @@ -173,22 +157,20 @@ namespace ApartmentManager.Handler try { ApartmentViewModel.UserSingleton.CurrentUser.Picture = await ImgurPhotoUploader.UploadPhotoAsync(); - var tmp = ApartmentViewModel.UserSingleton.CurrentUser; - ApartmentViewModel.UserSingleton.CurrentUser = new User(); - ApartmentViewModel.UserSingleton.CurrentUser = tmp; + } catch (Exception e) { } } - + /////////////////////////////////////////////////////////////////////////////////////////////////// public void UpdateUser() { try { User user = new User(); user = ApartmentViewModel.UserSingleton.CurrentUser; - ApiClient.PutData("api/users/" + user.Username, user); + ApiClient.PutData("api/users/" + user.Username, user); } catch (Exception e) { @@ -201,7 +183,7 @@ namespace ApartmentManager.Handler public void GetApartmentDefects() { Defect defect = new Defect(); - defect.ApartmentId = ApartmentViewModel.ApartmentNumber; + defect.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; var defectsFromDatabase = ApiClient.GetData("api/ApartmentDefects/" + defect.ApartmentId); IEnumerable defecttlist = JsonConvert.DeserializeObject>(defectsFromDatabase); @@ -228,12 +210,11 @@ namespace ApartmentManager.Handler ApartmentViewModel.NewResident = new Resident(); foreach (var defect2 in defecttlist) { - ApartmentViewModel.CatalogSingleton.Defects.Add(defect2); } ApartmentViewModel.CatalogSingleton.DefectPictures.Clear(); } - + /////////////////////////////////////////////////////////////////////////////////////////////////// public void DeleteDefectPicture() { ApartmentViewModel.CatalogSingleton.DefectPictures.Remove(ApartmentViewModel.SelectedDefectPicture); @@ -245,25 +226,23 @@ namespace ApartmentManager.Handler ApartmentViewModel.SelectedDefectPicture = new DefectPicture(); ApartmentViewModel.SelectedDefectPicture.Picture = await ImgurPhotoUploader.UploadPhotoAsync(); - ApartmentViewModel.CatalogSingleton.DefectPictures.Add(ApartmentViewModel.SelectedDefectPicture); - + ApartmentViewModel.CatalogSingleton.DefectPictures.Add(ApartmentViewModel.SelectedDefectPicture); } catch (Exception e) { } } + /////////////////////////////////////////////////////////////////////////////////////////////////// public void CreateDefect() - { - try - { + { Defect defect = new Defect(); defect = ApartmentViewModel.NewDefect; - defect.ApartmentId = ApartmentViewModel.ApartmentNumber; + defect.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; defect.Status = "New"; defect.UploadDate = DateTime.Now; ApiClient.PostData("api/defects/", defect); - defect.DefectId = Int32.Parse(ApartmentViewModel.ServerResponse); + defect.DefectId = ApartmentViewModel.ServerResponse; foreach (var picture in ApartmentViewModel.CatalogSingleton.DefectPictures) { picture.DefectId = defect.DefectId; @@ -271,14 +250,17 @@ namespace ApartmentManager.Handler } GetApartmentDefects(); - - } - catch (Exception e) - { - new MessageDialog(e.Message).ShowAsync(); - } + } - + /////////////////////////////////////////////////////////////////////////////////////////////////// + public bool CreateDefect_CanExecute() + { + if (string.IsNullOrEmpty(ApartmentViewModel.NewDefect.Description) || string.IsNullOrEmpty(ApartmentViewModel.NewDefect.Name)) + return false; + else + return true; + } + /////////////////////////////////////////////////////////////////////////////////////////////////// public void GetDefectInfo() { var id = ApartmentViewModel.NewDefect.DefectId; @@ -300,9 +282,10 @@ namespace ApartmentManager.Handler ApartmentViewModel.CatalogSingleton.DefectPictures2.Add(asd); } + } + } + /////////////////////////////////////////////////////////////////////////////////////////////////// - } - } } } diff --git a/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs b/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs index e952e0b..65efeca 100644 --- a/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs @@ -2,6 +2,8 @@ using ApartmentManager.Persistency; using Newtonsoft.Json; using System; +using ApartmentManager.Singletons; +using ApartmentManager.ViewModel; namespace ApartmentManager.Handler { @@ -16,7 +18,9 @@ namespace ApartmentManager.Handler if (user.Password == password) { UserSingleton.Instance.CurrentUser = user; - } + + + } else throw new Exception("Wrong password!"); } else throw new Exception("Wrong username!"); diff --git a/ApartmentManager/ApartmentManager/Model/User.cs b/ApartmentManager/ApartmentManager/Model/User.cs index 42964af..8543833 100644 --- a/ApartmentManager/ApartmentManager/Model/User.cs +++ b/ApartmentManager/ApartmentManager/Model/User.cs @@ -1,13 +1,16 @@ 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 { - public class User + public class User: INotifyPropertyChanged { public string Username { get; set; } public int ApartmentId { get; set; } @@ -18,7 +21,7 @@ namespace ApartmentManager.Model public DateTime BirthDate { get; set; } public string Phone { get; set; } public string Email { get; set; } - public string Picture { get; set; } + private string _picture { get; set; } public DateTime? MoveInDate { get; set; } public DateTime? MoveOutDate { get; set; } @@ -33,10 +36,29 @@ namespace ApartmentManager.Model this.Email = Email; } + public string Picture + { + get { return _picture; } + set + { + _picture = value; + OnPropertyChanged(nameof(Picture)); + } + } public override string ToString() { return string.Format($"First name {FirstName} Last name {LastName} Phone {Phone}"); } + + + public event PropertyChangedEventHandler PropertyChanged; + + [NotifyPropertyChangedInvocator] + protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + + } } } diff --git a/ApartmentManager/ApartmentManager/Persistency/ApiClient.cs b/ApartmentManager/ApartmentManager/Persistency/ApiClient.cs index 8ae0e1c..78a5a55 100644 --- a/ApartmentManager/ApartmentManager/Persistency/ApiClient.cs +++ b/ApartmentManager/ApartmentManager/Persistency/ApiClient.cs @@ -3,6 +3,7 @@ using System; using System.Net.Http; using System.Net.Http.Headers; using System.Text; +using ApartmentManager.Model; using ApartmentManager.ViewModel; namespace ApartmentManager.Persistency @@ -68,11 +69,15 @@ namespace ApartmentManager.Persistency { string serializedData = JsonConvert.SerializeObject(objectToPost); StringContent content = new StringContent(serializedData, Encoding.UTF8, "application/json"); - var response = client.PostAsync(url, content).Result.Headers.Location.AbsolutePath.Remove(0,13); - ApartmentViewModel.ServerResponse = response; + var response = new HttpResponseMessage(); + response = client.PostAsync(url, content).Result; + var def = JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync().Result); + //var response = client.PostAsync(url, content).Result.Headers.Location.AbsolutePath.Remove(0,13); + ApartmentViewModel.ServerResponse = def.DefectId; } catch (Exception) { + } } } diff --git a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs index 62bbae3..050987d 100644 --- a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs +++ b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs @@ -1,10 +1,13 @@ using System; using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Runtime.CompilerServices; +using ApartmentManager.Annotations; using ApartmentManager.Model; namespace ApartmentManager.Singletons { - public class CatalogSingleton + public class CatalogSingleton : INotifyPropertyChanged { private static CatalogSingleton instance = new CatalogSingleton(); @@ -13,7 +16,7 @@ namespace ApartmentManager.Singletons public Apartment Apartment { get; set; } public ObservableCollection Residents { get; set; } - public ObservableCollection Defects { get; set; } + public ObservableCollection defects { get; set; } public ObservableCollection DefectPictures { get; set; } public ObservableCollection DefectPictures2 { get; set; } public Defect Defect { get; set; } @@ -22,9 +25,27 @@ namespace ApartmentManager.Singletons { Residents = new ObservableCollection(); - Defects = new ObservableCollection(); + defects = new ObservableCollection(); DefectPictures = new ObservableCollection(); DefectPictures2 = new ObservableCollection(); } + public ObservableCollection Defects + { + get => this.defects; + set + { + this.defects = value; + OnPropertyChanged(nameof(Defect)); + + } + } + + public event PropertyChangedEventHandler PropertyChanged; + + [NotifyPropertyChangedInvocator] + protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } } } diff --git a/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml.cs b/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml.cs index ba7139d..aed6e6e 100644 --- a/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml.cs +++ b/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml.cs @@ -29,12 +29,16 @@ namespace ApartmentManager.View this.InitializeComponent(); vm = new ApartmentViewModel(); DataContext = vm; + } private void Navigate(object sender, RoutedEventArgs e) { vm.CreateDefect.Execute(null); - Frame.Navigate(typeof(ApartmentDefectPage)); + if (vm.CreateDefect.CanExecute(null)) + { + Frame.Navigate(typeof(ApartmentDefectPage)); + } } } } diff --git a/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs b/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs index f932f18..618f27e 100644 --- a/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs +++ b/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs @@ -21,14 +21,15 @@ namespace ApartmentManager.ViewModel public CatalogSingleton CatalogSingleton { get; set; } public UserSingleton UserSingleton { get; set; } + private User _newUser; private Resident _newResident; private Defect _newDefect; private DefectPicture _selectedDefectPicture; - public static int ApartmentNumber { get; set; } - public static string ServerResponse { get; set; } + + public static int ServerResponse { get; set; } public ICommand CreateResidentCommand { get; set; } public ICommand DeleteResidentCommand { get; set; } @@ -51,7 +52,7 @@ namespace ApartmentManager.ViewModel ApartmentHandler = new ApartmentHandler(this); CatalogSingleton = CatalogSingleton.Instance; UserSingleton = UserSingleton.Instance; - ApartmentNumber = UserSingleton.CurrentUser.ApartmentId; + ////////// User relay commands////////// UpdateUser = new RelayCommand(ApartmentHandler.UpdateUser); UploadUserPhoto = new RelayCommand(ApartmentHandler.UploadUserPhoto); @@ -63,12 +64,11 @@ namespace ApartmentManager.ViewModel ////////// Defect relay commands////////// UploadDefectPicture = new RelayCommand(ApartmentHandler.UploadDefectPhoto); DeleteDefectPicture = new RelayCommand(ApartmentHandler.DeleteDefectPicture); - CreateDefect = new RelayCommand(ApartmentHandler.CreateDefect); + CreateDefect = new RelayCommand(ApartmentHandler.CreateDefect, ApartmentHandler.CreateDefect_CanExecute); DefectInfo = new RelayCommand(ApartmentHandler.GetDefectInfo); - ApartmentHandler.GetApartmentResidents(); - ApartmentHandler.GetApartment(); - ApartmentHandler.GetApartmentDefects(); + } + public Defect NewDefect { diff --git a/ApartmentManager/ApartmentManager/ViewModel/BoardMemberViewModel.cs b/ApartmentManager/ApartmentManager/ViewModel/BoardMemberViewModel.cs index fc2c838..db80503 100644 --- a/ApartmentManager/ApartmentManager/ViewModel/BoardMemberViewModel.cs +++ b/ApartmentManager/ApartmentManager/ViewModel/BoardMemberViewModel.cs @@ -9,6 +9,7 @@ using System.Windows.Input; using ApartmentManager.Annotations; using ApartmentManager.Common; using ApartmentManager.Model; +using ApartmentManager.Singletons; namespace ApartmentManager.ViewModel { diff --git a/ApartmentManager/ApartmentManager/ViewModel/LoginViewModel.cs b/ApartmentManager/ApartmentManager/ViewModel/LoginViewModel.cs index 5f3c1b7..0031061 100644 --- a/ApartmentManager/ApartmentManager/ViewModel/LoginViewModel.cs +++ b/ApartmentManager/ApartmentManager/ViewModel/LoginViewModel.cs @@ -7,6 +7,7 @@ using System.Windows.Input; using Windows.UI.Popups; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; +using ApartmentManager.Singletons; namespace ApartmentManager.ViewModel { @@ -69,7 +70,14 @@ namespace ApartmentManager.ViewModel // When the navigation stack isn't restored, navigate to the first page // suppressing the initial entrance animation. if (UserSingleton.Instance.CurrentUser.IsBm) appShell.AppFrame.Navigate(typeof(BoardMembersMainPage)); - else appShell.AppFrame.Navigate(typeof(ApartmentPage)); + else + { + ApartmentViewModel asd = new ApartmentViewModel(); + asd.ApartmentHandler.GetApartmentResidents(); + asd.ApartmentHandler.GetApartment(); + asd.ApartmentHandler.GetApartmentDefects(); + appShell.AppFrame.Navigate(typeof(ApartmentPage)); + } } // Ensure the current window is active -- cgit v1.2.3 From 8e8f14bcd7e7a6d30535e65e4b73506fb353c535 Mon Sep 17 00:00:00 2001 From: Donatas Adamonis Date: Wed, 24 May 2017 22:26:50 +0200 Subject: begining of comments --- .../ApartmentManager/ApartmentManager.csproj | 1 + .../ApartmentManager/Handler/ApartmentHandler.cs | 52 +++++++-------- .../ApartmentManager/Model/DefectComments.cs | 18 +++++ ApartmentManager/ApartmentManager/Model/User.cs | 9 +-- .../ApartmentManager/Persistency/ApiClient.cs | 15 ++--- .../Singletons/CatalogSingleton.cs | 7 +- .../View/ApartmentDefectPage.xaml.cs | 3 +- .../View/ApartmentDefectViewPage.xaml | 78 +++++++++++++++------- .../ApartmentManager/View/ApartmentNewDefect.xaml | 2 +- .../View/ApartmentResidentsPage.xaml | 4 +- .../ViewModel/ApartmentViewModel.cs | 10 +-- 11 files changed, 128 insertions(+), 71 deletions(-) create mode 100644 ApartmentManager/ApartmentManager/Model/DefectComments.cs diff --git a/ApartmentManager/ApartmentManager/ApartmentManager.csproj b/ApartmentManager/ApartmentManager/ApartmentManager.csproj index e6f14f6..81f44b5 100644 --- a/ApartmentManager/ApartmentManager/ApartmentManager.csproj +++ b/ApartmentManager/ApartmentManager/ApartmentManager.csproj @@ -105,6 +105,7 @@ + diff --git a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs index e59d75f..52310cc 100644 --- a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs @@ -65,7 +65,7 @@ namespace ApartmentManager.Handler Resident resident = new Resident(); resident = ApartmentViewModel.NewResident; resident.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; - + ApiClient.PostData("api/residents/", resident); var residentsFromDatabase = ApiClient.GetData("api/ApartmentResidents/" + resident.ApartmentId); @@ -91,7 +91,7 @@ namespace ApartmentManager.Handler Resident resident = new Resident(); resident = ApartmentViewModel.NewResident; resident.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; - + ApiClient.DeleteData("api/residents/" + resident.ResidentId); var residentsFromDatabase = ApiClient.GetData("api/ApartmentResidents/" + resident.ApartmentId); @@ -116,7 +116,7 @@ namespace ApartmentManager.Handler { Resident resident = new Resident(); resident = ApartmentViewModel.NewResident; - resident.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; + resident.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; ApiClient.PutData("api/residents/" + resident.ResidentId, resident); var residentsFromDatabase = ApiClient.GetData("api/ApartmentResidents/" + resident.ApartmentId); @@ -157,7 +157,7 @@ namespace ApartmentManager.Handler try { ApartmentViewModel.UserSingleton.CurrentUser.Picture = await ImgurPhotoUploader.UploadPhotoAsync(); - + } catch (Exception e) { @@ -170,7 +170,7 @@ namespace ApartmentManager.Handler { User user = new User(); user = ApartmentViewModel.UserSingleton.CurrentUser; - ApiClient.PutData("api/users/" + user.Username, user); + ApiClient.PutData("api/users/" + user.Username, user); } catch (Exception e) { @@ -202,7 +202,7 @@ namespace ApartmentManager.Handler } qwe.MainPicture = ApartmentViewModel.CatalogSingleton.DefectPictures[0].Picture; } - + } @@ -224,9 +224,9 @@ namespace ApartmentManager.Handler try { ApartmentViewModel.SelectedDefectPicture = new DefectPicture(); - + ApartmentViewModel.SelectedDefectPicture.Picture = await ImgurPhotoUploader.UploadPhotoAsync(); - ApartmentViewModel.CatalogSingleton.DefectPictures.Add(ApartmentViewModel.SelectedDefectPicture); + ApartmentViewModel.CatalogSingleton.DefectPictures.Add(ApartmentViewModel.SelectedDefectPicture); } catch (Exception e) { @@ -234,23 +234,23 @@ namespace ApartmentManager.Handler } /////////////////////////////////////////////////////////////////////////////////////////////////// public void CreateDefect() - { - Defect defect = new Defect(); - defect = ApartmentViewModel.NewDefect; - defect.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; - defect.Status = "New"; - defect.UploadDate = DateTime.Now; - - ApiClient.PostData("api/defects/", defect); - defect.DefectId = ApartmentViewModel.ServerResponse; - foreach (var picture in ApartmentViewModel.CatalogSingleton.DefectPictures) - { - picture.DefectId = defect.DefectId; - ApiClient.PostData("api/defectpictures/", picture); - } + { + Defect defect = new Defect(); + defect = ApartmentViewModel.NewDefect; + defect.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; + defect.Status = "New"; + defect.UploadDate = DateTime.Now; + + var response = ApiClient.PostData("api/defects/", defect); + var defectResponse = JsonConvert.DeserializeObject(response); + defect.DefectId = defectResponse.DefectId; - GetApartmentDefects(); - + foreach (var picture in ApartmentViewModel.CatalogSingleton.DefectPictures) + { + picture.DefectId = defect.DefectId; + ApiClient.PostData("api/defectpictures/", picture); + } + GetApartmentDefects(); } /////////////////////////////////////////////////////////////////////////////////////////////////// public bool CreateDefect_CanExecute() @@ -276,13 +276,13 @@ namespace ApartmentManager.Handler if (picturesFromDatabase != "[]") { IEnumerable picturetlist = - JsonConvert.DeserializeObject>(picturesFromDatabase); + JsonConvert.DeserializeObject>(picturesFromDatabase); foreach (var asd in picturetlist) { ApartmentViewModel.CatalogSingleton.DefectPictures2.Add(asd); } - } + } } /////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/ApartmentManager/ApartmentManager/Model/DefectComments.cs b/ApartmentManager/ApartmentManager/Model/DefectComments.cs new file mode 100644 index 0000000..a1e6d1e --- /dev/null +++ b/ApartmentManager/ApartmentManager/Model/DefectComments.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ApartmentManager.Model +{ + public class DefectComments + { + + public int CommentId { get; set; } + public int DefectId { get; set; } + public string Comment { get; set; } + public string Name { get; set; } + public DateTimeOffset Date { get; set; } + } +} diff --git a/ApartmentManager/ApartmentManager/Model/User.cs b/ApartmentManager/ApartmentManager/Model/User.cs index 8543833..e7e43ec 100644 --- a/ApartmentManager/ApartmentManager/Model/User.cs +++ b/ApartmentManager/ApartmentManager/Model/User.cs @@ -10,7 +10,7 @@ using ApartmentManager.Annotations; namespace ApartmentManager.Model { - public class User: INotifyPropertyChanged + public class User : INotifyPropertyChanged { public string Username { get; set; } public int ApartmentId { get; set; } @@ -21,13 +21,14 @@ namespace ApartmentManager.Model public DateTime BirthDate { get; set; } public string Phone { get; set; } public string Email { get; set; } - private string _picture { get; set; } + public string _picture { get; set; } public DateTime? MoveInDate { get; set; } public DateTime? MoveOutDate { get; set; } + public User() { } - public User(string FirstName, string LastName, string Phone, DateTime BirthDate, string Email, int ApartmentNr) + public User(string FirstName, string LastName, string Phone, DateTime BirthDate, string Email) { this.FirstName = FirstName; this.LastName = LastName; @@ -38,7 +39,7 @@ namespace ApartmentManager.Model public string Picture { - get { return _picture; } + get => _picture; set { _picture = value; diff --git a/ApartmentManager/ApartmentManager/Persistency/ApiClient.cs b/ApartmentManager/ApartmentManager/Persistency/ApiClient.cs index 78a5a55..b99f582 100644 --- a/ApartmentManager/ApartmentManager/Persistency/ApiClient.cs +++ b/ApartmentManager/ApartmentManager/Persistency/ApiClient.cs @@ -57,7 +57,7 @@ namespace ApartmentManager.Persistency } } - public static void PostData(string url, object objectToPost) + public static string PostData(string url, object objectToPost) { HttpClientHandler handler = new HttpClientHandler() { UseDefaultCredentials = true }; using (var client = new HttpClient(handler)) @@ -69,15 +69,14 @@ namespace ApartmentManager.Persistency { string serializedData = JsonConvert.SerializeObject(objectToPost); StringContent content = new StringContent(serializedData, Encoding.UTF8, "application/json"); - var response = new HttpResponseMessage(); - response = client.PostAsync(url, content).Result; - var def = JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync().Result); - //var response = client.PostAsync(url, content).Result.Headers.Location.AbsolutePath.Remove(0,13); - ApartmentViewModel.ServerResponse = def.DefectId; + + var response = client.PostAsync(url, content).Result; + string result = response.Content.ReadAsStringAsync().Result; + return result; } catch (Exception) { - + return null; } } } @@ -92,7 +91,7 @@ namespace ApartmentManager.Persistency client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); try { - var response = client.DeleteAsync(url).Result; + var response =client.DeleteAsync(url).Result; } catch (Exception) { diff --git a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs index 050987d..a14c7d5 100644 --- a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs +++ b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs @@ -19,11 +19,16 @@ namespace ApartmentManager.Singletons public ObservableCollection defects { get; set; } public ObservableCollection DefectPictures { get; set; } public ObservableCollection DefectPictures2 { get; set; } + public ObservableCollection DefectComments { get; set; } public Defect Defect { get; set; } private CatalogSingleton() { - + DefectComments = new ObservableCollection(); + DefectComments.Add(new DefectComments( ){Date = DateTimeOffset.Now, Comment = "Comment",CommentId = 1,DefectId = 1,Name = "Name"} ); + DefectComments.Add(new DefectComments() { Date = DateTimeOffset.Now, Comment = "Comment", CommentId = 1, DefectId = 1, Name = "Name" }); + DefectComments.Add(new DefectComments() { Date = DateTimeOffset.Now, Comment = "Comment", CommentId = 1, DefectId = 1, Name = "Name" }); + DefectComments.Add(new DefectComments() { Date = DateTimeOffset.Now, Comment = "Comment", CommentId = 1, DefectId = 1, Name = "Name" }); Residents = new ObservableCollection(); defects = new ObservableCollection(); DefectPictures = new ObservableCollection(); diff --git a/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml.cs b/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml.cs index ee53458..21bc90e 100644 --- a/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml.cs +++ b/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml.cs @@ -38,8 +38,7 @@ namespace ApartmentManager.View private void NavigateDefect(object sender, RoutedEventArgs e) { - vm.DefectInfo.Execute(null); - //vm.ApartmentHandler.GetDefectInfo(); + vm.DefectInfo.Execute(null); Frame.Navigate(typeof(ApartmentDefectViewPagexaml)); } } diff --git a/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPage.xaml b/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPage.xaml index 0da2b73..2c7e322 100644 --- a/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPage.xaml +++ b/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPage.xaml @@ -13,37 +13,69 @@ - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + - - - - - - - - - - - + diff --git a/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml b/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml index fa4862e..c68a36d 100644 --- a/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml +++ b/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml @@ -40,7 +40,7 @@ - +