aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ApartmentManager/ApartmentManager/Handler/BmHandler.cs71
-rw-r--r--ApartmentManager/ApartmentManager/Handler/LoginHandler.cs1
-rw-r--r--ApartmentManager/ApartmentManager/Model/Resident.cs16
-rw-r--r--ApartmentManager/ApartmentManager/Singletons/BmSingleton.cs5
-rw-r--r--ApartmentManager/ApartmentManager/View/BmResidentsPage.xaml158
-rw-r--r--ApartmentManager/ApartmentManager/ViewModel/BmViewModel.cs25
6 files changed, 255 insertions, 21 deletions
diff --git a/ApartmentManager/ApartmentManager/Handler/BmHandler.cs b/ApartmentManager/ApartmentManager/Handler/BmHandler.cs
index 2b6b5b0..27dc827 100644
--- a/ApartmentManager/ApartmentManager/Handler/BmHandler.cs
+++ b/ApartmentManager/ApartmentManager/Handler/BmHandler.cs
@@ -9,7 +9,7 @@ using ApartmentManager.Singletons;
namespace ApartmentManager.Handler
{
- public class BmHandler
+ public class BmHandler
{
private BmViewModel _vm;
@@ -18,9 +18,12 @@ namespace ApartmentManager.Handler
_vm = vm;
}
+
+ #region APARTMENTS
+
public void GetApartments()
{
- BmSingleton.Instance.Apartments = JsonConvert.DeserializeObject<ObservableCollection<Apartment>> (ApiClient.GetData("api/Apartments/"));
+ BmSingleton.Instance.Apartments = JsonConvert.DeserializeObject<ObservableCollection<Apartment>>(ApiClient.GetData("api/Apartments/"));
}
public void CreateApartment()
@@ -71,5 +74,69 @@ namespace ApartmentManager.Handler
{
_vm.ApartmentTemplate = new Apartment();
}
+ #endregion
+
+ #region RESIDENTS
+
+ public void GetResidents()
+ {
+ var residents = JsonConvert.DeserializeObject<ObservableCollection<Resident>>(ApiClient.GetData("api/Residents/"));
+ BmSingleton.Instance.Residents.Clear();
+ foreach (var resident in residents) BmSingleton.Instance.Residents.Add(resident);
+ }
+
+ public void CreateResident()
+ {
+ try
+ {
+ ApiClient.PostData("api/Residents/", _vm.ResidentTemplate);
+ GetResidents();
+ _vm.ResidentTemplate = new Resident();
+ }
+ catch (Exception e)
+ {
+ var msg = new MessageDialog(e.Message).ShowAsync();
+ }
+ }
+ public void UpdateResident()
+ {
+ try
+ {
+ ApiClient.PutData("api/Residents/" + _vm.ResidentTemplate.ResidentId, _vm.ResidentTemplate);
+ GetResidents();
+ }
+ catch (Exception e)
+ {
+ var msg = new MessageDialog(e.Message).ShowAsync();
+ }
+ }
+ public void DeleteResident()
+ {
+ try
+ {
+ ApiClient.DeleteData("api/Residents/" + _vm.ResidentTemplate.ResidentId);
+ BmSingleton.Instance.Residents.Remove(_vm.ResidentTemplate);
+ GetResidents();
+ }
+ catch (Exception e)
+ {
+ var msg = new MessageDialog(e.Message).ShowAsync();
+ }
+ }
+
+ public async void UploadResidentPhoto()
+ {
+ _vm.ResidentTemplate.Picture = await ImgurPhotoUploader.UploadPhotoAsync();
+ var tmp = _vm.ResidentTemplate;
+ _vm.ResidentTemplate = new Resident();
+ _vm.ResidentTemplate = tmp;
+ }
+
+ public void ClearResidentTemplate()
+ {
+ _vm.ResidentTemplate = new Resident();
+ }
+ #endregion
+
}
}
diff --git a/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs b/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs
index d0088d9..e41f5ed 100644
--- a/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs
+++ b/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs
@@ -77,6 +77,7 @@ namespace ApartmentManager.Handler
{
BmViewModel bvm = new BmViewModel();
bvm.BmHandler.GetApartments();
+ bvm.BmHandler.GetResidents();
appShell.AppFrame.Navigate(typeof(BmMainPage));
}
else
diff --git a/ApartmentManager/ApartmentManager/Model/Resident.cs b/ApartmentManager/ApartmentManager/Model/Resident.cs
index ac20ffa..aaa7af4 100644
--- a/ApartmentManager/ApartmentManager/Model/Resident.cs
+++ b/ApartmentManager/ApartmentManager/Model/Resident.cs
@@ -8,7 +8,7 @@ namespace ApartmentManager.Model
public int ApartmentId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
- public DateTime BirthDate { get; set; }
+ public DateTimeOffset BirthDate { get; set; }
public string Phone { get; set; }
public string Email { get; set; }
public string Picture { get; set; }
@@ -17,19 +17,5 @@ namespace ApartmentManager.Model
{
BirthDate = DateTime.Now;
}
- public Resident(int residentId, int apartmentId, string firstName, string lastName, DateTime birthDate, string phone, string email)
- {
- ResidentId = residentId;
- ApartmentId = apartmentId;
- FirstName = firstName;
- LastName = lastName;
- BirthDate = birthDate;
- Phone = phone;
- Email = email;
- }
- public override string ToString()
- {
- return string.Format($"First name: {FirstName}, Last name: {LastName}, Birth date: {BirthDate}, Phone: {Phone}, Email: {Email} ");
- }
}
}
diff --git a/ApartmentManager/ApartmentManager/Singletons/BmSingleton.cs b/ApartmentManager/ApartmentManager/Singletons/BmSingleton.cs
index 966390c..14c1100 100644
--- a/ApartmentManager/ApartmentManager/Singletons/BmSingleton.cs
+++ b/ApartmentManager/ApartmentManager/Singletons/BmSingleton.cs
@@ -13,6 +13,9 @@ namespace ApartmentManager.Singletons
public ObservableCollection<Resident> Residents { get; set; }
public ObservableCollection<Defect> Defects { get; set; }
- private BmSingleton() { }
+ private BmSingleton()
+ {
+ Residents = new ObservableCollection<Resident>();
+ }
}
}
diff --git a/ApartmentManager/ApartmentManager/View/BmResidentsPage.xaml b/ApartmentManager/ApartmentManager/View/BmResidentsPage.xaml
index 7607d86..4bcb6b0 100644
--- a/ApartmentManager/ApartmentManager/View/BmResidentsPage.xaml
+++ b/ApartmentManager/ApartmentManager/View/BmResidentsPage.xaml
@@ -5,7 +5,163 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:ApartmentManager.View"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:vm="using:ApartmentManager.ViewModel"
mc:Ignorable="d">
- <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" />
+ <Page.Resources>
+ <Style x:Key="ListItemStyle" TargetType="ListViewItem">
+ <Setter Property="Background" Value="White" />
+ <Setter Property="Padding" Value="0" />
+ <Setter Property="Margin" Value="12,12,12,0" />
+ <Setter Property="BorderThickness" Value="1" />
+ <Setter Property="BorderBrush" Value="#DFE0E4" />
+ <Setter Property="HorizontalContentAlignment" Value="Stretch" />
+ <Setter Property="VerticalContentAlignment" Value="Center" />
+ <Setter Property="Template">
+ <Setter.Value>
+ <ControlTemplate TargetType="ListViewItem">
+ <ListViewItemPresenter />
+ </ControlTemplate>
+ </Setter.Value>
+ </Setter>
+ </Style>
+ <Style x:Key="TextBlockStyle" TargetType="TextBlock">
+ <Setter Property="Margin" Value="0,0,0,10" />
+ <Setter Property="Foreground" Value="White" />
+ </Style>
+ <Style x:Key="ActionButtonStyle" TargetType="Button">
+ <Setter Property="Background" Value="Transparent" />
+ <Setter Property="Height" Value="40" />
+ <Setter Property="Width" Value="40" />
+ <Setter Property="HorizontalAlignment" Value="Right" />
+ <Setter Property="VerticalAlignment" Value="Top" />
+ </Style>
+ </Page.Resources>
+
+ <Page.DataContext>
+ <vm:BmViewModel />
+ </Page.DataContext>
+
+ <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
+ <Grid>
+ <Grid.RowDefinitions>
+ <RowDefinition Height="50" />
+ <RowDefinition />
+ </Grid.RowDefinitions>
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition />
+ <ColumnDefinition Width="450" />
+ </Grid.ColumnDefinitions>
+
+ <Grid Background="#E9EBEE">
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition />
+ <ColumnDefinition />
+ </Grid.ColumnDefinitions>
+ <StackPanel Orientation="Horizontal">
+ <TextBlock
+ Margin="50,0,10,0"
+ VerticalAlignment="Center"
+ FontSize="18"
+ Text="Search: " />
+ <TextBox Height="32" PlaceholderText="Type search parameters..." />
+ </StackPanel>
+ <AppBarButton
+ Grid.Column="1"
+ HorizontalAlignment="Right"
+ Command="{Binding ClearResidentTemplateCommand}"
+ Icon="Add" />
+ </Grid>
+ <ListView
+ Grid.Row="1"
+ Padding="10"
+ Background="#E9EBEE"
+ ItemsSource="{Binding BmSingleton.Residents}"
+ SelectedItem="{Binding ResidentTemplate, Mode=TwoWay}">
+
+ <ListView.ItemContainerStyle>
+ <Style BasedOn="{StaticResource ListItemStyle}" TargetType="ListViewItem" />
+ </ListView.ItemContainerStyle>
+
+ <ListView.ItemTemplate>
+
+ <DataTemplate>
+ <Grid Height="150">
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="150" />
+ <ColumnDefinition />
+ </Grid.ColumnDefinitions>
+
+ <Image
+ Margin="5"
+ Source="{Binding Picture}"
+ Stretch="Fill" />
+
+ <Grid Grid.Column="1">
+ <StackPanel Margin="10,0,0,0" VerticalAlignment="Center">
+ <TextBlock FontSize="20"><Run Text="Name: " /><Run Text="{Binding FirstName}" /><Run Text=" " /><Run Text="{Binding LastName}" /></TextBlock>
+ <TextBlock><Run Text="Apartment number: " /><Run Text="{Binding ApartmentId}" /></TextBlock>
+ <TextBlock><Run Text="Birth date: " /><Run Text="{Binding BirthDate.Day}" /><Run Text="." /><Run Text="{Binding BirthDate.Month}" /><Run Text="." /><Run Text="{Binding BirthDate.Year}" /></TextBlock>
+ <TextBlock><Run Text="E-mail address: " /><Run Text="{Binding Email}" /></TextBlock>
+ <TextBlock><Run Text="Phone number: " /><Run Text="{Binding Phone}" /></TextBlock>
+ </StackPanel>
+ </Grid>
+ </Grid>
+ </DataTemplate>
+
+ </ListView.ItemTemplate>
+ </ListView>
+ <StackPanel
+ Grid.RowSpan="2"
+ Grid.Column="1"
+ Width="400"
+ HorizontalAlignment="Center">
+ <TextBlock
+ Margin="0,5,0,10"
+ HorizontalAlignment="Center"
+ FontSize="20"
+ FontWeight="Bold"
+ Text="Resident Info" />
+ <Image
+ Width="150"
+ Height="150"
+ Source="{Binding ResidentTemplate.Picture, Mode=TwoWay}" />
+ <Button
+ Margin="0,5,0,0"
+ HorizontalAlignment="Stretch"
+ Command="{Binding UploadResidentPhotoCommand}"
+ Content="Upload Picture" />
+ <TextBlock Margin="0,5,0,1" Text="Apartment number" />
+ <TextBox Text="{Binding ResidentTemplate.ApartmentId, Mode=TwoWay}" />
+ <TextBlock Margin="0,5,0,1" Text=" First name" />
+ <TextBox Text="{Binding ResidentTemplate.FirstName, Mode=TwoWay}" />
+ <TextBlock Margin="0,5,0,1" Text="Last Name" />
+ <TextBox Text="{Binding ResidentTemplate.LastName, Mode=TwoWay}" />
+ <TextBlock Margin="0,5,0,1" Text="Birth date" />
+ <DatePicker HorizontalAlignment="Stretch" Date="{Binding ResidentTemplate.BirthDate, Mode=TwoWay}" />
+ <TextBlock Margin="0,5,0,1" Text="Email address" />
+ <TextBox Text="{Binding ResidentTemplate.Email, Mode=TwoWay}" />
+ <TextBlock Margin="0,5,0,1" Text="Phone number" />
+ <TextBox Text="{Binding ResidentTemplate.Phone, Mode=TwoWay}" />
+
+ <StackPanel Margin="0,10,0,0" Orientation="Horizontal">
+ <Button
+ Width="125"
+ Margin="0"
+ Command="{Binding CreateResidentCommand}"
+ Content="Create" />
+ <Button
+ Width="125"
+ Margin="10,0"
+ Command="{Binding DeleteResidentCommand}"
+ Content="Delete" />
+ <Button
+ Width="125"
+ Margin="0"
+ Command="{Binding UpdateResidentCommand}"
+ Content="Update" />
+ </StackPanel>
+ </StackPanel>
+ </Grid>
+ </Grid>
</Page>
diff --git a/ApartmentManager/ApartmentManager/ViewModel/BmViewModel.cs b/ApartmentManager/ApartmentManager/ViewModel/BmViewModel.cs
index 9faf80e..0ccea4e 100644
--- a/ApartmentManager/ApartmentManager/ViewModel/BmViewModel.cs
+++ b/ApartmentManager/ApartmentManager/ViewModel/BmViewModel.cs
@@ -24,9 +24,14 @@ namespace ApartmentManager.ViewModel
public ICommand ClearApartmentTemplateCommand { get; }
public ICommand GetApartmentsCommand { get; }
- public ICommand DeleteDefectCommand { get; }
-
+ public ICommand CreateResidentCommand { get; }
+ public ICommand DeleteResidentCommand { get; }
+ public ICommand UpdateResidentCommand { get; }
+ public ICommand UploadResidentPhotoCommand { get; }
+ public ICommand ClearResidentTemplateCommand { get; }
+
private static Apartment _apartmentTemplate = new Apartment();
+ private static Resident _residentTemplate = new Resident();
public BmViewModel()
{
@@ -38,6 +43,12 @@ namespace ApartmentManager.ViewModel
UploadApartmentPlanCommand = new RelayCommand(BmHandler.UploadApartmentPlan);
ClearApartmentTemplateCommand = new RelayCommand(BmHandler.ClearApartmentTemplate);
GetApartmentsCommand = new RelayCommand(BmHandler.GetApartments);
+
+ CreateResidentCommand = new RelayCommand(BmHandler.CreateResident);
+ DeleteResidentCommand = new RelayCommand(BmHandler.DeleteResident);
+ UpdateResidentCommand = new RelayCommand(BmHandler.UpdateResident);
+ UploadResidentPhotoCommand = new RelayCommand(BmHandler.UploadResidentPhoto);
+ ClearResidentTemplateCommand = new RelayCommand(BmHandler.ClearResidentTemplate);
}
public Apartment ApartmentTemplate
@@ -50,6 +61,16 @@ namespace ApartmentManager.ViewModel
}
}
+ public Resident ResidentTemplate
+ {
+ get => _residentTemplate;
+ set
+ {
+ _residentTemplate = value;
+ OnPropertyChanged();
+ }
+ }
+
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]