diff options
author | Paulius Klezys <paul4618@edu.easj.dk> | 2017-05-12 12:58:44 +0200 |
---|---|---|
committer | Paulius Klezys <paul4618@edu.easj.dk> | 2017-05-12 12:58:44 +0200 |
commit | a59f6e6d3163d2c83ebfcc9c5b5da2d2f2c114c1 (patch) | |
tree | 9066f5c37e0d20f050b9903e14122fdff5c0c1b3 | |
parent | 3bb2b6b33225463abaa881c7562cdc0a39c5ce5e (diff) |
Added things to the view. Most of the things - if not all - are related to the board members
14 files changed, 110 insertions, 72 deletions
diff --git a/ApartmentManager/ApartmentManager/ApartmentManager.csproj b/ApartmentManager/ApartmentManager/ApartmentManager.csproj index de07d8e..6a74df4 100644 --- a/ApartmentManager/ApartmentManager/ApartmentManager.csproj +++ b/ApartmentManager/ApartmentManager/ApartmentManager.csproj @@ -132,6 +132,9 @@ <Compile Include="View\BoardMembersPage.xaml.cs"> <DependentUpon>BoardMembersPage.xaml</DependentUpon> </Compile> + <Compile Include="View\CreateApartmentPage.xaml.cs"> + <DependentUpon>CreateApartmentPage.xaml</DependentUpon> + </Compile> <Compile Include="View\DefectsPicturesBoard.xaml.cs"> <DependentUpon>DefectsPicturesBoard.xaml</DependentUpon> </Compile> @@ -196,6 +199,10 @@ <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> + <Page Include="View\CreateApartmentPage.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> <Page Include="View\DefectsPicturesBoard.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> diff --git a/ApartmentManager/ApartmentManager/Handler/BoardApartmentsHandler.cs b/ApartmentManager/ApartmentManager/Handler/BoardApartmentsHandler.cs index 46740d9..266ba5a 100644 --- a/ApartmentManager/ApartmentManager/Handler/BoardApartmentsHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/BoardApartmentsHandler.cs @@ -8,10 +8,11 @@ using Windows.UI.Popups; using ApartmentManager.Model; using ApartmentManager.Persistency; using ApartmentManager.ViewModel; +using Newtonsoft.Json; namespace ApartmentManager.Handler { - class BoardApartmentsHandler + public class BoardApartmentsHandler { public ApartmentsViewModel ApartmentsViewModel { get; set; } @@ -25,12 +26,14 @@ namespace ApartmentManager.Handler Apartment apartment = new Apartment(); apartment.ApartmentNumber = ApartmentsViewModel.ApartmentsNumber; - var apartmentList = new PersistenceFacade().GetApartments(apartment); - ApartmentsViewModel.ApartmentsCatalogSingleton.Apartment.Clear(); + var apartmentsFromDatabase = ApiClient.GetData("api/apartmentsList/" + apartment.ApartmentNumber); + IEnumerable<Apartment> apartmentslist = JsonConvert.DeserializeObject<IEnumerable<Apartment>>(apartmentsFromDatabase); - foreach (var apartments in apartmentList) + ApartmentsViewModel.ApartmentsCatalogSingleton.Apartment.Clear(); + ApartmentsViewModel.NewApartment = new Apartment(); + foreach (var apartment2 in apartmentslist) { - ApartmentsViewModel.ApartmentsCatalogSingleton.Apartment.Add(apartments); + ApartmentsViewModel.ApartmentsCatalogSingleton.Apartment.Add(apartment2); } } @@ -39,8 +42,6 @@ namespace ApartmentManager.Handler try { Apartment apartment = new Apartment(); - apartment.ApartmentNumber = ApartmentsViewModel.ApartmentsCatalogSingleton.Apartment.Count; - apartment.ApartmentNumber++; apartment.ApartmentNumber = ApartmentsViewModel.ApartmentsNumber; apartment.Address = ApartmentsViewModel.NewApartment.Address; apartment.Floor = ApartmentsViewModel.NewApartment.Floor; @@ -48,17 +49,18 @@ namespace ApartmentManager.Handler apartment.NumberOfRooms = ApartmentsViewModel.NewApartment.NumberOfRooms; apartment.Size = ApartmentsViewModel.NewApartment.Size; - new PersistenceFacade().CreateApartment(apartment); + ApiClient.PostData("api/apartments/", apartment); - var apartmentslist = new PersistenceFacade().GetApartments(apartment); - ApartmentsViewModel.ApartmentsCatalogSingleton.Apartment.Clear(); + var apartmentsFromDatabase = ApiClient.GetData("api/apartmentsList/" + apartment.ApartmentNumber); + IEnumerable<Apartment> apartmentlist = JsonConvert.DeserializeObject<IEnumerable<Apartment>>(apartmentsFromDatabase); - foreach (var apartmento in apartmentslist) + ApartmentsViewModel.ApartmentsCatalogSingleton.Apartment.Clear(); + ApartmentsViewModel.NewApartment = new Apartment(); + foreach (var apartment2 in apartmentlist) { - ApartmentsViewModel.ApartmentsCatalogSingleton.Apartment.Add(apartmento); + ApartmentsViewModel.ApartmentsCatalogSingleton.Apartment.Add(apartment2); } - //ApartmentsViewModel.ApartmentsCatalogSingleton.Apartment.Clear(apartment); } catch (Exception e) { diff --git a/ApartmentManager/ApartmentManager/Handler/BoardResidentsHandler.cs b/ApartmentManager/ApartmentManager/Handler/BoardResidentsHandler.cs index d33d3a3..cf7deaf 100644 --- a/ApartmentManager/ApartmentManager/Handler/BoardResidentsHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/BoardResidentsHandler.cs @@ -11,7 +11,7 @@ using Newtonsoft.Json; namespace ApartmentManager.Handler { - class BoardResidentsHandler + public class BoardResidentsHandler { public ApartmentsViewModel ApartmentsViewModel { get; set; } @@ -33,7 +33,6 @@ namespace ApartmentManager.Handler { ApartmentsViewModel.ApartmentsCatalogSingleton.Residents.Add(resident2); } - } public void CreateResident() diff --git a/ApartmentManager/ApartmentManager/Handler/ResidentsHandler.cs b/ApartmentManager/ApartmentManager/Handler/ResidentsHandler.cs index d406880..203c06e 100644 --- a/ApartmentManager/ApartmentManager/Handler/ResidentsHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/ResidentsHandler.cs @@ -34,7 +34,6 @@ namespace ApartmentManager.Handler { ApartmentViewModel.CatalogSingleton.Residents.Add(resident2); } - } public void CreateResident() diff --git a/ApartmentManager/ApartmentManager/Model/Defect.cs b/ApartmentManager/ApartmentManager/Model/Defect.cs index f695c95..c588c18 100644 --- a/ApartmentManager/ApartmentManager/Model/Defect.cs +++ b/ApartmentManager/ApartmentManager/Model/Defect.cs @@ -7,7 +7,7 @@ using Windows.UI.Xaml.Controls; namespace ApartmentManager.Model { - class Defect + public class Defect { public int DefectNumber { get; set; } public int ApartmentNumber { get; set; } diff --git a/ApartmentManager/ApartmentManager/Persistency/PersistenceFacade.cs b/ApartmentManager/ApartmentManager/Persistency/PersistenceFacade.cs index 1665833..4948e7d 100644 --- a/ApartmentManager/ApartmentManager/Persistency/PersistenceFacade.cs +++ b/ApartmentManager/ApartmentManager/Persistency/PersistenceFacade.cs @@ -25,33 +25,6 @@ namespace ApartmentManager.Persistency // Get apartments - public List<Apartment> GetApartments(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 apartments = "api/apartments/" + apartment.ApartmentNumber; - var response = client.GetAsync(apartments).Result; - - if (response.IsSuccessStatusCode) - { - var apartmentList = response.Content.ReadAsAsync<IEnumerable<Apartment>>().Result; - return apartmentList.ToList(); - } - } - catch (Exception e) - { - new MessageDialog("Cyka blyat").ShowAsync(); - - } - return null; - } - } - public void CreateApartment(Apartment apartment) { using (var client = new HttpClient(handler)) diff --git a/ApartmentManager/ApartmentManager/Singletons/ApartmentsCatalogSingleton.cs b/ApartmentManager/ApartmentManager/Singletons/ApartmentsCatalogSingleton.cs index c65c241..8afbeb3 100644 --- a/ApartmentManager/ApartmentManager/Singletons/ApartmentsCatalogSingleton.cs +++ b/ApartmentManager/ApartmentManager/Singletons/ApartmentsCatalogSingleton.cs @@ -10,7 +10,7 @@ using Windows.UI.Xaml.Media.Imaging; namespace ApartmentManager.Model { - class ApartmentsCatalogSingleton + public class ApartmentsCatalogSingleton { private static ApartmentsCatalogSingleton instance = new ApartmentsCatalogSingleton(); @@ -26,9 +26,9 @@ namespace ApartmentManager.Model User.Add(new User("Bibis", "Kiausiai", "3214568", new DateTime(2017, 1, 5, 2, 27, 0), "Bibis@mail.com", 1)); Apartment = new ObservableCollection<Apartment>(); - Apartment.Add(new Apartment(1, "30 Square meters", 2, "200", 0, "adresas")); - Apartment.Add(new Apartment(2, "40 Square meters", 4, "300", 1, "kvaerkebyvej")); - Apartment.Add(new Apartment(3, "28 Square meters", 1, "125", 0, "ugandavej")); + //Apartment.Add(new Apartment(1, "30 Square meters", 2, "200", 0, "adresas")); + //Apartment.Add(new Apartment(2, "40 Square meters", 4, "300", 1, "kvaerkebyvej")); + //Apartment.Add(new Apartment(3, "28 Square meters", 1, "125", 0, "ugandavej")); Residents = new ObservableCollection<Resident>(); //Residents.Add(new Resident("Bibis", "Kiausiai", 3214568, new DateTime(2017, 1, 5, 0, 0, 0), "Bibis@mail.com", 1)); @@ -37,9 +37,9 @@ namespace ApartmentManager.Model //Residents.Add(new Resident("Bibis", "Kiausiai", 3214568, new DateTime(2017, 1, 5, 0, 0, 0), "Bibis@mail.com", 1)); Defects = new ObservableCollection<Defect>(); - Defects.Add(new Defect(1, 2, "Leaking downpipe", DateTime.Now, new Image(), new Image(), new Image(), "Ze fokin daun paip iz aboot to ekslpod bois", "Iditi vse naxui", "Not fixed")); - Defects.Add(new Defect(1, 2, "Leaking downpipe", DateTime.Now, new Image(), new Image(), new Image(), "Ze fokin daun paip iz aboot to ekslpod bois", "Iditi vse naxui", "Not fixed")); - Defects.Add(new Defect(1, 2, "Leaking downpipe", DateTime.Now, new Image(), new Image(), new Image(), "Ze fokin daun paip iz aboot to ekslpod bois", "Iditi vse naxui", "Fixed")); + Defects.Add(new Defect(1, 2, "Leaking downpipe", DateTime.Now, new Image(), new Image(), new Image(), "downpipe will explode, do something!", "hello", "Not fixed")); + Defects.Add(new Defect(1, 2, "Leaking downpipe", DateTime.Now, new Image(), new Image(), new Image(), "downpipe will explode, do something!", "hello", "Not fixed")); + Defects.Add(new Defect(1, 2, "Leaking downpipe", DateTime.Now, new Image(), new Image(), new Image(), "downpipe will explode, do something!", "hello", "Fixed")); } } } diff --git a/ApartmentManager/ApartmentManager/View/BoardMemberManageApartment.xaml b/ApartmentManager/ApartmentManager/View/BoardMemberManageApartment.xaml index ce8577b..6dc4d48 100644 --- a/ApartmentManager/ApartmentManager/View/BoardMemberManageApartment.xaml +++ b/ApartmentManager/ApartmentManager/View/BoardMemberManageApartment.xaml @@ -19,27 +19,12 @@ <StackPanel Margin="0 0" Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="top" Width="1100" > <StackPanel Orientation="Vertical"> <!--<Image Source="ms-appx:///Assets/plan.jpg" HorizontalAlignment="Left" Margin="0 0" Width="600"></Image>--> - <!--<StackPanel HorizontalAlignment="Right" Orientation="Vertical" VerticalAlignment="Top"> - <TextBlock Margin="0,10,0,10" Text="Apartment information:" HorizontalAlignment="Center" FontSize="20" FontWeight="Bold"/> - <TextBlock Margin="0,10,0,10" Text="Apartment size:"/> - <TextBox Text="{Binding NewApartment.ApartmentNumber, Mode=TwoWay}" /> - <TextBlock Margin="0,10,0,10" Text="Square meters:"/> - <TextBox Text="{Binding NewApartment.Size, Mode=TwoWay}" /> - <TextBlock Margin="0,10,0,10" Text="Number of rooms:"/> - <TextBox Text="{Binding NewApartment.NumberOfRooms}"></TextBox> - <TextBlock Margin="0,10,0,10" Text="Monthly charge:"/> - <TextBox Text="{Binding NewApartment.MonthlyCharge, Mode=TwoWay}" /> - <TextBlock Margin="0,10,0,10" Text="Floor:"/> - <TextBox Text="{Binding NewApartment.Floor, Mode=TwoWay}" /> - <TextBlock Margin="0,10,0,10" Text="Address:" ></TextBlock> - <TextBox Text="{Binding NewApartment.Floor, Mode=TwoWay}"></TextBox> - </StackPanel>--> <Frame Background="Bisque"> <ListView HorizontalAlignment="Left" VerticalAlignment="Top" Width="1100" ItemsSource="{Binding ApartmentsCatalogSingleton.Apartment}" SelectedItem="{Binding NewApartment, Mode=TwoWay}" Height="567"/> </Frame> <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0 0"> <Button Width="150" Margin="50 0" Content="View residents" Click="ButtonBase_OnClick"></Button> - <Button Width="150" Content="New apartment" VerticalAlignment="Bottom" HorizontalAlignment="Center"></Button> + <Button Width="150" Content="Add apartment" Click="CreateApartment" VerticalAlignment="Bottom" HorizontalAlignment="Center"></Button> <Button Width="150" Margin="50 0" Content="Delete apartment" VerticalAlignment="Bottom" HorizontalAlignment="Center"></Button> <Button Width="150" Content="Update apartment" VerticalAlignment="Bottom" HorizontalAlignment="Center"></Button> </StackPanel> diff --git a/ApartmentManager/ApartmentManager/View/BoardMemberManageApartment.xaml.cs b/ApartmentManager/ApartmentManager/View/BoardMemberManageApartment.xaml.cs index fe460a4..b76d732 100644 --- a/ApartmentManager/ApartmentManager/View/BoardMemberManageApartment.xaml.cs +++ b/ApartmentManager/ApartmentManager/View/BoardMemberManageApartment.xaml.cs @@ -31,5 +31,10 @@ namespace ApartmentManager.View { this.Frame.Navigate(typeof(InfoForBoardMembers)); } + + private void CreateApartment(object sender, RoutedEventArgs e) + { + this.Frame.Navigate(typeof(CreateApartmentPage)); + } } } diff --git a/ApartmentManager/ApartmentManager/View/CreateApartmentPage.xaml b/ApartmentManager/ApartmentManager/View/CreateApartmentPage.xaml new file mode 100644 index 0000000..2496cb6 --- /dev/null +++ b/ApartmentManager/ApartmentManager/View/CreateApartmentPage.xaml @@ -0,0 +1,35 @@ +<Page + 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" + x:Class="ApartmentManager.View.CreateApartmentPage" + mc:Ignorable="d"> + + + <Page.DataContext> + <ViewModel:ApartmentsViewModel/> + </Page.DataContext> + + + <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> + <StackPanel HorizontalAlignment="Center" Orientation="Vertical" VerticalAlignment="Center"> + <TextBlock Margin="0,10,0,10" Text="Apartment information:" HorizontalAlignment="Center" FontSize="20" FontWeight="Bold"/> + <TextBlock Margin="0,10,0,10" Text="Apartment number:"/> + <TextBox Text="{Binding NewApartment.ApartmentNumber, Mode=TwoWay}" /> + <TextBlock Margin="0,10,0,10" Text="Square meters:"/> + <TextBox Text="{Binding NewApartment.Size, Mode=TwoWay}" /> + <TextBlock Margin="0,10,0,10" Text="Number of rooms:"/> + <TextBox Text="{Binding NewApartment.NumberOfRooms}"></TextBox> + <TextBlock Margin="0,10,0,10" Text="Monthly charge:"/> + <TextBox Text="{Binding NewApartment.MonthlyCharge, Mode=TwoWay}" /> + <TextBlock Margin="0,10,0,10" Text="Floor:"/> + <TextBox Text="{Binding NewApartment.Floor, Mode=TwoWay}" /> + <TextBlock Margin="0,10,0,10" Text="Address:" ></TextBlock> + <TextBox Text="{Binding NewApartment.Floor, Mode=TwoWay}"></TextBox> + <Button Content="Add" Width="225" Margin="0 20" Command="{Binding CreateApartmentCommand}"></Button> + </StackPanel> + </Grid> +</Page> diff --git a/ApartmentManager/ApartmentManager/View/CreateApartmentPage.xaml.cs b/ApartmentManager/ApartmentManager/View/CreateApartmentPage.xaml.cs new file mode 100644 index 0000000..cc469d5 --- /dev/null +++ b/ApartmentManager/ApartmentManager/View/CreateApartmentPage.xaml.cs @@ -0,0 +1,30 @@ +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 CreateApartmentPage : Page + { + public CreateApartmentPage() + { + this.InitializeComponent(); + } + } +} diff --git a/ApartmentManager/ApartmentManager/View/InfoForBoardMembers.xaml b/ApartmentManager/ApartmentManager/View/InfoForBoardMembers.xaml index 69d5930..f7ae5f5 100644 --- a/ApartmentManager/ApartmentManager/View/InfoForBoardMembers.xaml +++ b/ApartmentManager/ApartmentManager/View/InfoForBoardMembers.xaml @@ -14,10 +14,9 @@ <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <StackPanel Margin="50" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="top" > - <StackPanel Width="650"> <StackPanel> - <ListView Width="700" Height="500" ItemsSource="{Binding ApartmentsCatalogSingleton.Residents}" SelectedItem="{Binding NewResident, Mode=TwoWay}"></ListView> + <ListView ItemsSource="{Binding ApartmentsCatalogSingleton.Residents}" SelectedItem="{Binding NewResident, Mode=TwoWay}"></ListView> </StackPanel> </StackPanel> <StackPanel Margin="50" Orientation="Horizontal" HorizontalAlignment="Right"> diff --git a/ApartmentManager/ApartmentManager/ViewModel/ApartmenViewModel.cs b/ApartmentManager/ApartmentManager/ViewModel/ApartmenViewModel.cs index 3d76120..f4d511b 100644 --- a/ApartmentManager/ApartmentManager/ViewModel/ApartmenViewModel.cs +++ b/ApartmentManager/ApartmentManager/ViewModel/ApartmenViewModel.cs @@ -65,4 +65,4 @@ namespace ApartmentManager.ViewModel PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } -} +}
\ No newline at end of file diff --git a/ApartmentManager/ApartmentManager/ViewModel/ApartmentsViewModel.cs b/ApartmentManager/ApartmentManager/ViewModel/ApartmentsViewModel.cs index e00ef07..2ee6c20 100644 --- a/ApartmentManager/ApartmentManager/ViewModel/ApartmentsViewModel.cs +++ b/ApartmentManager/ApartmentManager/ViewModel/ApartmentsViewModel.cs @@ -12,7 +12,7 @@ using ApartmentManager.Model; namespace ApartmentManager.ViewModel { - class ApartmentsViewModel : INotifyPropertyChanged + public class ApartmentsViewModel : INotifyPropertyChanged { public ApartmentsCatalogSingleton ApartmentsCatalogSingleton { get; set; } private User _newUser; @@ -23,6 +23,8 @@ namespace ApartmentManager.ViewModel public static int ApartmentsNumber { get; set; } public Handler.BoardApartmentsHandler BoardApartmentsHandler { get; set; } + public Handler.BoardResidentsHandler BoardResidentsHandler { get; set; } + public ICommand CreateApartmentCommand { get; set; } public ICommand DeleteApartmentCommand { get; set; } public ICommand UpdateApartmentCommand { get; set; } @@ -35,11 +37,13 @@ namespace ApartmentManager.ViewModel NewResident = new Resident(); NewApartment = new Apartment(); NewDefect = new Defect(); + BoardResidentsHandler = new Handler.BoardResidentsHandler(this); BoardApartmentsHandler = new Handler.BoardApartmentsHandler(this); ApartmentsCatalogSingleton = ApartmentsCatalogSingleton.Instance; ApartmentsNumber = ApartmentsCatalogSingleton.User[0].ApartmentNr; CreateApartmentCommand = new RelayCommand(BoardApartmentsHandler.CreateApartment); - + BoardApartmentsHandler.GetApartments(); + BoardResidentsHandler.GetApartmentsResidents(); } public User NewUser |