From f163283a6fc8bfb4dccd04fb5df79e9e1b5a80d1 Mon Sep 17 00:00:00 2001 From: Paulius Klezys Date: Fri, 5 May 2017 16:57:51 +0200 Subject: cyka --- ApartmentManager/ApartmentManager.sln | 4 +- .../Handler/BoardApartmentsHandler.cs | 35 ++++++++++++- .../Persistency/PersistenceFacade.cs | 59 ++++++++++++++++++++++ .../HousingWebApi/HousingWebApi.csproj | 4 +- 4 files changed, 97 insertions(+), 5 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 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>().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 GetApartmentResidents(Resident resident) { diff --git a/ApartmentManager/HousingWebApi/HousingWebApi.csproj b/ApartmentManager/HousingWebApi/HousingWebApi.csproj index f824c8e..6f8fde1 100644 --- a/ApartmentManager/HousingWebApi/HousingWebApi.csproj +++ b/ApartmentManager/HousingWebApi/HousingWebApi.csproj @@ -151,12 +151,12 @@ + - @@ -198,8 +198,8 @@ - + -- cgit v1.2.3