From aa4a3fc2f1146b8c2342706e46db8e5c5e358ca9 Mon Sep 17 00:00:00 2001 From: Donatas Adamonis Date: Wed, 31 May 2017 10:50:21 +0200 Subject: apartment changes --- .../ApartmentManager/ApartmentManager.csproj | 21 +++ ApartmentManager/ApartmentManager/AppShell.xaml.cs | 2 +- .../ApartmentManager/Handler/ApartmentHandler.cs | 115 +++++++++++++++- .../ApartmentManager/Handler/LoginHandler.cs | 1 + .../Singletons/CatalogSingleton.cs | 9 +- .../View/ApartmentChangesPage.xaml | 124 +++++++++++++++++ .../View/ApartmentChangesPage.xaml.cs | 40 ++++++ .../View/ApartmentChangesViewPage.xaml | 147 +++++++++++++++++++++ .../View/ApartmentChangesViewPage.xaml.cs | 35 +++++ .../ApartmentManager/View/ApartmentDefectPage.xaml | 107 +++++++-------- .../View/ApartmentDefectViewPage.xaml | 7 +- .../View/ApartmentNewChangePage.xaml | 89 +++++++++++++ .../View/ApartmentNewChangePage.xaml.cs | 51 +++++++ .../ApartmentManager/View/ApartmentNewDefect.xaml | 5 - .../ApartmentManager/View/ApartmentPage.xaml | 4 +- .../ApartmentManager/View/ApartmentPage.xaml.cs | 7 +- .../ApartmentManager/View/BmMainPage.xaml | 2 +- .../ViewModel/ApartmentViewModel.cs | 84 ++++++++++-- .../Controllers/ApartmentChangesController.cs | 10 +- .../Controllers/ChangeCommentsController.cs | 2 + 20 files changed, 765 insertions(+), 97 deletions(-) create mode 100644 ApartmentManager/ApartmentManager/View/ApartmentChangesPage.xaml create mode 100644 ApartmentManager/ApartmentManager/View/ApartmentChangesPage.xaml.cs create mode 100644 ApartmentManager/ApartmentManager/View/ApartmentChangesViewPage.xaml create mode 100644 ApartmentManager/ApartmentManager/View/ApartmentChangesViewPage.xaml.cs create mode 100644 ApartmentManager/ApartmentManager/View/ApartmentNewChangePage.xaml create mode 100644 ApartmentManager/ApartmentManager/View/ApartmentNewChangePage.xaml.cs diff --git a/ApartmentManager/ApartmentManager/ApartmentManager.csproj b/ApartmentManager/ApartmentManager/ApartmentManager.csproj index 426f616..d9da403 100644 --- a/ApartmentManager/ApartmentManager/ApartmentManager.csproj +++ b/ApartmentManager/ApartmentManager/ApartmentManager.csproj @@ -131,12 +131,21 @@ + + ApartmentChangesPage.xaml + + + ApartmentChangesViewPage.xaml + ApartmentDefectPage.xaml ApartmentDefectViewPage.xaml + + ApartmentNewChangePage.xaml + ApartmentNewDefect.xaml @@ -223,6 +232,14 @@ MSBuild:Compile Designer + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -231,6 +248,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 c5fcfe5..6da842b 100644 --- a/ApartmentManager/ApartmentManager/AppShell.xaml.cs +++ b/ApartmentManager/ApartmentManager/AppShell.xaml.cs @@ -102,7 +102,7 @@ namespace ApartmentManager new NavMenuItem() { Symbol = Symbol.Bookmarks, - Label = "Changes", + Label = "ApartmentChanges", DestPage = typeof(BmChangesPage), IsSelected = false } diff --git a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs index 41b9cda..b5ea6d2 100644 --- a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs @@ -79,7 +79,7 @@ namespace ApartmentManager.Handler } if (!string.IsNullOrEmpty(resident.FirstName) && !string.IsNullOrEmpty(resident.LastName)) { - var response = ApiClient.PostData("api/residents/", resident); + var response = ApiClient.PostData("api/residents/", resident); } GetApartmentResidents(); } @@ -194,9 +194,9 @@ namespace ApartmentManager.Handler { try { - if (ApartmentViewModel.NewDefect.Pictures == null) ApartmentViewModel.NewDefect.Pictures = new ObservableCollection(); + if (ApartmentViewModel.NewDefect.Pictures == null) ApartmentViewModel.NewDefect.Pictures = new ObservableCollection(); var picture = new DefectPicture() { Picture = await ImgurPhotoUploader.UploadPhotoAsync() }; - ApartmentViewModel.NewDefect.Pictures.Add(picture); + ApartmentViewModel.NewDefect.Pictures.Add(picture); } catch (Exception e) { @@ -226,7 +226,7 @@ namespace ApartmentManager.Handler { new MessageDialog(e.Message).ShowAsync(); } - + } /////////////////////////////////////////////////////////////////////////////////////////////////// public bool CreateDefect_CanExecute() @@ -235,7 +235,7 @@ namespace ApartmentManager.Handler return false; else return true; - } + } /////////////////////////////////////////////////////////////////////////////////////////////////// public void CreateDefectComment() { @@ -262,8 +262,109 @@ namespace ApartmentManager.Handler catch (Exception e) { new MessageDialog(e.Message).ShowAsync(); - } + } } - /////////////////////////////////////////////////////////////////////////////////////////////////// + /// + /// Defect HANDLERS + /// + public void GetApartmentChanges() + { + ApartmentChange change = new ApartmentChange(); + change.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; + var changesFromDatabase = ApiClient.GetData("api/ApartmentChangesByid/" + change.ApartmentId); + var changeslist = JsonConvert.DeserializeObject>(changesFromDatabase); + CatalogSingleton.Instance.ApartmentChanges.Clear(); + foreach (var apartmentChange in changeslist) + { + apartmentChange.Documents = JsonConvert.DeserializeObject>(ApiClient.GetData("api/ChangeDocumentsById/" + apartmentChange.ChangeId)); + apartmentChange.Comments = JsonConvert.DeserializeObject>(ApiClient.GetData("api/ChangeCommentsById/" + apartmentChange.ChangeId)); + CatalogSingleton.Instance.ApartmentChanges.Add(apartmentChange); + } + } + public void CreateChangeComment() + { + try + { + ChangeComment Comment = new ChangeComment(); + Comment.Comment = ApartmentViewModel.NewChangeComment.Comment; + Comment.ChangeId = CatalogSingleton.Instance.SelectedChange.ChangeId; + Comment.Name = UserSingleton.Instance.CurrentUser.FirstName + " " + UserSingleton.Instance.CurrentUser.LastName; + Comment.Date = DateTimeOffset.Now; + if (!string.IsNullOrEmpty(Comment.Comment)) + { + var asd =ApiClient.PostData("api/ChangeComments/", Comment); + } + var response = ApiClient.GetData("api/ChangeCommentsById/" + CatalogSingleton.Instance.SelectedChange.ChangeId); + var commentlist = JsonConvert.DeserializeObject>(response); + + CatalogSingleton.Instance.SelectedChange.Comments.Clear(); + foreach (var comment in commentlist) + { + CatalogSingleton.Instance.SelectedChange.Comments.Add(comment); + } + } + catch (Exception e) + { + new MessageDialog(e.Message).ShowAsync(); + } + } + public void DeleteChangePicture() + { + try + { + ApartmentViewModel.NewChange.Documents.Remove(ApartmentViewModel.SelectedChangeDocument); + } + catch (Exception e) + { + new MessageDialog(e.Message).ShowAsync(); + } + } + public async void UploadChangePicture() + { + try + { + if (ApartmentViewModel.NewChange.Documents == null) ApartmentViewModel.NewChange.Documents = new ObservableCollection(); + var picture = new ChangeDocument() { Document = await ImgurPhotoUploader.UploadPhotoAsync() }; + ApartmentViewModel.NewChange.Documents.Add(picture); + } + catch (Exception e) + { + new MessageDialog(e.Message).ShowAsync(); + } + } + public void CreateChange() + { + try + { + ApartmentChange change = ApartmentViewModel.NewChange; + change.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; + change.Status = "New"; + change.UploadDate = DateTime.Now; + var response = ApiClient.PostData("api/ApartmentChanges/", change); + var changeResponse = JsonConvert.DeserializeObject(response); + change.ChangeId = changeResponse.ChangeId; + if (change.Documents !=null) + { + foreach (var document in change.Documents) + { + document.ChangeId = change.ChangeId; + ApiClient.PostData("api/ChangeDocuments/", document); + } + } + GetApartmentChanges(); + } + catch (Exception e) + { + new MessageDialog(e.Message).ShowAsync(); + } + } + public bool CreateChange_CanExecute() + { + if (string.IsNullOrEmpty(ApartmentViewModel.NewChange.Description) || string.IsNullOrEmpty(ApartmentViewModel.NewChange.Name)) + return false; + else + return true; + } + } } diff --git a/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs b/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs index 9f52a40..9360f97 100644 --- a/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs @@ -93,6 +93,7 @@ namespace ApartmentManager.Handler avm.ApartmentHandler.GetApartmentResidents(); avm.ApartmentHandler.GetApartment(); avm.ApartmentHandler.GetApartmentDefects(); + avm.ApartmentHandler.GetApartmentChanges(); appShell.AppFrame.Navigate(typeof(ApartmentPage)); } } diff --git a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs index a05c01a..ee101c6 100644 --- a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs +++ b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs @@ -18,13 +18,18 @@ namespace ApartmentManager.Singletons public ObservableCollection Residents { get; set; } ////////// For Defects ////////// public ObservableCollection Defects { get; set; } + public ApartmentChange SelectedChange { get; set; } + ////////// For Defects ////////// + public ObservableCollection ApartmentChanges { get; set; } public Defect SelectedDefect { get; set; } ////////// Constructor ////////// private CatalogSingleton() - { + { + ApartmentChanges = new ObservableCollection(); Residents = new ObservableCollection(); Defects = new ObservableCollection(); - SelectedDefect = new Defect(); + SelectedDefect = new Defect(); + SelectedChange = new ApartmentChange(); } } } diff --git a/ApartmentManager/ApartmentManager/View/ApartmentChangesPage.xaml b/ApartmentManager/ApartmentManager/View/ApartmentChangesPage.xaml new file mode 100644 index 0000000..9a7ddb1 --- /dev/null +++ b/ApartmentManager/ApartmentManager/View/ApartmentChangesPage.xaml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ApartmentManager/ApartmentManager/View/ApartmentChangesPage.xaml.cs b/ApartmentManager/ApartmentManager/View/ApartmentChangesPage.xaml.cs new file mode 100644 index 0000000..c498d1d --- /dev/null +++ b/ApartmentManager/ApartmentManager/View/ApartmentChangesPage.xaml.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using Windows.Foundation; +using Windows.Foundation.Collections; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Controls.Primitives; +using Windows.UI.Xaml.Data; +using Windows.UI.Xaml.Input; +using Windows.UI.Xaml.Media; +using Windows.UI.Xaml.Navigation; + +// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 + +namespace ApartmentManager.View +{ + /// + /// An empty page that can be used on its own or navigated to within a Frame. + /// + public sealed partial class ApartmentChangesPage : Page + { + public ApartmentChangesPage() + { + this.InitializeComponent(); + } + + private void GotoApartmentChangeViewPage(object sender, SelectionChangedEventArgs e) + { + Frame.Navigate(typeof(ApartmentChangesViewPage)); + } + + private void GotoNewChangePage(object sender, RoutedEventArgs e) + { + Frame.Navigate(typeof(ApartmentNewChangePage)); + } + } +} diff --git a/ApartmentManager/ApartmentManager/View/ApartmentChangesViewPage.xaml b/ApartmentManager/ApartmentManager/View/ApartmentChangesViewPage.xaml new file mode 100644 index 0000000..5ec7b99 --- /dev/null +++ b/ApartmentManager/ApartmentManager/View/ApartmentChangesViewPage.xaml @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs b/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs index ae0919d..bb126b4 100644 --- a/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs +++ b/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs @@ -25,9 +25,14 @@ namespace ApartmentManager.ViewModel ////////// Store Data From Interface////////// private User _newUser; private Resident _newResident; + //// For defect/// private Defect _newDefect; private DefectPicture _selectedDefectPicture; private DefectComment _newDefectComment; + //// For Changes/// + private ChangeComment _newChangeComment; + private ApartmentChange _newApartmentChange; + private ChangeDocument _selectedChangeDocument; ////////// Resident relay commands////////// public ICommand CreateResidentCommand { get; set; } public ICommand DeleteResidentCommand { get; set; } @@ -39,22 +44,32 @@ namespace ApartmentManager.ViewModel ////////// Defect relay commands////////// public ICommand DeleteDefectPicture { get; set; } public ICommand UploadDefectPicture { get; set; } - public ICommand CreateDefect { get; set; } + public ICommand CreateDefect { get; set; } public ICommand CreateDefectComment { get; set; } + ////////// Change relay commands////////// + public ICommand DeleteChangePicture { get; set; } + public ICommand UploadChangePicture { get; set; } + public ICommand CreateChangeComment { get; set; } + public ICommand CreateChange { get; set; } ////////// Constructor ////////// public ApartmentViewModel() { ////////// Store Data From Interface instance ////////// NewUser = new User(); NewResident = new Resident(); + NewDefect = new Defect(); NewDefectComment = new DefectComment(); SelectedDefectPicture = new DefectPicture(); + + NewChangeComment = new ChangeComment(); + SelectedChangeDocument = new ChangeDocument(); + NewChange = new ApartmentChange(); ////////// Handler ////////// ApartmentHandler = new ApartmentHandler(this); ////////// Singletons ////////// CatalogSingleton = CatalogSingleton.Instance; - UserSingleton = UserSingleton.Instance; + UserSingleton = UserSingleton.Instance; ////////// User relay commands////////// UpdateUser = new RelayCommand(ApartmentHandler.UpdateUser); UploadUserPhoto = new RelayCommand(ApartmentHandler.UploadUserPhoto); @@ -66,10 +81,15 @@ namespace ApartmentManager.ViewModel ////////// Defect relay commands////////// UploadDefectPicture = new RelayCommand(ApartmentHandler.UploadDefectPhoto); DeleteDefectPicture = new RelayCommand(ApartmentHandler.DeleteDefectPicture); - CreateDefect = new RelayCommand(ApartmentHandler.CreateDefect, ApartmentHandler.CreateDefect_CanExecute); + CreateDefect = new RelayCommand(ApartmentHandler.CreateDefect, ApartmentHandler.CreateDefect_CanExecute); CreateDefectComment = new RelayCommand(ApartmentHandler.CreateDefectComment); + ////////// changes relay commands////////// + CreateChangeComment = new RelayCommand(ApartmentHandler.CreateChangeComment); + DeleteChangePicture = new RelayCommand(ApartmentHandler.DeleteChangePicture); + UploadChangePicture = new RelayCommand(ApartmentHandler.UploadChangePicture); + CreateChange = new RelayCommand(ApartmentHandler.CreateChange, ApartmentHandler.CreateChange_CanExecute); } - ////////// Store Data From Interface////////// + ////////// Store Data From Interface for defects////////// public DefectComment NewDefectComment { get => _newDefectComment; @@ -88,33 +108,71 @@ namespace ApartmentManager.ViewModel OnPropertyChanged(); } } - public User NewUser + public DefectPicture SelectedDefectPicture { - get => _newUser; + get => _selectedDefectPicture; set { - _newUser = value; + _selectedDefectPicture = value; OnPropertyChanged(); } } - public Resident NewResident + ////////// Store Data From Interface for Changes////////// + public ChangeComment NewChangeComment { - get => _newResident; + get => _newChangeComment; set { - _newResident = value; + _newChangeComment = value; OnPropertyChanged(); } } - public DefectPicture SelectedDefectPicture + public ChangeDocument SelectedChangeDocument { - get => _selectedDefectPicture; + get => _selectedChangeDocument; set { - _selectedDefectPicture = value; + _selectedChangeDocument = value; + OnPropertyChanged(); + } + } + public ApartmentChange NewChange + { + get => _newApartmentChange; + set + { + _newApartmentChange = value; OnPropertyChanged(); } } + + + + + + + + + + public User NewUser + { + get => _newUser; + set + { + _newUser = value; + OnPropertyChanged(); + } + } + public Resident NewResident + { + get => _newResident; + set + { + _newResident = value; + OnPropertyChanged(); + } + } + ////////// INotifyPropertyChanged ////////// public event PropertyChangedEventHandler PropertyChanged; [NotifyPropertyChangedInvocator] diff --git a/ApartmentManager/HousingWebApi/Controllers/ApartmentChangesController.cs b/ApartmentManager/HousingWebApi/Controllers/ApartmentChangesController.cs index f96385a..eadd910 100644 --- a/ApartmentManager/HousingWebApi/Controllers/ApartmentChangesController.cs +++ b/ApartmentManager/HousingWebApi/Controllers/ApartmentChangesController.cs @@ -21,7 +21,15 @@ namespace HousingWebApi.Controllers { return db.ApartmentChanges; } - + [Route("api/ApartmentChangesByid/{id}")] + public IQueryable GetApartmentChangesByid(int id) + { + var changetlist = from change in db.ApartmentChanges + where (change.ApartmentId == id) + orderby change.ChangeId descending + select change; + return changetlist; + } // GET: api/ApartmentChanges/5 [ResponseType(typeof(ApartmentChange))] public IHttpActionResult GetApartmentChange(int id) diff --git a/ApartmentManager/HousingWebApi/Controllers/ChangeCommentsController.cs b/ApartmentManager/HousingWebApi/Controllers/ChangeCommentsController.cs index 11519fd..6026938 100644 --- a/ApartmentManager/HousingWebApi/Controllers/ChangeCommentsController.cs +++ b/ApartmentManager/HousingWebApi/Controllers/ChangeCommentsController.cs @@ -22,6 +22,8 @@ namespace HousingWebApi.Controllers { var commentsList = from changeComment in db.ChangeComments where (changeComment.ChangeId == id) + orderby changeComment.CommentId descending + select changeComment; return commentsList; } -- cgit v1.2.3