diff options
30 files changed, 1308 insertions, 327 deletions
diff --git a/ApartmentManager/ApartmentManager/ApartmentManager.csproj b/ApartmentManager/ApartmentManager/ApartmentManager.csproj index 2378b79..560357a 100644 --- a/ApartmentManager/ApartmentManager/ApartmentManager.csproj +++ b/ApartmentManager/ApartmentManager/ApartmentManager.csproj @@ -104,7 +104,7 @@ <Compile Include="Handler\LoginHandler.cs" /> <Compile Include="Handler\ApartmentHandler.cs" /> <Compile Include="Model\Apartment.cs" /> - <Compile Include="Model\DefectComments.cs" /> + <Compile Include="Model\DefectComment.cs" /> <Compile Include="Model\DefectPicture.cs" /> <Compile Include="Persistency\ImgurPhotoUploader.cs" /> <Compile Include="Singletons\BmSingleton.cs" /> @@ -115,7 +115,6 @@ <Compile Include="Model\User.cs" /> <Compile Include="Singletons\UserSingleton.cs" /> <Compile Include="Persistency\ApiClient.cs" /> - <Compile Include="Persistency\PersistenceFacade.cs" /> <Compile Include="Properties\Annotations.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="ViewModel\BmViewModel.cs" /> @@ -136,9 +135,15 @@ <Compile Include="View\BmChangesPage.xaml.cs"> <DependentUpon>BmChangesPage.xaml</DependentUpon> </Compile> + <Compile Include="View\BmCreateDefectPage.xaml.cs"> + <DependentUpon>BmCreateDefectPage.xaml</DependentUpon> + </Compile> <Compile Include="View\BmEditApartmentPage.xaml.cs"> <DependentUpon>BmEditApartmentPage.xaml</DependentUpon> </Compile> + <Compile Include="View\BmEditDefectPage.xaml.cs"> + <DependentUpon>BmEditDefectPage.xaml</DependentUpon> + </Compile> <Compile Include="View\BmResidentsPage.xaml.cs"> <DependentUpon>BmResidentsPage.xaml</DependentUpon> </Compile> @@ -154,6 +159,9 @@ <Compile Include="View\BmCreateApartmentPage.xaml.cs"> <DependentUpon>BmCreateApartmentPage.xaml</DependentUpon> </Compile> + <Compile Include="View\BmSingleDefectPage.xaml.cs"> + <DependentUpon>BmSingleDefectPage.xaml</DependentUpon> + </Compile> <Compile Include="View\BmUsersPage.xaml.cs"> <DependentUpon>BmUsersPage.xaml</DependentUpon> </Compile> @@ -219,10 +227,18 @@ <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> + <Page Include="View\BmCreateDefectPage.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> <Page Include="View\BmEditApartmentPage.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> + <Page Include="View\BmEditDefectPage.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> <Page Include="View\BmResidentsPage.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> @@ -243,6 +259,10 @@ <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> + <Page Include="View\BmSingleDefectPage.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> <Page Include="View\BmUsersPage.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> diff --git a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs index 52849aa..ac5999e 100644 --- a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs @@ -178,7 +178,7 @@ namespace ApartmentManager.Handler foreach (var defect in defecttlist) { - var picturesFromDatabase = ApiClient.GetData("api/DefectPictures/" + defect.DefectId); + var picturesFromDatabase = ApiClient.GetData("api/DefectPicturesById/" + defect.DefectId); if (picturesFromDatabase != "[]") { ApartmentViewModel.CatalogSingleton.DefectPictures = JsonConvert.DeserializeObject<ObservableCollection<DefectPicture>>(picturesFromDatabase); @@ -254,10 +254,10 @@ namespace ApartmentManager.Handler { var defectFromDatabase = ApiClient.GetData("api/defects/" + ApartmentViewModel.NewDefect.DefectId); ApartmentViewModel.CatalogSingleton.Defect = JsonConvert.DeserializeObject<Defect>(defectFromDatabase); - var picturesFromDatabase = ApiClient.GetData("api/DefectPictures/" + ApartmentViewModel.NewDefect.DefectId); + var picturesFromDatabase = ApiClient.GetData("api/DefectPicturesById/" + ApartmentViewModel.NewDefect.DefectId); ApartmentViewModel.CatalogSingleton.DefectPictures = JsonConvert.DeserializeObject<ObservableCollection<DefectPicture>>(picturesFromDatabase); var defectComments = ApiClient.GetData("api/Defectcomments/" + ApartmentViewModel.NewDefect.DefectId); - ApartmentViewModel.CatalogSingleton.DefectComments = JsonConvert.DeserializeObject<ObservableCollection<DefectComments>>(defectComments); + ApartmentViewModel.CatalogSingleton.DefectComments = JsonConvert.DeserializeObject<ObservableCollection<DefectComment>>(defectComments); CatalogSingleton.Instance.DefectId = ApartmentViewModel.NewDefect.DefectId; } catch (Exception e) @@ -271,7 +271,7 @@ namespace ApartmentManager.Handler { try { - DefectComments Comment = new DefectComments(); + DefectComment Comment = new DefectComment(); Comment.Comment = ApartmentViewModel.NewDefectComment.Comment; Comment.DefectId = CatalogSingleton.Instance.Defect.DefectId; Comment.Name = UserSingleton.Instance.CurrentUser.FirstName + " " + UserSingleton.Instance.CurrentUser.LastName; @@ -281,7 +281,7 @@ namespace ApartmentManager.Handler ApiClient.PostData("api/Defectcomments/", Comment); } var response = ApiClient.GetData("api/Defectcomments/" + CatalogSingleton.Instance.DefectId); - var commentlist = JsonConvert.DeserializeObject<ObservableCollection<DefectComments>>(response); + var commentlist = JsonConvert.DeserializeObject<ObservableCollection<DefectComment>>(response); CatalogSingleton.Instance.DefectComments.Clear(); foreach (var comment in commentlist) { diff --git a/ApartmentManager/ApartmentManager/Handler/BmHandler.cs b/ApartmentManager/ApartmentManager/Handler/BmHandler.cs index 2cbffea..8709180 100644 --- a/ApartmentManager/ApartmentManager/Handler/BmHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/BmHandler.cs @@ -6,6 +6,7 @@ using ApartmentManager.Persistency; using ApartmentManager.ViewModel; using Newtonsoft.Json; using ApartmentManager.Singletons; +using System.Collections.Generic; namespace ApartmentManager.Handler { @@ -204,5 +205,127 @@ namespace ApartmentManager.Handler } #endregion + #region DEFECTS + + public void GetDefects() + { + var defects = JsonConvert.DeserializeObject<ObservableCollection<Defect>>(ApiClient.GetData("api/Defects/")); + BmSingleton.Instance.Defects.Clear(); + foreach (var defect in defects) + { + defect.Pictures = JsonConvert.DeserializeObject<ObservableCollection<DefectPicture>>(ApiClient.GetData("api/DefectPicturesById/" + defect.DefectId)); + defect.Comments = JsonConvert.DeserializeObject<ObservableCollection<DefectComment>>(ApiClient.GetData("api/DefectComments/" + defect.DefectId)); + BmSingleton.Instance.Defects.Add(defect); + } + } + + public void CreateDefect() + { + try + { + _vm.DefectTemplate.Status = "New"; + _vm.DefectTemplate.UploadDate = DateTime.Now; + var response = JsonConvert.DeserializeObject<Defect>(ApiClient.PostData("api/Defects/", _vm.DefectTemplate)); + foreach(var defectPicture in _vm.DefectTemplate.Pictures) + { + defectPicture.DefectId = response.DefectId; + ApiClient.PostData("api/DefectPictures", defectPicture); + } + GetDefects(); + _vm.DefectTemplate = new Defect(); + } + catch (Exception e) + { + var msg = new MessageDialog(e.Message).ShowAsync(); + } + } + public void UpdateDefect() + { + try + { + ApiClient.PutData("api/Defects/" + _vm.DefectTemplate.DefectId, _vm.DefectTemplate); + var deletedDefectPictures = new List<DefectPicture>(_vm.DeletedDefectPictures); + var addedDefectPictures = new List<DefectPicture>(_vm.AddedDefectPictures); + + foreach (var defectPicture in deletedDefectPictures) + { + ApiClient.DeleteData("api/DefectPictures/" + defectPicture.Pictureid); + _vm.DeletedDefectPictures.Remove(defectPicture); + } + foreach (var defectPicture in addedDefectPictures) + { + defectPicture.DefectId = _vm.DefectTemplate.DefectId; + ApiClient.PostData("api/DefectPictures", defectPicture); + addedDefectPictures.Remove(defectPicture); + } + GetDefects(); + } + catch (Exception e) + { + var msg = new MessageDialog(e.Message).ShowAsync(); + } + } + public void DeleteDefect() + { + try + { + ApiClient.DeleteData("api/Defects/" + _vm.DefectTemplate.DefectId); + BmSingleton.Instance.Defects.Remove(_vm.DefectTemplate); + GetDefects(); + } + catch (Exception e) + { + var msg = new MessageDialog(e.Message).ShowAsync(); + } + } + + public void ClearDefectTemplate() + { + _vm.DefectTemplate = new Defect(); + } + + public async void UploadDefectPicture() + { + if (_vm.DefectTemplate.Pictures == null) _vm.DefectTemplate.Pictures = new ObservableCollection<DefectPicture>(); + var picture = new DefectPicture() { Picture = await ImgurPhotoUploader.UploadPhotoAsync() }; + _vm.DefectTemplate.Pictures.Add(picture); + _vm.AddedDefectPictures.Add(picture); + } + + public void DeleteDefectPicture() + { + _vm.DefectTemplate.Pictures.Remove(_vm.SelectedDefectPicture); + } + + public void DeleteDefectPictureTemp() + { + _vm.DeletedDefectPictures.Add(_vm.SelectedDefectPicture); + _vm.DefectTemplate.Pictures.Remove(_vm.SelectedDefectPicture); + } + + public void CreateDefectComment() + { + try + { + var comment = new DefectComment() + { + Comment = _vm.NewDefectComment.Comment, + DefectId = _vm.DefectTemplate.DefectId, + Name = UserSingleton.Instance.CurrentUser.FirstName + " " + UserSingleton.Instance.CurrentUser.LastName, + Date = DateTimeOffset.Now + }; + if (!string.IsNullOrEmpty(comment.Comment)) + { + ApiClient.PostData("api/DefectComments/", comment); + _vm.DefectTemplate.Comments.Add(comment); + _vm.NewDefectComment = new DefectComment(); + } + } + catch (Exception e) + { + new MessageDialog(e.Message).ShowAsync(); + } + } + #endregion } } diff --git a/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs b/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs index e4d9721..4f93cc1 100644 --- a/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs @@ -79,6 +79,7 @@ namespace ApartmentManager.Handler bvm.BmHandler.GetApartments(); bvm.BmHandler.GetUsers(); bvm.BmHandler.GetResidents(); + bvm.BmHandler.GetDefects(); appShell.AppFrame.Navigate(typeof(BmMainPage)); } else diff --git a/ApartmentManager/ApartmentManager/Model/Defect.cs b/ApartmentManager/ApartmentManager/Model/Defect.cs index ea305e6..6e78e66 100644 --- a/ApartmentManager/ApartmentManager/Model/Defect.cs +++ b/ApartmentManager/ApartmentManager/Model/Defect.cs @@ -1,8 +1,12 @@ -using System; +using ApartmentManager.Annotations; +using System; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Runtime.CompilerServices; namespace ApartmentManager.Model { - public class Defect + public class Defect : INotifyPropertyChanged { public int DefectId { get; set; } public int ApartmentId { get; set; } @@ -11,6 +15,8 @@ namespace ApartmentManager.Model public string Description { get; set; } public string Status { get; set; } public string MainPicture { get; set; } + private ObservableCollection<DefectPicture> _pictures; + private ObservableCollection<DefectComment> _comments; public Defect() { } @@ -23,9 +29,39 @@ namespace ApartmentManager.Model Description = description; Status = status; } + public override string ToString() { return string.Format($"Defect ID: {DefectId}, Apartment number: {ApartmentId}, Name: {Name}, Upload date: {UploadDate}, Description: {Description}, Status: {Status}"); } + + public ObservableCollection<DefectPicture> Pictures + { + get => _pictures; + set + { + _pictures = value; + OnPropertyChanged(nameof(Pictures)); + } + } + + public ObservableCollection<DefectComment> Comments + { + get => _comments; + set + { + _comments = value; + OnPropertyChanged(nameof(Comments)); + } + } + + public event PropertyChangedEventHandler PropertyChanged; + + [NotifyPropertyChangedInvocator] + protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + + } } } diff --git a/ApartmentManager/ApartmentManager/Model/DefectComments.cs b/ApartmentManager/ApartmentManager/Model/DefectComment.cs index a1e6d1e..7610e0b 100644 --- a/ApartmentManager/ApartmentManager/Model/DefectComments.cs +++ b/ApartmentManager/ApartmentManager/Model/DefectComment.cs @@ -1,14 +1,9 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace ApartmentManager.Model { - public class DefectComments + public class DefectComment { - public int CommentId { get; set; } public int DefectId { get; set; } public string Comment { get; set; } diff --git a/ApartmentManager/ApartmentManager/Persistency/ApiClient.cs b/ApartmentManager/ApartmentManager/Persistency/ApiClient.cs index b99f582..8f59a38 100644 --- a/ApartmentManager/ApartmentManager/Persistency/ApiClient.cs +++ b/ApartmentManager/ApartmentManager/Persistency/ApiClient.cs @@ -3,8 +3,6 @@ using System; using System.Net.Http; using System.Net.Http.Headers; using System.Text; -using ApartmentManager.Model; -using ApartmentManager.ViewModel; namespace ApartmentManager.Persistency { diff --git a/ApartmentManager/ApartmentManager/Persistency/PersistenceFacade.cs b/ApartmentManager/ApartmentManager/Persistency/PersistenceFacade.cs deleted file mode 100644 index 3a6f85e..0000000 --- a/ApartmentManager/ApartmentManager/Persistency/PersistenceFacade.cs +++ /dev/null @@ -1,118 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; -using System.Threading.Tasks; -using Windows.UI.Popups; -using ApartmentManager.Model; -using Newtonsoft.Json; - -namespace ApartmentManager.Persistency -{ - class PersistenceFacade - { - - const string ServerUrl = "http://localhost:60916"; - HttpClientHandler handler; - - public PersistenceFacade() - { - handler = new HttpClientHandler(); - handler.UseDefaultCredentials = true; - } - - // Get apartments - - public void CreateApartment(Apartment apartment) - { - using (var client = new HttpClient(handler)) - { - client.BaseAddress = new Uri(ServerUrl); - client.DefaultRequestHeaders.Clear(); - client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - try - { - string postBody = JsonConvert.SerializeObject(apartment); - var response = client.PostAsync("api/apartments/", - new StringContent(postBody, Encoding.UTF8, "application/json")) - .Result; - if (response.IsSuccessStatusCode) - { - new MessageDialog("Success").ShowAsync(); - } - else - { - new MessageDialog("Error").ShowAsync(); - } - - } - catch (Exception ex) - { - new MessageDialog(ex.Message).ShowAsync(); - } - } - } - - ///Get Get Residents/// - public List<Resident> GetApartmentResidents(Resident resident) - { - using (var client = new HttpClient(handler)) - { - client.BaseAddress = new Uri(ServerUrl); - client.DefaultRequestHeaders.Clear(); - client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - try - { - string residentsBody = "api/residents/" + resident.ApartmentId; - var response = client.GetAsync(residentsBody).Result; - - if (response.IsSuccessStatusCode) - { - var residentList = response.Content.ReadAsAsync<IEnumerable<Resident>>().Result; - return residentList.ToList(); - } - - } - catch (Exception ex) - { - new MessageDialog(ex.Message).ShowAsync(); - } - return null; - } - } - ///Get Get Residents/// - public void CreateResident(Resident resident) - { - using (var client = new HttpClient(handler)) - { - client.BaseAddress = new Uri(ServerUrl); - client.DefaultRequestHeaders.Clear(); - client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - try - { - string postBody = JsonConvert.SerializeObject(resident); - var response = client.PostAsync("api/Residents", - new StringContent(postBody, Encoding.UTF8, "application/json")) - .Result; - if (response.IsSuccessStatusCode) - { - new MessageDialog("Success").ShowAsync(); - } - else - { - new MessageDialog("Error").ShowAsync(); - } - - } - catch (Exception ex) - { - new MessageDialog(ex.Message).ShowAsync(); - } - } - - } - - } -} diff --git a/ApartmentManager/ApartmentManager/Singletons/BmSingleton.cs b/ApartmentManager/ApartmentManager/Singletons/BmSingleton.cs index 737a1f3..5ee5019 100644 --- a/ApartmentManager/ApartmentManager/Singletons/BmSingleton.cs +++ b/ApartmentManager/ApartmentManager/Singletons/BmSingleton.cs @@ -17,6 +17,7 @@ namespace ApartmentManager.Singletons { Users = new ObservableCollection<User>(); Residents = new ObservableCollection<Resident>(); + Defects = new ObservableCollection<Defect>(); } } } diff --git a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs index 39f352e..66e081e 100644 --- a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs +++ b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs @@ -20,11 +20,11 @@ namespace ApartmentManager.Singletons public ObservableCollection<DefectPicture> DefectPictures { get; set; } public int DefectId { get; set; } - public ObservableCollection<DefectComments> DefectComments { get; set; } + public ObservableCollection<DefectComment> DefectComments { get; set; } public Defect Defect { get; set; } private CatalogSingleton() { - DefectComments = new ObservableCollection<DefectComments>(); + DefectComments = new ObservableCollection<DefectComment>(); Residents = new ObservableCollection<Resident>(); Defects = new ObservableCollection<Defect>(); DefectPictures = new ObservableCollection<DefectPicture>(); diff --git a/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml b/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml index 001de31..7b4a853 100644 --- a/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml +++ b/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml @@ -1,11 +1,11 @@ <Page + x:Class="ApartmentManager.View.ApartmentDefectPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:local="using:ApartmentManager.View" + xmlns:ViewModel="using:ApartmentManager.ViewModel" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:local="using:ApartmentManager.View" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:ViewModel="using:ApartmentManager.ViewModel" - x:Class="ApartmentManager.View.ApartmentDefectPage" mc:Ignorable="d"> <!--<Page.DataContext> @@ -14,51 +14,90 @@ <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <StackPanel Margin="10"> - <TextBlock Text="Apartment Defects" HorizontalAlignment="Center" FontSize="30" FontWeight="Bold"></TextBlock> - <ListView ItemsSource="{Binding CatalogSingleton.Defects}" Height="500" SelectedItem="{Binding NewDefect, Mode=TwoWay}" > + <TextBlock + HorizontalAlignment="Center" + FontSize="30" + FontWeight="Bold" + Text="Apartment Defects" /> + <ListView + Height="550" + ItemsSource="{Binding CatalogSingleton.Defects}" + SelectedItem="{Binding NewDefect, Mode=TwoWay}"> <ListView.ItemContainerStyle> <Style TargetType="ListViewItem"> - <Setter Property="HorizontalContentAlignment" Value="Stretch"/> + <Setter Property="HorizontalContentAlignment" Value="Stretch" /> </Style> </ListView.ItemContainerStyle> <ListView.ItemTemplate> <DataTemplate> - <Grid Background="LightGray" Height="200" Margin="0,0,0,5"> + <Grid + Height="200" + Margin="0,0,0,5" + Background="LightGray"> <Grid.ColumnDefinitions> - <ColumnDefinition Width="200"/> + <ColumnDefinition Width="200" /> <ColumnDefinition /> </Grid.ColumnDefinitions> - <Grid Grid.Column="0" Background="Gray" BorderThickness="0,0,2,0" BorderBrush="#CCFFFFFF" > - <Image Stretch="Fill" Source="{Binding MainPicture}" /> + <Grid + Grid.Column="0" + Background="Gray" + BorderBrush="#CCFFFFFF" + BorderThickness="0,0,2,0"> + <Image Source="{Binding MainPicture}" Stretch="Fill" /> </Grid> <Grid Grid.Column="1" Margin="2"> <StackPanel Margin="10"> <StackPanel Orientation="Horizontal"> - <TextBlock Text="Name :" Margin="0,0,10,0" FontSize="30" FontWeight="Bold"/> - <TextBlock Text="{Binding Name}" Margin="0,0,10,0" FontSize="30"/> + <TextBlock + Margin="0,0,10,0" + FontSize="30" + FontWeight="Bold" + Text="Name :" /> + <TextBlock + Margin="0,0,10,0" + FontSize="30" + Text="{Binding Name}" /> </StackPanel> <StackPanel Orientation="Horizontal"> - <TextBlock Text="{Binding Description}" TextWrapping="Wrap" Margin="0,0,10,0" FontSize="20" Height="108" Width="800"/> + <TextBlock + Width="800" + Height="108" + Margin="0,0,10,0" + FontSize="20" + Text="{Binding Description}" + TextWrapping="Wrap" /> |