diff options
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<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); @@ -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<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; - } - 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<ObservableCollection<DefectComment>>(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<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 Defect SelectedDefect { get; set; } ////////// Constructor ////////// private CatalogSingleton() - { - DefectComments = new ObservableCollection<DefectComment>(); + { Residents = new ObservableCollection<Resident>(); Defects = new ObservableCollection<Defect>(); - DefectPictures = new ObservableCollection<DefectPicture>(); + 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"> - <!--<Page.DataContext> + <Page.DataContext> <ViewModel:ApartmentViewModel/> - </Page.DataContext>--> + </Page.DataContext> + + <Page.BottomAppBar> + <CommandBar> + <CommandBar.Content> + <Grid /> + </CommandBar.Content> + <AppBarButton + Click="NavigateNewDefect" + Command="{Binding ClearDefectTemplateCommand}" + Icon="Add" + Label="Create Defect"> + <AppBarButton.DataContext> + <ViewModel:BmDefectsViewModel /> + </AppBarButton.DataContext> + </AppBarButton> + </CommandBar> + </Page.BottomAppBar> <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> - <StackPanel Margin="10"> - <TextBlock + <Grid.RowDefinitions> + <RowDefinition Height="45"/> + <RowDefinition/> + </Grid.RowDefinitions> + + <TextBlock Grid.Row="0" 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" /> - </Style> - </ListView.ItemContainerStyle> - - <ListView.ItemTemplate> - - <DataTemplate> - <Grid - Height="200" - Margin="0,0,0,5" - Background="LightGray"> - <Grid.ColumnDefinitions> - <ColumnDefinition Width="200" /> - <ColumnDefinition /> - </Grid.ColumnDefinitions> - <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"> + Text="Apartment Defects"> + </TextBlock> + + <ListView ItemsSource="{Binding CatalogSingleton.Defects}" SelectedItem="{Binding CatalogSingleton.SelectedDefect, Mode=TwoWay}" SelectionChanged="NavigateDefectViewPage" Grid.Row="1" Background="LightGray"> + <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="200" /> + <ColumnDefinition/> + </Grid.ColumnDefinitions> + + <Image + Margin="5" + Source="{Binding Pictures[0].Picture}" + Stretch="Fill"> + </Image> + + <StackPanel Grid.Column="1" Margin="10"> <StackPanel Orientation="Horizontal"> <TextBlock - Margin="0,0,10,0" - FontSize="30" - FontWeight="Bold" - Text="Name :" /> + Margin="0,0,10,0" + FontSize="30" + FontWeight="Bold" + Text="Name :"> + </TextBlock> <TextBlock - Margin="0,0,10,0" - FontSize="30" - Text="{Binding Name}" /> + 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" /> + Width="800" + Height="108" + Margin="0,0,10,0" + FontSize="20" + Text="{Binding Description}" + TextWrapping="Wrap"> + </TextBlock> </StackPanel> - <StackPanel Orientation="Horizontal" /> + <StackPanel Orientation="Horizontal"> <TextBlock - Margin="0,0,10,0" - FontSize="25" - FontWeight="Bold" - Text="Status :" /> + Margin="0,0,10,0" + FontSize="25" + FontWeight="Bold" + Text="Status :"> + </TextBlock> <TextBlock - Margin="0,0,10,0" - FontSize="25" - Text="{Binding Status}" /> + 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 :" /> + 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> - </Grid> - </DataTemplate> - </ListView.ItemTemplate> - </ListView> - <StackPanel - Margin="0,15,0,0" - HorizontalAlignment="Right" - Orientation="Horizontal"> - <Button - Width="200" - Margin="0,0,100,0" - Click="NavigateNewDefect" - Content="New Defect" /> - <Button - Width="200" - Margin="0,0,100,0" - Click="NavigateDefect" - Content="View Defect" /> - </StackPanel> - - </StackPanel> - - - - - - - - - - - - - - - - + </DataTemplate> + </ListView.ItemTemplate> + </ListView> + + + </Grid> </Page> diff --git a/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml.cs b/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml.cs index 21bc90e..9ff9dd4 100644 --- a/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml.cs +++ b/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml.cs @@ -23,22 +23,17 @@ namespace ApartmentManager.View /// </summary> 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) + private void NavigateDefectViewPage(object sender, SelectionChangedEventArgs e) { - vm.DefectInfo.Execute(null); Frame.Navigate(typeof(ApartmentDefectViewPagexaml)); } } diff --git a/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPage.xaml b/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPage.xaml index 38a2e50..b14dc99 100644 --- a/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPage.xaml +++ b/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPage.xaml @@ -12,6 +12,23 @@ <ViewModel:ApartmentViewModel /> </Page.DataContext> + <Page.BottomAppBar> + <CommandBar> + <CommandBar.Content> + <Grid /> + </CommandBar.Content> + <AppBarButton + + Command="{Binding ClearDefectTemplateCommand}" + Icon="back" + Label="Create Defect" Click="BackToDefectPage" > + <AppBarButton.DataContext> + <ViewModel:BmDefectsViewModel /> + </AppBarButton.DataContext> + </AppBarButton> + </CommandBar> + </Page.BottomAppBar> + <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <ScrollViewer> <StackPanel> @@ -24,7 +41,7 @@ <TextBlock Margin="10,0,0,0" FontSize="30" - Text="{Binding CatalogSingleton.Defect.Name}" /> + Text="{Binding CatalogSingleton.SelectedDefect.Name}" /> <TextBlock Margin="700,0,0,0" FontSize="30" @@ -33,14 +50,14 @@ <TextBlock Margin="10,0,0,0" FontSize="30" - Text="{Binding CatalogSingleton.Defect.Status}" /> + Text="{Binding CatalogSingleton.SelectedDefect.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.DefectPictures, Mode=TwoWay}"> + ItemsSource="{Binding CatalogSingleton.SelectedDefect.Pictures, Mode=TwoWay}"> <GridView.ItemTemplate> <DataTemplate> <Image @@ -62,7 +79,7 @@ <TextBlock Height="400" Margin="10" - Text="{Binding CatalogSingleton.Defect.Description, Mode=TwoWay}" + Text="{Binding CatalogSingleton.SelectedDefect.Description, Mode=TwoWay}" TextWrapping="WrapWholeWords" /> </Grid> @@ -91,7 +108,7 @@ </StackPanel> - <ListView ItemsSource="{Binding CatalogSingleton.DefectComments}"> + <ListView ItemsSource="{Binding CatalogSingleton.SelectedDefect.Comments}"> <ListView.ItemContainerStyle> <Style TargetType="ListViewItem"> <Setter Property="HorizontalContentAlignment" Value="Stretch" /> diff --git a/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPage.xaml.cs b/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPage.xaml.cs index 7abaf26..6225ebc 100644 --- a/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPage.xaml.cs +++ b/ApartmentManager/ApartmentManager/View/ApartmentDefectViewPage.xaml.cs @@ -30,5 +30,10 @@ namespace ApartmentManager.View vm = new ApartmentViewModel(); DataContext = vm; } + + private void BackToDefectPage(object sender, RoutedEventArgs e) + { + Frame.Navigate(typeof(ApartmentDefectPage)); + } } } diff --git a/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml b/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml index ab919b6..22c169c 100644 --- a/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml +++ b/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml @@ -8,6 +8,22 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> + <Page.BottomAppBar> + <CommandBar> + <CommandBar.Content> + <Grid /> + </CommandBar.Content> + <AppBarButton + + Command="{Binding ClearDefectTemplateCommand}" + Icon="back" + Label="Create Defect" Click="BackToDefectPage"> + <AppBarButton.DataContext> + <ViewModel:BmDefectsViewModel /> + </AppBarButton.DataContext> + </AppBarButton> + </CommandBar> + </Page.BottomAppBar> <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> @@ -25,7 +41,7 @@ <ListView Width="500" Height="600" - ItemsSource="{Binding CatalogSingleton.DefectPictures, Mode=TwoWay}" + ItemsSource="{Binding NewDefect.Pictures, Mode=TwoWay}" SelectedItem="{Binding SelectedDefectPicture, Mode=TwoWay}"> <ListView.ItemTemplate> <DataTemplate> diff --git a/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml.cs b/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml.cs index aed6e6e..31ce2a2 100644 --- a/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml.cs +++ b/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml.cs @@ -40,5 +40,10 @@ namespace ApartmentManager.View Frame.Navigate(typeof(ApartmentDefectPage)); } } + + private void BackToDefectPage(object sender, RoutedEventArgs e) + { + Frame.Navigate(typeof(ApartmentDefectPage)); + } } } diff --git a/ApartmentManager/ApartmentManager/View/BmDefectsPage.xaml b/ApartmentManager/ApartmentManager/View/BmDefectsPage.xaml index 46150d3..b6c9759 100644 --- a/ApartmentManager/ApartmentManager/View/BmDefectsPage.xaml +++ b/ApartmentManager/ApartmentManager/View/BmDefectsPage.xaml @@ -39,9 +39,11 @@ <Setter Property="VerticalAlignment" Value="Top" /> </Style> </Page.Resources> + <Page.DataContext> <vm:BmDefectsViewModel /> </Page.DataContext> + <Page.BottomAppBar> <CommandBar> <CommandBar.Content> @@ -58,6 +60,7 @@ </AppBarButton> </CommandBar> </Page.BottomAppBar> + <Grid Background="#E9EBEE"> <Grid.RowDefinitions> <RowDefinition Height="40" /> @@ -75,6 +78,7 @@ Text="Apartment number: " /> <TextBox Height="32" /> </StackPanel> + <ListView x:Name="DefectsList" Grid.Row="1" diff --git a/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs b/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs index 6048db4..ae0919d 100644 --- a/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs +++ b/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs @@ -39,8 +39,7 @@ namespace ApartmentManager.ViewModel ////////// Defect relay commands////////// public ICommand DeleteDefectPicture { get; set; } public ICommand UploadDefectPicture { get; set; } - public ICommand CreateDefect { get; set; } - public ICommand DefectInfo { get; set; } + public ICommand CreateDefect { get; set; } public ICommand CreateDefectComment { get; set; } ////////// Constructor ////////// public ApartmentViewModel() @@ -67,8 +66,7 @@ namespace ApartmentManager.ViewModel ////////// Defect relay commands////////// UploadDefectPicture = new RelayCommand(ApartmentHandler.UploadDefectPhoto); DeleteDefectPicture = new RelayCommand(ApartmentHandler.DeleteDefectPicture); - CreateDefect = new RelayCommand(ApartmentHandler.CreateDefect, ApartmentHandler.CreateDefect_CanExecute); - DefectInfo = new RelayCommand(ApartmentHandler.GetDefectInfo); + CreateDefect = new RelayCommand(ApartmentHandler.CreateDefect, ApartmentHandler.CreateDefect_CanExecute); CreateDefectComment = new RelayCommand(ApartmentHandler.CreateDefectComment); } ////////// Store Data From Interface////////// |