From a2551a60650e165cd556e33ea495e5730d487704 Mon Sep 17 00:00:00 2001 From: pekopa Date: Fri, 26 May 2017 13:20:09 +0200 Subject: Add files via upload All the use cases (10): Add/remove/update Apartment Add/remove/update Resident Add/remove/update Defect Apartment changes --- Use cases.odt | Bin 8082 -> 14355 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/Use cases.odt b/Use cases.odt index c66e8bc..90dbfc8 100644 Binary files a/Use cases.odt and b/Use cases.odt differ -- cgit v1.2.3 From d4ccb42366044c86d54fbbdefae491d436b7cf42 Mon Sep 17 00:00:00 2001 From: Donatas Adamonis Date: Fri, 26 May 2017 18:32:16 +0200 Subject: final version of Defect comments --- .../ApartmentManager/Handler/ApartmentHandler.cs | 223 +++++++++++---------- .../Singletons/CatalogSingleton.cs | 35 +--- .../View/ApartmentDefectViewPage.xaml | 27 ++- .../ViewModel/ApartmentViewModel.cs | 21 +- .../Controllers/DefectCommentsController.cs | 9 +- .../HousingWebApi/Controllers/DefectsController.cs | 1 + ApartmentManager/HousingWebApi/DataModel.cs | 8 + .../HousingWebApi/Models/ChangeComment.cs | 5 + .../HousingWebApi/Models/DefectComment.cs | 5 + 9 files changed, 182 insertions(+), 152 deletions(-) diff --git a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs index 52310cc..52849aa 100644 --- a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -12,6 +13,7 @@ using Newtonsoft.Json; using Windows.Storage; using ApartmentManager.Common; using Windows.Storage.Pickers; +using ApartmentManager.Singletons; using ApartmentManager.View; namespace ApartmentManager.Handler @@ -32,10 +34,16 @@ namespace ApartmentManager.Handler public void GetApartment() { - string serializedApartment = ApiClient.GetData("api/Apartments/" + ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId); - - Apartment apartment = JsonConvert.DeserializeObject(serializedApartment); - ApartmentViewModel.CatalogSingleton.Apartment = apartment; + try + { + string serializedApartment = ApiClient.GetData("api/Apartments/" + ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId); + Apartment apartment = JsonConvert.DeserializeObject(serializedApartment); + ApartmentViewModel.CatalogSingleton.Apartment = apartment; + } + catch (Exception e) + { + new MessageDialog(e.Message).ShowAsync(); + } } /// @@ -43,17 +51,19 @@ namespace ApartmentManager.Handler /// public void GetApartmentResidents() { - Resident resident = new Resident(); - resident.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; - - var residentsFromDatabase = ApiClient.GetData("api/ApartmentResidents/" + resident.ApartmentId); - IEnumerable residentlist = JsonConvert.DeserializeObject>(residentsFromDatabase); - - ApartmentViewModel.CatalogSingleton.Residents.Clear(); - ApartmentViewModel.NewResident = new Resident(); - foreach (var resident2 in residentlist) + try { - ApartmentViewModel.CatalogSingleton.Residents.Add(resident2); + var residentsFromDatabase = ApiClient.GetData("api/ApartmentResidents/" + UserSingleton.Instance.CurrentUser.ApartmentId); + var residentlist = JsonConvert.DeserializeObject>(residentsFromDatabase); + ApartmentViewModel.CatalogSingleton.Residents.Clear(); + foreach (var resident in residentlist) + { + ApartmentViewModel.CatalogSingleton.Residents.Add(resident); + } + } + catch (Exception e) + { + new MessageDialog(e.Message).ShowAsync(); } } @@ -62,21 +72,18 @@ namespace ApartmentManager.Handler { try { - 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); - IEnumerable residentlist = JsonConvert.DeserializeObject>(residentsFromDatabase); - ApartmentViewModel.CatalogSingleton.Residents.Clear(); - ApartmentViewModel.NewResident = new Resident(); - foreach (var resident2 in residentlist) + Resident resident = ApartmentViewModel.NewResident ?? new Resident(); + resident.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; + if (string.IsNullOrEmpty(resident.Picture)) { - ApartmentViewModel.CatalogSingleton.Residents.Add(resident2); + resident.Picture = "http://i.imgur.com/8KNkU26.png"; } + if (!string.IsNullOrEmpty(resident.FirstName) && !string.IsNullOrEmpty(resident.FirstName)) + { + ApiClient.PostData("api/residents/", resident); + } + GetApartmentResidents(); } catch (Exception e) { @@ -88,21 +95,11 @@ namespace ApartmentManager.Handler { try { - Resident resident = new Resident(); - resident = ApartmentViewModel.NewResident; + Resident resident = ApartmentViewModel.NewResident ?? new Resident(); resident.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; ApiClient.DeleteData("api/residents/" + resident.ResidentId); - - var residentsFromDatabase = ApiClient.GetData("api/ApartmentResidents/" + resident.ApartmentId); - IEnumerable residentlist = JsonConvert.DeserializeObject>(residentsFromDatabase); - - ApartmentViewModel.CatalogSingleton.Residents.Clear(); - ApartmentViewModel.NewResident = new Resident(); - foreach (var resident2 in residentlist) - { - ApartmentViewModel.CatalogSingleton.Residents.Add(resident2); - } + GetApartmentResidents(); } catch (Exception e) { @@ -114,20 +111,11 @@ namespace ApartmentManager.Handler { try { - Resident resident = new Resident(); - resident = ApartmentViewModel.NewResident; + Resident resident = ApartmentViewModel.NewResident ?? new Resident(); resident.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; ApiClient.PutData("api/residents/" + resident.ResidentId, resident); - var residentsFromDatabase = ApiClient.GetData("api/ApartmentResidents/" + resident.ApartmentId); - IEnumerable residentlist = JsonConvert.DeserializeObject>(residentsFromDatabase); - - ApartmentViewModel.CatalogSingleton.Residents.Clear(); - ApartmentViewModel.NewResident = new Resident(); - foreach (var resident2 in residentlist) - { - ApartmentViewModel.CatalogSingleton.Residents.Add(resident2); - } + GetApartmentResidents(); } catch (Exception e) { @@ -146,6 +134,7 @@ namespace ApartmentManager.Handler } catch (Exception e) { + new MessageDialog(e.Message).ShowAsync(); } } /// @@ -157,10 +146,10 @@ namespace ApartmentManager.Handler try { ApartmentViewModel.UserSingleton.CurrentUser.Picture = await ImgurPhotoUploader.UploadPhotoAsync(); - } catch (Exception e) { + new MessageDialog(e.Message).ShowAsync(); } } /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -168,8 +157,7 @@ namespace ApartmentManager.Handler { try { - User user = new User(); - user = ApartmentViewModel.UserSingleton.CurrentUser; + User user = ApartmentViewModel.UserSingleton.CurrentUser ?? new User(); ApiClient.PutData("api/users/" + user.Username, user); } catch (Exception e) @@ -182,75 +170,74 @@ namespace ApartmentManager.Handler /// public void GetApartmentDefects() { - Defect defect = new Defect(); - defect.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; + Defect Defect = new Defect(); + Defect.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; - var defectsFromDatabase = ApiClient.GetData("api/ApartmentDefects/" + defect.ApartmentId); - IEnumerable defecttlist = JsonConvert.DeserializeObject>(defectsFromDatabase); + var defectsFromDatabase = ApiClient.GetData("api/ApartmentDefects/" + Defect.ApartmentId); + var defecttlist = JsonConvert.DeserializeObject>(defectsFromDatabase); - foreach (var qwe in defecttlist) + foreach (var defect in defecttlist) { - var picturesFromDatabase = ApiClient.GetData("api/DefectPictures/" + qwe.DefectId); + var picturesFromDatabase = ApiClient.GetData("api/DefectPictures/" + defect.DefectId); if (picturesFromDatabase != "[]") { - IEnumerable picturetlist = JsonConvert.DeserializeObject>(picturesFromDatabase); - ApartmentViewModel.CatalogSingleton.DefectPictures.Clear(); - foreach (var asd in picturetlist) - { - - ApartmentViewModel.CatalogSingleton.DefectPictures.Add(asd); - } - qwe.MainPicture = ApartmentViewModel.CatalogSingleton.DefectPictures[0].Picture; + ApartmentViewModel.CatalogSingleton.DefectPictures = JsonConvert.DeserializeObject>(picturesFromDatabase); + defect.MainPicture = ApartmentViewModel.CatalogSingleton.DefectPictures[0].Picture; } - - - } - - ApartmentViewModel.CatalogSingleton.Defects.Clear(); - ApartmentViewModel.NewResident = new Resident(); - foreach (var defect2 in defecttlist) - { - ApartmentViewModel.CatalogSingleton.Defects.Add(defect2); } + ApartmentViewModel.CatalogSingleton.Defects = defecttlist; ApartmentViewModel.CatalogSingleton.DefectPictures.Clear(); } /////////////////////////////////////////////////////////////////////////////////////////////////// public void DeleteDefectPicture() { - ApartmentViewModel.CatalogSingleton.DefectPictures.Remove(ApartmentViewModel.SelectedDefectPicture); + try + { + ApartmentViewModel.CatalogSingleton.DefectPictures.Remove(ApartmentViewModel.SelectedDefectPicture); + } + catch (Exception e) + { + new MessageDialog(e.Message).ShowAsync(); + } } public async void UploadDefectPhoto() { try { - ApartmentViewModel.SelectedDefectPicture = new DefectPicture(); - ApartmentViewModel.SelectedDefectPicture.Picture = await ImgurPhotoUploader.UploadPhotoAsync(); ApartmentViewModel.CatalogSingleton.DefectPictures.Add(ApartmentViewModel.SelectedDefectPicture); } catch (Exception e) { + new MessageDialog(e.Message).ShowAsync(); } } /////////////////////////////////////////////////////////////////////////////////////////////////// public void CreateDefect() { - Defect defect = new Defect(); - defect = ApartmentViewModel.NewDefect; - defect.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; - defect.Status = "New"; - defect.UploadDate = DateTime.Now; + try + { + 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; + var response = ApiClient.PostData("api/defects/", defect); + var defectResponse = JsonConvert.DeserializeObject(response); + defect.DefectId = defectResponse.DefectId; - foreach (var picture in ApartmentViewModel.CatalogSingleton.DefectPictures) + foreach (var picture in ApartmentViewModel.CatalogSingleton.DefectPictures) + { + picture.DefectId = defect.DefectId; + ApiClient.PostData("api/defectpictures/", picture); + } + GetApartmentDefects(); + } + catch (Exception e) { - picture.DefectId = defect.DefectId; - ApiClient.PostData("api/defectpictures/", picture); + new MessageDialog(e.Message).ShowAsync(); } - GetApartmentDefects(); + } /////////////////////////////////////////////////////////////////////////////////////////////////// public bool CreateDefect_CanExecute() @@ -263,29 +250,49 @@ namespace ApartmentManager.Handler /////////////////////////////////////////////////////////////////////////////////////////////////// public void GetDefectInfo() { - var id = ApartmentViewModel.NewDefect.DefectId; - Defect defect = new Defect(); - defect.DefectId = id; - - var defectFromDatabase = ApiClient.GetData("api/defects/" + defect.DefectId); - var defect2 = JsonConvert.DeserializeObject(defectFromDatabase); - ApartmentViewModel.CatalogSingleton.Defect = defect2; - - var picturesFromDatabase = ApiClient.GetData("api/DefectPictures/" + defect.DefectId); - ApartmentViewModel.CatalogSingleton.DefectPictures2.Clear(); - if (picturesFromDatabase != "[]") + try + { + var defectFromDatabase = ApiClient.GetData("api/defects/" + ApartmentViewModel.NewDefect.DefectId); + ApartmentViewModel.CatalogSingleton.Defect = JsonConvert.DeserializeObject(defectFromDatabase); + var picturesFromDatabase = ApiClient.GetData("api/DefectPictures/" + ApartmentViewModel.NewDefect.DefectId); + ApartmentViewModel.CatalogSingleton.DefectPictures = JsonConvert.DeserializeObject>(picturesFromDatabase); + var defectComments = ApiClient.GetData("api/Defectcomments/" + ApartmentViewModel.NewDefect.DefectId); + ApartmentViewModel.CatalogSingleton.DefectComments = JsonConvert.DeserializeObject>(defectComments); + CatalogSingleton.Instance.DefectId = ApartmentViewModel.NewDefect.DefectId; + } + catch (Exception e) + { + new MessageDialog(e.Message).ShowAsync(); + } + + } + /////////////////////////////////////////////////////////////////////////////////////////////////// + public void CreateDefectComment() + { + try { - IEnumerable picturetlist = - JsonConvert.DeserializeObject>(picturesFromDatabase); - foreach (var asd in picturetlist) + DefectComments Comment = new DefectComments(); + Comment.Comment = ApartmentViewModel.NewDefectComment.Comment; + Comment.DefectId = CatalogSingleton.Instance.Defect.DefectId; + Comment.Name = UserSingleton.Instance.CurrentUser.FirstName + " " + UserSingleton.Instance.CurrentUser.LastName; + Comment.Date = DateTimeOffset.Now; + if (!string.IsNullOrEmpty(Comment.Comment)) { - - ApartmentViewModel.CatalogSingleton.DefectPictures2.Add(asd); + ApiClient.PostData("api/Defectcomments/", Comment); + } + var response = ApiClient.GetData("api/Defectcomments/" + CatalogSingleton.Instance.DefectId); + var commentlist = JsonConvert.DeserializeObject>(response); + CatalogSingleton.Instance.DefectComments.Clear(); + foreach (var comment in commentlist) + { + CatalogSingleton.Instance.DefectComments.Add(comment); } } + catch (Exception e) + { + new MessageDialog(e.Message).ShowAsync(); + } } /////////////////////////////////////////////////////////////////////////////////////////////////// - - } } diff --git a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs index a14c7d5..39f352e 100644 --- a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs +++ b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs @@ -7,7 +7,7 @@ using ApartmentManager.Model; namespace ApartmentManager.Singletons { - public class CatalogSingleton : INotifyPropertyChanged + public class CatalogSingleton { private static CatalogSingleton instance = new CatalogSingleton(); @@ -16,41 +16,20 @@ 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 int DefectId { 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(); + 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/ApartmentDefectViewPage.xaml b/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPage.xaml index 2c7e322..406cb8c 100644 --- a/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPage.xaml +++ b/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPage.xaml @@ -23,7 +23,7 @@ - + @@ -47,8 +47,8 @@ - - + + @@ -61,13 +61,24 @@ - + - - - + + + + + + + + + + + + + + + - diff --git a/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs b/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs index dad140a..9c1542b 100644 --- a/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs +++ b/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs @@ -24,8 +24,9 @@ namespace ApartmentManager.ViewModel private User _newUser; private Resident _newResident; - private Defect _newDefect; + private Defect _newDefect = new Defect(); private DefectPicture _selectedDefectPicture; + private DefectComments _newDefectComment; @@ -43,12 +44,13 @@ namespace ApartmentManager.ViewModel public ICommand UploadDefectPicture { get; set; } public ICommand CreateDefect { get; set; } public ICommand DefectInfo { get; set; } - + public ICommand CreateDefectComment { get; set; } public ApartmentViewModel() { NewUser = new User(); NewResident = new Resident(); - NewDefect = new Defect(); + //NewDefect = new Defect(); + NewDefectComment = new DefectComments(); SelectedDefectPicture = new DefectPicture(); ApartmentHandler = new ApartmentHandler(this); @@ -68,10 +70,19 @@ namespace ApartmentManager.ViewModel UploadDefectPicture = new RelayCommand(ApartmentHandler.UploadDefectPhoto); DeleteDefectPicture = new RelayCommand(ApartmentHandler.DeleteDefectPicture); CreateDefect = new RelayCommand(ApartmentHandler.CreateDefect, ApartmentHandler.CreateDefect_CanExecute); - DefectInfo = new RelayCommand(ApartmentHandler.GetDefectInfo); + DefectInfo = new RelayCommand(ApartmentHandler.GetDefectInfo); + CreateDefectComment = new RelayCommand(ApartmentHandler.CreateDefectComment); } - + public DefectComments NewDefectComment + { + get => _newDefectComment; + set + { + _newDefectComment = value; + OnPropertyChanged(); + } + } public Defect NewDefect { get => _newDefect; diff --git a/ApartmentManager/HousingWebApi/Controllers/DefectCommentsController.cs b/ApartmentManager/HousingWebApi/Controllers/DefectCommentsController.cs index a4fc8e8..8174962 100644 --- a/ApartmentManager/HousingWebApi/Controllers/DefectCommentsController.cs +++ b/ApartmentManager/HousingWebApi/Controllers/DefectCommentsController.cs @@ -16,10 +16,13 @@ namespace HousingWebApi.Controllers { private DataModel db = new DataModel(); - // GET: api/DefectComments - public IQueryable GetDefectComments() + [Route("api/DefectComments/{id}")] + public IQueryable GetDefectComments(int id) { - return db.DefectComments; + var commentlist = from defectComment in db.DefectComments + where (defectComment.DefectId == id) + orderby defectComment.CommentId descending select defectComment; + return commentlist; } // GET: api/DefectComments/5 diff --git a/ApartmentManager/HousingWebApi/Controllers/DefectsController.cs b/ApartmentManager/HousingWebApi/Controllers/DefectsController.cs index 1ec5ca3..587805f 100644 --- a/ApartmentManager/HousingWebApi/Controllers/DefectsController.cs +++ b/ApartmentManager/HousingWebApi/Controllers/DefectsController.cs @@ -21,6 +21,7 @@ namespace HousingWebApi.Controllers { var defectlist = from defect in db.Defects where (defect.ApartmentId == id) + orderby defect.DefectId descending select defect; return defectlist; } diff --git a/ApartmentManager/HousingWebApi/DataModel.cs b/ApartmentManager/HousingWebApi/DataModel.cs index 64826a3..78fd1f2 100644 --- a/ApartmentManager/HousingWebApi/DataModel.cs +++ b/ApartmentManager/HousingWebApi/DataModel.cs @@ -86,6 +86,10 @@ namespace HousingWebApi .Property(e => e.Comment) .IsUnicode(false); + modelBuilder.Entity() + .Property(e => e.Name) + .IsUnicode(false); + modelBuilder.Entity() .Property(e => e.Document) .IsUnicode(false); @@ -116,6 +120,10 @@ namespace HousingWebApi .Property(e => e.Comment) .IsUnicode(false); + modelBuilder.Entity() + .Property(e => e.Name) + .IsUnicode(false); + modelBuilder.Entity() .Property(e => e.Picture) .IsUnicode(false); diff --git a/ApartmentManager/HousingWebApi/Models/ChangeComment.cs b/ApartmentManager/HousingWebApi/Models/ChangeComment.cs index 3c5d8d8..b8ee58e 100644 --- a/ApartmentManager/HousingWebApi/Models/ChangeComment.cs +++ b/ApartmentManager/HousingWebApi/Models/ChangeComment.cs @@ -17,6 +17,11 @@ namespace HousingWebApi public string Comment { get; set; } + [StringLength(50)] + public string Name { get; set; } + + public DateTime? Date { get; set; } + public virtual ApartmentChange ApartmentChange { get; set; } } } diff --git a/ApartmentManager/HousingWebApi/Models/DefectComment.cs b/ApartmentManager/HousingWebApi/Models/DefectComment.cs index c65bac2..41733aa 100644 --- a/ApartmentManager/HousingWebApi/Models/DefectComment.cs +++ b/ApartmentManager/HousingWebApi/Models/DefectComment.cs @@ -16,6 +16,11 @@ namespace HousingWebApi public string Comment { get; set; } + [StringLength(50)] + public string Name { get; set; } + + public DateTime? Date { get; set; } + public virtual Defect Defect { get; set; } } } -- cgit v1.2.3