From 4db2836f85399fb5e14272354a2cdc1058de1ef0 Mon Sep 17 00:00:00 2001 From: Donatas Adamonis Date: Wed, 31 May 2017 00:18:44 +0200 Subject: apartment defects done --- .../ApartmentManager/Handler/ApartmentHandler.cs | 51 ++---- .../Singletons/CatalogSingleton.cs | 10 +- .../ApartmentManager/View/ApartmentDefectPage.xaml | 194 ++++++++++----------- .../View/ApartmentDefectPage.xaml.cs | 9 +- .../View/ApartmentDefectViewPage.xaml | 27 ++- .../View/ApartmentDefectViewPage.xaml.cs | 5 + .../ApartmentManager/View/ApartmentNewDefect.xaml | 18 +- .../View/ApartmentNewDefect.xaml.cs | 5 + .../ApartmentManager/View/BmDefectsPage.xaml | 4 + .../ViewModel/ApartmentViewModel.cs | 6 +- 10 files changed, 167 insertions(+), 162 deletions(-) diff --git a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs index 4cfa4fd..41b9cda 100644 --- a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs @@ -170,24 +170,20 @@ namespace ApartmentManager.Handler Defect.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; var defectsFromDatabase = ApiClient.GetData("api/ApartmentDefects/" + Defect.ApartmentId); var defecttlist = JsonConvert.DeserializeObject>(defectsFromDatabase); + CatalogSingleton.Instance.Defects.Clear(); foreach (var defect in defecttlist) { - var picturesFromDatabase = ApiClient.GetData("api/DefectPicturesById/" + defect.DefectId); - if (picturesFromDatabase != "[]") - { - ApartmentViewModel.CatalogSingleton.DefectPictures = JsonConvert.DeserializeObject>(picturesFromDatabase); - defect.MainPicture = ApartmentViewModel.CatalogSingleton.DefectPictures[0].Picture; - } + defect.Pictures = JsonConvert.DeserializeObject>(ApiClient.GetData("api/DefectPicturesById/" + defect.DefectId)); + defect.Comments = JsonConvert.DeserializeObject>(ApiClient.GetData("api/DefectComments/" + defect.DefectId)); + CatalogSingleton.Instance.Defects.Add(defect); } - ApartmentViewModel.CatalogSingleton.Defects = defecttlist; - ApartmentViewModel.CatalogSingleton.DefectPictures.Clear(); } /////////////////////////////////////////////////////////////////////////////////////////////////// public void DeleteDefectPicture() { try { - ApartmentViewModel.CatalogSingleton.DefectPictures.Remove(ApartmentViewModel.SelectedDefectPicture); + ApartmentViewModel.NewDefect.Pictures.Remove(ApartmentViewModel.SelectedDefectPicture); } catch (Exception e) { @@ -198,8 +194,9 @@ namespace ApartmentManager.Handler { try { - ApartmentViewModel.SelectedDefectPicture.Picture = await ImgurPhotoUploader.UploadPhotoAsync(); - ApartmentViewModel.CatalogSingleton.DefectPictures.Add(ApartmentViewModel.SelectedDefectPicture); + if (ApartmentViewModel.NewDefect.Pictures == null) ApartmentViewModel.NewDefect.Pictures = new ObservableCollection(); + var picture = new DefectPicture() { Picture = await ImgurPhotoUploader.UploadPhotoAsync() }; + ApartmentViewModel.NewDefect.Pictures.Add(picture); } catch (Exception e) { @@ -218,7 +215,7 @@ namespace ApartmentManager.Handler 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 defect.Pictures) { picture.DefectId = defect.DefectId; ApiClient.PostData("api/defectpictures/", picture); @@ -238,26 +235,7 @@ namespace ApartmentManager.Handler return false; else return true; - } - /////////////////////////////////////////////////////////////////////////////////////////////////// - public void GetDefectInfo() - { - try - { - var defectFromDatabase = ApiClient.GetData("api/defects/" + ApartmentViewModel.NewDefect.DefectId); - ApartmentViewModel.CatalogSingleton.Defect = JsonConvert.DeserializeObject(defectFromDatabase); - var picturesFromDatabase = ApiClient.GetData("api/DefectPicturesById/" + 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() { @@ -265,19 +243,20 @@ namespace ApartmentManager.Handler { DefectComment Comment = new DefectComment(); Comment.Comment = ApartmentViewModel.NewDefectComment.Comment; - Comment.DefectId = CatalogSingleton.Instance.Defect.DefectId; + Comment.DefectId = CatalogSingleton.Instance.SelectedDefect.DefectId; Comment.Name = UserSingleton.Instance.CurrentUser.FirstName + " " + UserSingleton.Instance.CurrentUser.LastName; Comment.Date = DateTimeOffset.Now; if (!string.IsNullOrEmpty(Comment.Comment)) { ApiClient.PostData("api/Defectcomments/", Comment); } - var response = ApiClient.GetData("api/Defectcomments/" + CatalogSingleton.Instance.DefectId); + var response = ApiClient.GetData("api/Defectcomments/" + CatalogSingleton.Instance.SelectedDefect.DefectId); var commentlist = JsonConvert.DeserializeObject>(response); - CatalogSingleton.Instance.DefectComments.Clear(); + + CatalogSingleton.Instance.SelectedDefect.Comments.Clear(); foreach (var comment in commentlist) { - CatalogSingleton.Instance.DefectComments.Add(comment); + CatalogSingleton.Instance.SelectedDefect.Comments.Add(comment); } } catch (Exception e) diff --git a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs index 6baa647..a05c01a 100644 --- a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs +++ b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs @@ -18,17 +18,13 @@ namespace ApartmentManager.Singletons public ObservableCollection Residents { get; set; } ////////// For Defects ////////// public ObservableCollection Defects { get; set; } - public ObservableCollection DefectPictures { get; set; } - public ObservableCollection DefectComments { get; set; } - public Defect Defect { get; set; } - public int DefectId { get; set; } + public Defect SelectedDefect { get; set; } ////////// Constructor ////////// private CatalogSingleton() - { - DefectComments = new ObservableCollection(); + { Residents = new ObservableCollection(); Defects = new ObservableCollection(); - DefectPictures = new ObservableCollection(); + SelectedDefect = new Defect(); } } } diff --git a/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml b/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml index 7b4a853..f2f0755 100644 --- a/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml +++ b/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml @@ -6,141 +6,131 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="using:ApartmentManager.View" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:interactivity="using:Microsoft.Xaml.Interactivity" + xmlns:core="using:Microsoft.Xaml.Interactions.Core" mc:Ignorable="d"> - + + + + + + + + + + + + + + - - + + + + + - - - - - - - - - - - - - - - - - - + Text="Apartment Defects"> + + + + + + + + + + + + + + + + + + + + + Margin="0,0,10,0" + FontSize="30" + FontWeight="Bold" + Text="Name :"> + + Margin="0,0,10,0" + FontSize="30" + Text="{Binding Name}"> + + Width="800" + Height="108" + Margin="0,0,10,0" + FontSize="20" + Text="{Binding Description}" + TextWrapping="Wrap"> + - + + Margin="0,0,10,0" + FontSize="25" + FontWeight="Bold" + Text="Status :"> + + Margin="0,0,10,0" + FontSize="25" + Text="{Binding Status}"> + + Margin="700,0,10,0" + HorizontalAlignment="Left" + FontSize="25" + FontWeight="Bold" + Text="Date Submitted :"> + + - - - - - - - - - - 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