aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonatas Adamonis <dona0169@edu.easj.dk>2017-05-05 17:24:56 +0200
committerDonatas Adamonis <dona0169@edu.easj.dk>2017-05-05 17:24:56 +0200
commitc28fbd118f517ff8c99d4ea1111ba741724dcea9 (patch)
tree94507f3fcccd608bf1968cdaab9a15024ba4d0fb
parent68d95074babccf9e2d714a03748241c25f432210 (diff)
parentf163283a6fc8bfb4dccd04fb5df79e9e1b5a80d1 (diff)
Merge branch 'master' of https://github.com/marcinzelent/ApartmentAdmin
-rw-r--r--ApartmentManager/ApartmentManager.sln4
-rw-r--r--ApartmentManager/ApartmentManager/Handler/BoardApartmentsHandler.cs35
-rw-r--r--ApartmentManager/ApartmentManager/Persistency/PersistenceFacade.cs59
3 files changed, 95 insertions, 3 deletions
diff --git a/ApartmentManager/ApartmentManager.sln b/ApartmentManager/ApartmentManager.sln
index e9cafc6..3cb16cf 100644
--- a/ApartmentManager/ApartmentManager.sln
+++ b/ApartmentManager/ApartmentManager.sln
@@ -41,8 +41,8 @@ Global
{95401ED6-D03C-417D-8897-81B5454D2426}.Release|x86.ActiveCfg = Release|x86
{95401ED6-D03C-417D-8897-81B5454D2426}.Release|x86.Build.0 = Release|x86
{95401ED6-D03C-417D-8897-81B5454D2426}.Release|x86.Deploy.0 = Release|x86
- {D777744A-9676-4193-BD59-6F30C724C87A}.Debug|Any CPU.ActiveCfg = Release|Any CPU
- {D777744A-9676-4193-BD59-6F30C724C87A}.Debug|Any CPU.Build.0 = Release|Any CPU
+ {D777744A-9676-4193-BD59-6F30C724C87A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D777744A-9676-4193-BD59-6F30C724C87A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D777744A-9676-4193-BD59-6F30C724C87A}.Debug|ARM.ActiveCfg = Debug|Any CPU
{D777744A-9676-4193-BD59-6F30C724C87A}.Debug|ARM.Build.0 = Debug|Any CPU
{D777744A-9676-4193-BD59-6F30C724C87A}.Debug|x64.ActiveCfg = Debug|Any CPU
diff --git a/ApartmentManager/ApartmentManager/Handler/BoardApartmentsHandler.cs b/ApartmentManager/ApartmentManager/Handler/BoardApartmentsHandler.cs
index 5a2929f..46740d9 100644
--- a/ApartmentManager/ApartmentManager/Handler/BoardApartmentsHandler.cs
+++ b/ApartmentManager/ApartmentManager/Handler/BoardApartmentsHandler.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Popups;
@@ -19,13 +20,45 @@ namespace ApartmentManager.Handler
ApartmentsViewModel = apartmentsViewModel;
}
+ public void GetApartments()
+ {
+ Apartment apartment = new Apartment();
+ apartment.ApartmentNumber = ApartmentsViewModel.ApartmentsNumber;
+
+ var apartmentList = new PersistenceFacade().GetApartments(apartment);
+ ApartmentsViewModel.ApartmentsCatalogSingleton.Apartment.Clear();
+
+ foreach (var apartments in apartmentList)
+ {
+ ApartmentsViewModel.ApartmentsCatalogSingleton.Apartment.Add(apartments);
+ }
+ }
+
public void CreateApartment()
{
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;
+ apartment.MonthlyCharge = ApartmentsViewModel.NewApartment.MonthlyCharge;
+ apartment.NumberOfRooms = ApartmentsViewModel.NewApartment.NumberOfRooms;
+ apartment.Size = ApartmentsViewModel.NewApartment.Size;
+
+ new PersistenceFacade().CreateApartment(apartment);
+
+ var apartmentslist = new PersistenceFacade().GetApartments(apartment);
+ ApartmentsViewModel.ApartmentsCatalogSingleton.Apartment.Clear();
+
+ foreach (var apartmento in apartmentslist)
+ {
+ ApartmentsViewModel.ApartmentsCatalogSingleton.Apartment.Add(apartmento);
+ }
+
+ //ApartmentsViewModel.ApartmentsCatalogSingleton.Apartment.Clear(apartment);
}
catch (Exception e)
{
diff --git a/ApartmentManager/ApartmentManager/Persistency/PersistenceFacade.cs b/ApartmentManager/ApartmentManager/Persistency/PersistenceFacade.cs
index 882fd3a..1665833 100644
--- a/ApartmentManager/ApartmentManager/Persistency/PersistenceFacade.cs
+++ b/ApartmentManager/ApartmentManager/Persistency/PersistenceFacade.cs
@@ -23,6 +23,65 @@ namespace ApartmentManager.Persistency
handler.UseDefaultCredentials = true;
}
+ // 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))
+ {
+ client.BaseAddress = new Uri(ServerUrl);
+ client.DefaultRequestHeaders.Clear();
+ client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
+ try
+ {
+ string postBody = JsonConvert.SerializeObject(apartment);
+ var response = client.PostAsync("api/apartments/",
+ new StringContent(postBody, Encoding.UTF8, "application/json"))
+ .Result;
+ if (response.IsSuccessStatusCode)
+ {
+ new MessageDialog("Success").ShowAsync();
+ }
+ else
+ {
+ new MessageDialog("Error").ShowAsync();
+ }
+
+ }
+ catch (Exception ex)
+ {
+ new MessageDialog(ex.Message).ShowAsync();
+ }
+ }
+ }
+
///Get Get Residents///
public List<Resident> GetApartmentResidents(Resident resident)
{