diff options
31 files changed, 875 insertions, 202 deletions
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 @@ <Compile Include="ViewModel\BmDefectsViewModel.cs" /> <Compile Include="ViewModel\ApartmentViewModel.cs" /> <Compile Include="ViewModel\LoginViewModel.cs" /> + <Compile Include="View\ApartmentChangesPage.xaml.cs"> + <DependentUpon>ApartmentChangesPage.xaml</DependentUpon> + </Compile> + <Compile Include="View\ApartmentChangesViewPage.xaml.cs"> + <DependentUpon>ApartmentChangesViewPage.xaml</DependentUpon> + </Compile> <Compile Include="View\ApartmentDefectPage.xaml.cs"> <DependentUpon>ApartmentDefectPage.xaml</DependentUpon> </Compile> <Compile Include="View\ApartmentDefectViewPage.xaml.cs"> <DependentUpon>ApartmentDefectViewPage.xaml</DependentUpon> </Compile> + <Compile Include="View\ApartmentNewChangePage.xaml.cs"> + <DependentUpon>ApartmentNewChangePage.xaml</DependentUpon> + </Compile> <Compile Include="View\ApartmentNewDefect.xaml.cs"> <DependentUpon>ApartmentNewDefect.xaml</DependentUpon> </Compile> @@ -223,6 +232,14 @@ <Generator>MSBuild:Compile</Generator> <SubType>Designer</SubType> </Page> + <Page Include="View\ApartmentChangesPage.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> + <Page Include="View\ApartmentChangesViewPage.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> <Page Include="View\ApartmentDefectPage.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> @@ -231,6 +248,10 @@ <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> + <Page Include="View\ApartmentNewChangePage.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> <Page Include="View\ApartmentNewDefect.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> 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 4cfa4fd..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(); } @@ -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<ObservableCollection<Defect>>(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<ObservableCollection<DefectPicture>>(picturesFromDatabase); - defect.MainPicture = ApartmentViewModel.CatalogSingleton.DefectPictures[0].Picture; - } + defect.Pictures = JsonConvert.DeserializeObject<ObservableCollection<DefectPicture>>(ApiClient.GetData("api/DefectPicturesById/" + defect.DefectId)); + defect.Comments = JsonConvert.DeserializeObject<ObservableCollection<DefectComment>>(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<DefectPicture>(); + 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<Defect>(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); @@ -229,7 +226,7 @@ namespace ApartmentManager.Handler { new MessageDialog(e.Message).ShowAsync(); } - + } /////////////////////////////////////////////////////////////////////////////////////////////////// public bool CreateDefect_CanExecute() @@ -240,51 +237,134 @@ namespace ApartmentManager.Handler return true; } /////////////////////////////////////////////////////////////////////////////////////////////////// - public void GetDefectInfo() + public void CreateDefectComment() { try { - var defectFromDatabase = ApiClient.GetData("api/defects/" + ApartmentViewModel.NewDefect.DefectId); - ApartmentViewModel.CatalogSingleton.Defect = JsonConvert.DeserializeObject<Defect>(defectFromDatabase); - 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<DefectComment>>(defectComments); - CatalogSingleton.Instance.DefectId = ApartmentViewModel.NewDefect.DefectId; + DefectComment Comment = new DefectComment(); + Comment.Comment = ApartmentViewModel.NewDefectComment.Comment; + 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.SelectedDefect.DefectId); + var commentlist = JsonConvert.DeserializeObject<ObservableCollection<DefectComment>>(response); + + CatalogSingleton.Instance.SelectedDefect.Comments.Clear(); + foreach (var comment in commentlist) + { + CatalogSingleton.Instance.SelectedDefect.Comments.Add(comment); + } } catch (Exception e) { new MessageDialog(e.Message).ShowAsync(); } - } - /////////////////////////////////////////////////////////////////////////////////////////////////// - public void CreateDefectComment() + /// <summary> + /// Defect HANDLERS + /// </summary> + 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<ObservableCollection<ApartmentChange>>(changesFromDatabase); + CatalogSingleton.Instance.ApartmentChanges.Clear(); + foreach (var apartmentChange in changeslist) + { + apartmentChange.Documents = JsonConvert.DeserializeObject<ObservableCollection<ChangeDocument>>(ApiClient.GetData("api/ChangeDocumentsById/" + apartmentChange.ChangeId)); + apartmentChange.Comments = JsonConvert.DeserializeObject<ObservableCollection<ChangeComment>>(ApiClient.GetData("api/ChangeCommentsById/" + apartmentChange.ChangeId)); + CatalogSingleton.Instance.ApartmentChanges.Add(apartmentChange); + } + } + public void CreateChangeComment() { try { - DefectComment Comment = new DefectComment(); - Comment.Comment = ApartmentViewModel.NewDefectComment.Comment; - Comment.DefectId = CatalogSingleton.Instance.Defect.DefectId; + 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)) { - ApiClient.PostData("api/Defectcomments/", Comment); + var asd =ApiClient.PostData("api/ChangeComments/", Comment); } - var response = ApiClient.GetData("api/Defectcomments/" + CatalogSingleton.Instance.DefectId); - var commentlist = JsonConvert.DeserializeObject<ObservableCollection<DefectComment>>(response); - CatalogSingleton.Instance.DefectComments.Clear(); + var response = ApiClient.GetData("api/ChangeCommentsById/" + CatalogSingleton.Instance.SelectedChange.ChangeId); + var commentlist = JsonConvert.DeserializeObject<ObservableCollection<ChangeComment>>(response); + + CatalogSingleton.Instance.SelectedChange.Comments.Clear(); foreach (var comment in commentlist) { - CatalogSingleton.Instance.DefectComments.Add(comment); + 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<ChangeDocument>(); + 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<ApartmentChange>(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 6baa647..ee101c6 100644 --- a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs +++ b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs @@ -18,17 +18,18 @@ namespace ApartmentManager.Singletons public ObservableCollection<Resident> Residents { get; set; } ////////// For Defects ////////// public ObservableCollection<Defect> Defects { get; set; } - public ObservableCollection<DefectPicture> DefectPictures { get; set; } - public ObservableCollection<DefectComment> DefectComments { get; set; } - public Defect Defect { get; set; } - public int DefectId { get; set; } + public ApartmentChange SelectedChange { get; set; } + ////////// For Defects ////////// + public ObservableCollection<ApartmentChange> ApartmentChanges { get; set; } + public Defect SelectedDefect { get; set; } ////////// Constructor ////////// private CatalogSingleton() { - DefectComments = new ObservableCollection<DefectComment>(); + ApartmentChanges = new ObservableCollection<ApartmentChange>(); Residents = new ObservableCollection<Resident>(); Defects = new ObservableCollection<Defect>(); - DefectPictures = new ObservableCollection<DefectPicture>(); + 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 @@ +<Page + x:Class="ApartmentManager.View.ApartmentChangesPage" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:local="using:ApartmentManager.View" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:viewModel="using:ApartmentManager.ViewModel" + mc:Ignorable="d"> + + <Page.DataContext> + <viewModel:ApartmentViewModel/> + </Page.DataContext> + + <Page.BottomAppBar> + <CommandBar> + <CommandBar.Content> + <Grid /> + </CommandBar.Content> + <AppBarButton + Icon="Add" + Label="Create Defect" Click="GotoNewChangePage"> + </AppBarButton> + </CommandBar> + </Page.BottomAppBar> + + <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> + <Grid.RowDefinitions> + <RowDefinition Height="45"/> + <RowDefinition/> + </Grid.RowDefinitions> + + <TextBlock Grid.Row="0" + HorizontalAlignment="Center" + FontSize="30" + FontWeight="Bold" + Text="Apartment Defects"> + </TextBlock> + + <ListView ItemsSource="{Binding CatalogSingleton.ApartmentChanges}" SelectedItem="{Binding CatalogSingleton.SelectedChange, Mode=TwoWay}" Grid.Row="1" Background="LightGray" SelectionChanged="GotoApartmentChangeViewPage"> + <ListView.ItemContainerStyle> + <Style TargetType="ListViewItem"> + <Setter Property="HorizontalContentAlignment" Value="Stretch" /> + </Style> + </ListView.ItemContainerStyle> + + + <ListView.ItemTemplate> + <DataTemplate> + <Grid Height="200" BorderThickness ="1" Margin="12,12,12,0" BorderBrush="#DFE0E4" Background="White" > + <Grid.ColumnDefinitions> + <ColumnDefinition Width="300" /> + <ColumnDefinition/> + </Grid.ColumnDefinitions> + + <Image + Margin="5" + Source="{Binding Documents[0].Document}" + > + </Image> + + <StackPanel Grid.Column="1" Margin="10"> + + <StackPanel Orientation="Horizontal"> + <TextBlock + Margin="0,0,10,0" + FontSize="30" + FontWeight="Bold" + Text="Name :"> + </TextBlock> + <TextBlock + Margin="0,0,10,0" + FontSize="30" + Text="{Binding Name}"> + </TextBlock> + + </StackPanel> + + <StackPanel Orientation="Horizontal"> + <TextBlock + Width="800" + Height="108" + Margin="0,0,10,0" + FontSize="20" + Text="{Binding Description}" + TextWrapping="Wrap"> + </TextBlock> + </StackPanel> + + <StackPanel Orientation="Horizontal"> + <TextBlock + Margin="0,0,10,0" + FontSize="25" + FontWeight="Bold" + Text="Status :"> + </TextBlock> + <TextBlock + Margin="0,0,10,0" + FontSize="25" + Text="{Binding Status}"> + </TextBlock> + + <TextBlock + Margin="700,0,10,0" + HorizontalAlignment="Left" + FontSize="25" + FontWeight="Bold" + Text="Date Submitted :"> + </TextBlock> + + <TextBlock FontSize="25" Text="{Binding UploadDate.Year}" /> + <TextBlock FontSize="25" Text="-" /> + <TextBlock FontSize="25" Text="{Binding UploadDate.Month}" /> + <TextBlock FontSize="25" Text="-" /> + <TextBlock FontSize="25" Text="{Binding UploadDate.Day}" /> + </StackPanel> + </StackPanel> + </Grid> + </DataTemplate> + </ListView.ItemTemplate> + + </ListView> + </Grid> +</Page> 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 +{ + /// <summary> + /// An empty page that can be used on its own or navigated to within a Frame. + /// </summary> + 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 @@ +<Page + x:Class="ApartmentManager.View.ApartmentChangesViewPage" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:viewModel="using:ApartmentManager.ViewModel" + mc:Ignorable="d"> + + <Page.DataContext> + <viewModel:ApartmentViewModel /> + </Page.DataContext> + + <Page.BottomAppBar> + <CommandBar> + <CommandBar.Content> + <Grid /> + </CommandBar.Content> + <AppBarButton + Icon="back" + Label="Create Defect" Click="GotoApartmentChangesPage" > + </AppBarButton> + </CommandBar> + </Page.BottomAppBar> + + <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> + <ScrollViewer> + <StackPanel> + <StackPanel Margin="10,10,10,0" Orientation="Horizontal"> + <TextBlock + Margin="100,0,0,0" + FontSize="30" + FontWeight="Bold" + Text="Name :" /> + <TextBlock + Margin="10,0,0,0" + FontSize="30" + Text="{Binding CatalogSingleton.SelectedChange.Name}" /> + <TextBlock + Margin="700,0,0,0" + FontSize="30" + FontWeight="Bold" + Text="Status :" /> + <TextBlock + Margin="10,0,0,0" + FontSize="30" + Text="{Binding CatalogSingleton.SelectedChange.Status}" /> + </StackPanel> + <StackPanel Margin="20,0,20,20" Orientation="Horizontal"> + <StackPanel Width="620" Margin="0,50,0,0"> + <GridView + Width="500" + Height="420" + ItemsSource="{Binding CatalogSingleton.SelectedChange.Documents, Mode=TwoWay}"> + <GridView.ItemTemplate> + <DataTemplate> + <Image + Width="220" + Margin="10,0,10,10" + Source="{Binding Document}" /> + </DataTemplate> + </GridView.ItemTemplate> + + </GridView> < |