From de05092ce474a8727ed2ec575822c6a43f50af8c Mon Sep 17 00:00:00 2001 From: Donatas Adamonis Date: Wed, 24 May 2017 03:05:14 +0200 Subject: defect view new defects --- .../ApartmentManager/ApartmentManager.csproj | 6 +- .../ApartmentManager/Handler/ApartmentHandler.cs | 77 +++++++++++++++++++--- .../ApartmentManager/Persistency/ApiClient.cs | 4 +- .../Singletons/CatalogSingleton.cs | 4 ++ .../ApartmentManager/View/ApartmentDefectPage.xaml | 6 +- .../View/ApartmentDefectPage.xaml.cs | 11 ++++ .../View/ApartmentDefectViewPage.xaml | 49 ++++++++++++++ .../View/ApartmentDefectViewPage.xaml.cs | 34 ++++++++++ .../View/ApartmentDefectViewPagexaml.xaml | 37 ----------- .../View/ApartmentDefectViewPagexaml.xaml.cs | 30 --------- .../ApartmentManager/View/ApartmentNewDefect.xaml | 8 +-- .../View/ApartmentNewDefect.xaml.cs | 10 +++ .../ViewModel/ApartmentViewModel.cs | 18 +++-- .../Controllers/DefectCommentsController.cs | 8 +-- .../HousingWebApi/Controllers/DefectsController.cs | 3 +- ApartmentManager/HousingWebApi/DataModel.cs | 2 +- ApartmentManager/HousingWebApi/Models/Apartment.cs | 1 - ApartmentManager/HousingWebApi/Models/Defect.cs | 1 - .../HousingWebApi/Models/DefectComment.cs | 5 +- .../HousingWebApi/Models/DefectPicture.cs | 2 - ApartmentManager/HousingWebApi/Models/Resident.cs | 1 - ApartmentManager/HousingWebApi/Models/User.cs | 1 - 22 files changed, 210 insertions(+), 108 deletions(-) create mode 100644 ApartmentManager/ApartmentManager/View/ApartmentDefectViewPage.xaml create mode 100644 ApartmentManager/ApartmentManager/View/ApartmentDefectViewPage.xaml.cs delete mode 100644 ApartmentManager/ApartmentManager/View/ApartmentDefectViewPagexaml.xaml delete mode 100644 ApartmentManager/ApartmentManager/View/ApartmentDefectViewPagexaml.xaml.cs diff --git a/ApartmentManager/ApartmentManager/ApartmentManager.csproj b/ApartmentManager/ApartmentManager/ApartmentManager.csproj index ac7b1f7..e6f14f6 100644 --- a/ApartmentManager/ApartmentManager/ApartmentManager.csproj +++ b/ApartmentManager/ApartmentManager/ApartmentManager.csproj @@ -124,8 +124,8 @@ ApartmentDefectPage.xaml - - ApartmentDefectViewPagexaml.xaml + + ApartmentDefectViewPage.xaml ApartmentNewDefect.xaml @@ -197,7 +197,7 @@ Designer MSBuild:Compile - + Designer MSBuild:Compile diff --git a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs index 388cbaa..095ee73 100644 --- a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs @@ -203,20 +203,24 @@ namespace ApartmentManager.Handler Defect defect = new Defect(); defect.ApartmentId = ApartmentViewModel.ApartmentNumber; - var residentsFromDatabase = ApiClient.GetData("api/ApartmentDefects/" + defect.ApartmentId); - IEnumerable defecttlist = JsonConvert.DeserializeObject>(residentsFromDatabase); + var defectsFromDatabase = ApiClient.GetData("api/ApartmentDefects/" + defect.ApartmentId); + IEnumerable defecttlist = JsonConvert.DeserializeObject>(defectsFromDatabase); foreach (var qwe in defecttlist) { var picturesFromDatabase = ApiClient.GetData("api/DefectPictures/" + qwe.DefectId); - IEnumerable picturetlist = JsonConvert.DeserializeObject>(picturesFromDatabase); - ApartmentViewModel.CatalogSingleton.DefectPictures.Clear(); - foreach (var asd in picturetlist) + if (picturesFromDatabase != "[]") { + IEnumerable picturetlist = JsonConvert.DeserializeObject>(picturesFromDatabase); + ApartmentViewModel.CatalogSingleton.DefectPictures.Clear(); + foreach (var asd in picturetlist) + { - ApartmentViewModel.CatalogSingleton.DefectPictures.Add(asd); + ApartmentViewModel.CatalogSingleton.DefectPictures.Add(asd); + } + qwe.MainPicture = ApartmentViewModel.CatalogSingleton.DefectPictures[0].Picture; } - qwe.MainPicture = ApartmentViewModel.CatalogSingleton.DefectPictures[0].Picture; + } @@ -227,6 +231,7 @@ namespace ApartmentManager.Handler ApartmentViewModel.CatalogSingleton.Defects.Add(defect2); } + ApartmentViewModel.CatalogSingleton.DefectPictures.Clear(); } public void DeleteDefectPicture() @@ -237,14 +242,66 @@ namespace ApartmentManager.Handler { try { + ApartmentViewModel.SelectedDefectPicture = new DefectPicture(); + ApartmentViewModel.SelectedDefectPicture.Picture = await ImgurPhotoUploader.UploadPhotoAsync(); ApartmentViewModel.CatalogSingleton.DefectPictures.Add(ApartmentViewModel.SelectedDefectPicture); - var tmp = ApartmentViewModel.UserSingleton.CurrentUser; - ApartmentViewModel.UserSingleton.CurrentUser = new User(); - ApartmentViewModel.UserSingleton.CurrentUser = tmp; + + } + catch (Exception e) + { + } + } + public void CreateDefect() + { + try + { + Defect defect = new Defect(); + defect = ApartmentViewModel.NewDefect; + defect.ApartmentId = ApartmentViewModel.ApartmentNumber; + defect.Status = "New"; + defect.UploadDate = DateTime.Now; + + ApiClient.PostData("api/defects/", defect); + defect.DefectId = Int32.Parse(ApartmentViewModel.ServerResponse); + foreach (var picture in ApartmentViewModel.CatalogSingleton.DefectPictures) + { + picture.DefectId = defect.DefectId; + ApiClient.PostData("api/defectpictures/", picture); + } + + GetApartmentDefects(); + } catch (Exception e) { + new MessageDialog(e.Message).ShowAsync(); + } + } + + 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 != "[]") + { + IEnumerable picturetlist = + JsonConvert.DeserializeObject>(picturesFromDatabase); + foreach (var asd in picturetlist) + { + + ApartmentViewModel.CatalogSingleton.DefectPictures2.Add(asd); + } + + } } } diff --git a/ApartmentManager/ApartmentManager/Persistency/ApiClient.cs b/ApartmentManager/ApartmentManager/Persistency/ApiClient.cs index 2faa07a..8ae0e1c 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.ViewModel; namespace ApartmentManager.Persistency { @@ -67,7 +68,8 @@ namespace ApartmentManager.Persistency { string serializedData = JsonConvert.SerializeObject(objectToPost); StringContent content = new StringContent(serializedData, Encoding.UTF8, "application/json"); - var response = client.PostAsync(url, content).Result; + var response = client.PostAsync(url, content).Result.Headers.Location.AbsolutePath.Remove(0,13); + ApartmentViewModel.ServerResponse = response; } catch (Exception) { diff --git a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs index f158063..62bbae3 100644 --- a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs +++ b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs @@ -15,12 +15,16 @@ namespace ApartmentManager.Singletons public ObservableCollection Residents { get; set; } public ObservableCollection Defects { get; set; } public ObservableCollection DefectPictures { get; set; } + public ObservableCollection DefectPictures2 { get; set; } + public Defect Defect { get; set; } private CatalogSingleton() { + Residents = new ObservableCollection(); Defects = new ObservableCollection(); DefectPictures = new ObservableCollection(); + DefectPictures2 = new ObservableCollection(); } } } diff --git a/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml b/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml index 5cff9d2..df052a6 100644 --- a/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml +++ b/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml @@ -8,9 +8,9 @@ x:Class="ApartmentManager.View.ApartmentDefectPage" mc:Ignorable="d"> - + @@ -71,7 +71,7 @@ - + diff --git a/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml.cs b/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml.cs index eef6323..ee53458 100644 --- a/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml.cs +++ b/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml.cs @@ -12,6 +12,7 @@ using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Navigation; +using ApartmentManager.ViewModel; // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 @@ -22,14 +23,24 @@ namespace ApartmentManager.View /// public sealed partial class ApartmentDefectPage : Page { + private ApartmentViewModel vm; public ApartmentDefectPage() { this.InitializeComponent(); + vm = new ApartmentViewModel(); + DataContext = vm; } private void NavigateNewDefect(object sender, RoutedEventArgs e) { Frame.Navigate(typeof(ApartmentNewDefect)); } + + private void NavigateDefect(object sender, RoutedEventArgs e) + { + vm.DefectInfo.Execute(null); + //vm.ApartmentHandler.GetDefectInfo(); + Frame.Navigate(typeof(ApartmentDefectViewPagexaml)); + } } } diff --git a/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPage.xaml b/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPage.xaml new file mode 100644 index 0000000..0da2b73 --- /dev/null +++ b/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPage.xaml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPage.xaml.cs b/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPage.xaml.cs new file mode 100644 index 0000000..7abaf26 --- /dev/null +++ b/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPage.xaml.cs @@ -0,0 +1,34 @@ +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; +using ApartmentManager.ViewModel; + +// 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 ApartmentDefectViewPagexaml : Page + { + private ApartmentViewModel vm; + public ApartmentDefectViewPagexaml() + { + this.InitializeComponent(); + vm = new ApartmentViewModel(); + DataContext = vm; + } + } +} diff --git a/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPagexaml.xaml b/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPagexaml.xaml deleted file mode 100644 index 42c48a2..0000000 --- a/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPagexaml.xaml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPagexaml.xaml.cs b/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPagexaml.xaml.cs deleted file mode 100644 index beffd9c..0000000 --- a/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPagexaml.xaml.cs +++ /dev/null @@ -1,30 +0,0 @@ -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 ApartmentDefectViewPagexaml : Page - { - public ApartmentDefectViewPagexaml() - { - this.InitializeComponent(); - } - } -} diff --git a/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml b/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml index 9b22dc9..fa4862e 100644 --- a/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml +++ b/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml @@ -8,9 +8,7 @@ x:Class="ApartmentManager.View.ApartmentNewDefect" mc:Ignorable="d"> - - - + @@ -29,7 +27,7 @@ -