aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonatas Adamonis <dona0169@edu.easj.dk>2017-05-23 22:56:20 +0200
committerDonatas Adamonis <dona0169@edu.easj.dk>2017-05-23 22:56:20 +0200
commit763d01f938ccc1b2b3c35ad7ad45bc3626113a3e (patch)
tree697dc188dc5034ef9aa6d2a057a174b8e7ba7d55
parenta7084d331d4a0701426fe5b76604ec1228f5e96f (diff)
defects
-rw-r--r--ApartmentManager/ApartmentManager/ApartmentManager.csproj1
-rw-r--r--ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs79
-rw-r--r--ApartmentManager/ApartmentManager/Model/Defect.cs5
-rw-r--r--ApartmentManager/ApartmentManager/Model/DefectPicture.cs15
-rw-r--r--ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs7
-rw-r--r--ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml13
-rw-r--r--ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml14
-rw-r--r--ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs14
-rw-r--r--ApartmentManager/HousingWebApi/Controllers/DefectPicturesController.cs10
9 files changed, 128 insertions, 30 deletions
diff --git a/ApartmentManager/ApartmentManager/ApartmentManager.csproj b/ApartmentManager/ApartmentManager/ApartmentManager.csproj
index f267a50..ac7b1f7 100644
--- a/ApartmentManager/ApartmentManager/ApartmentManager.csproj
+++ b/ApartmentManager/ApartmentManager/ApartmentManager.csproj
@@ -105,6 +105,7 @@
<Compile Include="Handler\LoginHandler.cs" />
<Compile Include="Handler\ApartmentHandler.cs" />
<Compile Include="Model\Apartment.cs" />
+ <Compile Include="Model\DefectPicture.cs" />
<Compile Include="Persistency\ImgurPhotoUploader.cs" />
<Compile Include="Singletons\BoardMemberCatalogSingleton.cs" />
<Compile Include="Model\Defect.cs" />
diff --git a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs
index aa5f415..388cbaa 100644
--- a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs
+++ b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs
@@ -28,6 +28,18 @@ namespace ApartmentManager.Handler
/// <summary>
/// APARTMENT HANDLERS
/// </summary>
+
+ public void GetApartment()
+ {
+ string serializedApartment = ApiClient.GetData("api/Apartments/" + ApartmentViewModel.ApartmentNumber);
+
+ Apartment apartment = JsonConvert.DeserializeObject<Apartment>(serializedApartment);
+ ApartmentViewModel.CatalogSingleton.Apartment = apartment;
+ }
+
+ /// <summary>
+ /// RESIDENT HANDLERS
+ /// </summary>
public void GetApartmentResidents()
{
Resident resident = new Resident();
@@ -44,17 +56,7 @@ namespace ApartmentManager.Handler
}
}
- public void GetApartment()
- {
- string serializedApartment = ApiClient.GetData("api/Apartments/" + ApartmentViewModel.ApartmentNumber);
-
- Apartment apartment = JsonConvert.DeserializeObject<Apartment>(serializedApartment);
- ApartmentViewModel.CatalogSingleton.Apartment = apartment;
- }
- /// <summary>
- /// RESIDENT HANDLERS
- /// </summary>
public void CreateResident()
{
try
@@ -162,8 +164,6 @@ namespace ApartmentManager.Handler
{
}
}
-
-
/// <summary>
/// USER HANDLERS
/// </summary>
@@ -181,18 +181,71 @@ namespace ApartmentManager.Handler
{
}
}
+
public void UpdateUser()
{
try
{
User user = new User();
user = ApartmentViewModel.UserSingleton.CurrentUser;
- ApiClient.PutData("api/users/" + user.Username, user);
+ ApiClient.PutData("api/users/" + user.Username, user);
}
catch (Exception e)
{
new MessageDialog(e.Message).ShowAsync();
}
}
+ /// <summary>
+ /// Defect HANDLERS
+ /// </summary>
+ public void GetApartmentDefects()
+ {
+ Defect defect = new Defect();
+ defect.ApartmentId = ApartmentViewModel.ApartmentNumber;
+
+ var residentsFromDatabase = ApiClient.GetData("api/ApartmentDefects/" + defect.ApartmentId);
+ IEnumerable<Defect> defecttlist = JsonConvert.DeserializeObject<IEnumerable<Defect>>(residentsFromDatabase);
+
+ foreach (var qwe in defecttlist)
+ {
+ var picturesFromDatabase = ApiClient.GetData("api/DefectPictures/" + qwe.DefectId);
+ IEnumerable<DefectPicture> picturetlist = JsonConvert.DeserializeObject<IEnumerable<DefectPicture>>(picturesFromDatabase);
+ ApartmentViewModel.CatalogSingleton.DefectPictures.Clear();
+ foreach (var asd in picturetlist)
+ {
+
+ ApartmentViewModel.CatalogSingleton.DefectPictures.Add(asd);
+ }
+ qwe.MainPicture = ApartmentViewModel.CatalogSingleton.DefectPictures[0].Picture;
+
+ }
+
+ ApartmentViewModel.CatalogSingleton.Defects.Clear();
+ ApartmentViewModel.NewResident = new Resident();
+ foreach (var defect2 in defecttlist)
+ {
+
+ ApartmentViewModel.CatalogSingleton.Defects.Add(defect2);
+ }
+ }
+
+ public void DeleteDefectPicture()
+ {
+ ApartmentViewModel.CatalogSingleton.DefectPictures.Remove(ApartmentViewModel.SelectedDefectPicture);
+ }
+ public async void UploadDefectPhoto()
+ {
+ try
+ {
+ ApartmentViewModel.SelectedDefectPicture.Picture = await ImgurPhotoUploader.UploadPhotoAsync();
+ ApartmentViewModel.CatalogSingleton.DefectPictures.Add(ApartmentViewModel.SelectedDefectPicture);
+ var tmp = ApartmentViewModel.UserSingleton.CurrentUser;
+ ApartmentViewModel.UserSingleton.CurrentUser = new User();
+ ApartmentViewModel.UserSingleton.CurrentUser = tmp;
+ }
+ catch (Exception e)
+ {
+ }
+ }
}
}
diff --git a/ApartmentManager/ApartmentManager/Model/Defect.cs b/ApartmentManager/ApartmentManager/Model/Defect.cs
index afb29e2..ea305e6 100644
--- a/ApartmentManager/ApartmentManager/Model/Defect.cs
+++ b/ApartmentManager/ApartmentManager/Model/Defect.cs
@@ -7,13 +7,14 @@ namespace ApartmentManager.Model
public int DefectId { get; set; }
public int ApartmentId { get; set; }
public string Name { get; set; }
- public DateTime? UploadDate { get; set; }
+ public DateTime UploadDate { get; set; }
public string Description { get; set; }
public string Status { get; set; }
+ public string MainPicture { get; set; }
public Defect() { }
- public Defect(int defectId, int apartmentId, string name, DateTime? uploadDate, string description, string status)
+ public Defect(int defectId, int apartmentId, string name, DateTime uploadDate, string description, string status)
{
DefectId = defectId;
ApartmentId = apartmentId;
diff --git a/ApartmentManager/ApartmentManager/Model/DefectPicture.cs b/ApartmentManager/ApartmentManager/Model/DefectPicture.cs
new file mode 100644
index 0000000..ec502f5
--- /dev/null
+++ b/ApartmentManager/ApartmentManager/Model/DefectPicture.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ApartmentManager.Model
+{
+ public class DefectPicture
+ {
+ public int Pictureid { get; set; }
+ public int DefectId { get; set; }
+ public string Picture { get; set; }
+ }
+}
diff --git a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs
index 95f2323..f158063 100644
--- a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs
+++ b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs
@@ -14,14 +14,13 @@ namespace ApartmentManager.Singletons
public Apartment Apartment { get; set; }
public ObservableCollection<Resident> Residents { get; set; }
public ObservableCollection<Defect> Defects { get; set; }
+ public ObservableCollection<DefectPicture> DefectPictures { get; set; }
+
private CatalogSingleton()
{
Residents = new ObservableCollection<Resident>();
Defects = new ObservableCollection<Defect>();
- Defects.Add(new Defect(1, 1, "Broken Pipe", new DateTime(1988, 8, 8), "description", "status"));
- Defects.Add(new Defect(1, 1, "Broken Pipe", new DateTime(1988, 8, 8), "description", "status"));
- Defects.Add(new Defect(1, 1, "Broken Pipe", new DateTime(1988, 8, 8), "description", "status"));
- Defects.Add(new Defect(1, 1, "Broken Pipe", new DateTime(1988, 8, 8), "description", "status"));
+ DefectPictures = new ObservableCollection<DefectPicture>();
}
}
}
diff --git a/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml b/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml
index c73065f..5cff9d2 100644
--- a/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml
+++ b/ApartmentManager/ApartmentManager/View/ApartmentDefectPage.xaml
@@ -31,7 +31,7 @@
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" Background="Gray" BorderThickness="0,0,2,0" BorderBrush="#CCFFFFFF" >
- <Image Stretch="Fill" Source="{Binding Picture}" />
+ <Image Stretch="Fill" Source="{Binding MainPicture}" />
</Grid>
<Grid Grid.Column="1" Margin="2">
<StackPanel Margin="10">
@@ -49,11 +49,16 @@
<StackPanel Orientation="Horizontal"/>
<StackPanel Orientation="Horizontal">
- <TextBlock Text="Status :" Margin="0,0,10,0" FontSize="25"/>
+ <TextBlock Text="Status :" Margin="0,0,10,0" FontSize="25" FontWeight="Bold"/>
<TextBlock Text="{Binding Status}" Margin="0,0,10,0" FontSize="25"/>
- <TextBlock Text="Date Submitted :" Margin="700,0,10,0" FontSize="25" HorizontalAlignment="Left"/>
- <TextBlock Text="{Binding DateUploaded}" Margin="0,0,10,0" FontSize="25"/>
+ <TextBlock Text="Date Submitted :" Margin="700,0,10,0" FontSize="25" FontWeight="Bold" HorizontalAlignment="Left"/>
+ <TextBlock Text="{Binding UploadDate.Year}" FontSize="25"/>
+ <TextBlock Text="-" FontSize="25"/>
+ <TextBlock Text="{Binding UploadDate.Month}" FontSize="25"/>
+ <TextBlock Text="-" FontSize="25"/>
+ <TextBlock Text="{Binding UploadDate.Day}" FontSize="25"/>
+
</StackPanel>
</StackPanel>
diff --git a/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml b/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml
index 770a132..9b22dc9 100644
--- a/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml
+++ b/ApartmentManager/ApartmentManager/View/ApartmentNewDefect.xaml
@@ -19,13 +19,21 @@
<StackPanel Orientation="Horizontal">
<StackPanel Margin="0,5,30,0">
-
- <StackPanel Orientation="Horizontal" >
+ <ListView ItemsSource="{Binding CatalogSingleton.DefectPictures, Mode=TwoWay}" Height="600" Width="500" SelectedItem="{Binding SelectedDefectPicture, Mode=TwoWay}">
+ <ListView.ItemTemplate>
+ <DataTemplate>
+ <Image Source="{Binding Picture}" Width="400" Margin="10"></Image>
+ </DataTemplate>
+ </ListView.ItemTemplate>
+
+ </ListView>
+
+ <StackPanel Orientation="Horizontal" Margin="10" >
<Button Content="Upload Picture" Margin="30,0,0,0"/>
+ <Button Content="Delete Picture" Margin="170,0,0,0" Command="{Binding DeleteDefectPicture}"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,30,0,0"/>
-
<StackPanel Orientation="Horizontal" Margin="0,30,0,0"/>
</StackPanel>
diff --git a/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs b/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs
index c668de2..1b39e8f 100644
--- a/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs
+++ b/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs
@@ -24,6 +24,7 @@ namespace ApartmentManager.ViewModel
private User _newUser;
private Resident _newResident;
private Defect _newDefect;
+ private DefectPicture _selectedDefectPicture;
public static int ApartmentNumber { get; set; }
@@ -34,7 +35,7 @@ namespace ApartmentManager.ViewModel
public ICommand UploadResidentPhoto { get; set; }
public ICommand UploadUserPhoto { get; set; }
public ICommand UpdateUser { get; set; }
-
+ public ICommand DeleteDefectPicture { get; set; }
public ApartmentViewModel()
{
NewUser = new User();
@@ -53,8 +54,10 @@ namespace ApartmentManager.ViewModel
DeleteResidentCommand = new RelayCommand(ApartmentHandler.DeleteResident);
UpdateResidentCommand = new RelayCommand(ApartmentHandler.UpdateResident);
+ DeleteDefectPicture = new RelayCommand(ApartmentHandler.DeleteDefectPicture);
ApartmentHandler.GetApartmentResidents();
ApartmentHandler.GetApartment();
+ ApartmentHandler.GetApartmentDefects();
}
public Defect NewDefect
@@ -84,6 +87,15 @@ namespace ApartmentManager.ViewModel
OnPropertyChanged();
}
}
+ public DefectPicture SelectedDefectPicture
+ {
+ get => _selectedDefectPicture;
+ set
+ {
+ _selectedDefectPicture = value;
+ OnPropertyChanged();
+ }
+ }
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
diff --git a/ApartmentManager/HousingWebApi/Controllers/DefectPicturesController.cs b/ApartmentManager/HousingWebApi/Controllers/DefectPicturesController.cs
index 288a660..2c42471 100644
--- a/ApartmentManager/HousingWebApi/Controllers/DefectPicturesController.cs
+++ b/ApartmentManager/HousingWebApi/Controllers/DefectPicturesController.cs
@@ -16,11 +16,15 @@ namespace HousingWebApi.Controllers
{
private DataModel db = new DataModel();
- // GET: api/DefectPictures
- public IQueryable<DefectPicture> GetDefectPictures()
+ [Route("api/DefectPictures/{id}")]
+ public IQueryable<DefectPicture> GetResidents(int id)
{
- return db.DefectPictures;
+ var pictureslist = from defectPicture in db.DefectPictures
+ where (defectPicture.DefectId == id)
+ select defectPicture;
+ return pictureslist;
}
+
// GET: api/DefectPictures/5
[ResponseType(typeof(DefectPicture))]