From 724670b37f15a928b69680c3b80b4ec3cbe86506 Mon Sep 17 00:00:00 2001 From: DonatasAd Date: Wed, 3 May 2017 20:52:40 +0200 Subject: delete faking database --- HousingDatabase.ldf | Bin 8388608 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 HousingDatabase.ldf diff --git a/HousingDatabase.ldf b/HousingDatabase.ldf deleted file mode 100644 index 80e00d5..0000000 Binary files a/HousingDatabase.ldf and /dev/null differ -- cgit v1.2.3 From 4fe698a03dcb6635261a68d39bb9d5f91e1f3eb6 Mon Sep 17 00:00:00 2001 From: DonatasAd Date: Wed, 3 May 2017 20:53:18 +0200 Subject: delete faking database 2 --- HousingDatabase.mdf | Bin 8388608 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 HousingDatabase.mdf diff --git a/HousingDatabase.mdf b/HousingDatabase.mdf deleted file mode 100644 index 9fb615b..0000000 Binary files a/HousingDatabase.mdf and /dev/null differ -- cgit v1.2.3 From 6fd7dd5064f5baed732976b0cfc47101ae52f783 Mon Sep 17 00:00:00 2001 From: Donatas Adamonis Date: Wed, 3 May 2017 20:54:01 +0200 Subject: GET: api/Residents/1 --- ApartmentAdmin | 1 + .../ApartmentManager/Handler/ResidentsHandler.cs | 15 ++++++++++- .../ApartmentManager/Model/CatalogSingleton.cs | 8 +++--- .../Controllers/ResidentsController.cs | 29 ++++++++++++++------- .../HousingWebAPI/HousingWebAPI.csproj | 2 ++ ApartmentManager/HousingWebAPI/ResidentList.cs | 20 ++++++++++++++ ApartmentManager/HousingWebAPI/Web.config | 5 ++-- ApartmentManager/HousingWebApi/Models/Resident.cs | 4 +++ HousingDatabase.ldf | Bin 8388608 -> 0 bytes HousingDatabase.mdf | Bin 8388608 -> 0 bytes 10 files changed, 67 insertions(+), 17 deletions(-) create mode 160000 ApartmentAdmin create mode 100644 ApartmentManager/HousingWebAPI/ResidentList.cs delete mode 100644 HousingDatabase.ldf delete mode 100644 HousingDatabase.mdf diff --git a/ApartmentAdmin b/ApartmentAdmin new file mode 160000 index 0000000..da22548 --- /dev/null +++ b/ApartmentAdmin @@ -0,0 +1 @@ +Subproject commit da22548164ed3a3a9b89f25b31780c35a89a3b3f diff --git a/ApartmentManager/ApartmentManager/Handler/ResidentsHandler.cs b/ApartmentManager/ApartmentManager/Handler/ResidentsHandler.cs index 6b6395e..77136fb 100644 --- a/ApartmentManager/ApartmentManager/Handler/ResidentsHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/ResidentsHandler.cs @@ -18,6 +18,7 @@ namespace ApartmentManager.Handler ApartmentViewModel = apartmenViewModel; } + public void CreateResident() { try @@ -109,7 +110,19 @@ namespace ApartmentManager.Handler new MessageDialog(e.Message).ShowAsync(); } } - + public void GetApartmentResidents() + { + //Resident resident = new Resident(); + //resident.ApartmentNr = ApartmentViewModel.ApartmentNumber; + + + //var roomslist = new PersistenceFacade().GetHotelRooms(roomNumber); + //HotelViewModel.RoomsCatalogSingleton.Rooms.Clear(); + //foreach (var room in roomslist) + //{ + // HotelViewModel.RoomsCatalogSingleton.Rooms.Add(room); + //} + } } diff --git a/ApartmentManager/ApartmentManager/Model/CatalogSingleton.cs b/ApartmentManager/ApartmentManager/Model/CatalogSingleton.cs index 26f7c2e..249a78f 100644 --- a/ApartmentManager/ApartmentManager/Model/CatalogSingleton.cs +++ b/ApartmentManager/ApartmentManager/Model/CatalogSingleton.cs @@ -23,10 +23,10 @@ namespace ApartmentManager.Model Apartment = new ObservableCollection(); Apartment.Add(new Apartment(1,"30 Square meters",2,"200",0,"adresas")); Residents = new ObservableCollection(); - Residents.Add(new Resident("Bibis", "Kiausiai", 3214568, new DateTime(2017, 1, 5, 0, 0, 0), "Bibis@mail.com", 1)); - Residents.Add(new Resident("Bibis", "Kiausiai", 3214568, new DateTime(2017, 1, 5, 0, 0, 0), "Bibis@mail.com", 1)); - Residents.Add(new Resident("Bibis", "Kiausiai", 3214568, new DateTime(2017, 1, 5, 0, 0, 0), "Bibis@mail.com", 1)); - Residents.Add(new Resident("Bibis", "Kiausiai", 3214568, new DateTime(2017, 1, 5, 0, 0, 0), "Bibis@mail.com", 1)); + Residents.Add(new Resident("Bibis", "Kiausiai", 3214568, new DateTime(2017, 1, 5, 0, 0, 0), "Bibis@mail.com", 1,1)); + Residents.Add(new Resident("Bibis", "Kiausiai", 3214568, new DateTime(2017, 1, 5, 0, 0, 0), "Bibis@mail.com", 1,1)); + Residents.Add(new Resident("Bibis", "Kiausiai", 3214568, new DateTime(2017, 1, 5, 0, 0, 0), "Bibis@mail.com", 1,1)); + Residents.Add(new Resident("Bibis", "Kiausiai", 3214568, new DateTime(2017, 1, 5, 0, 0, 0), "Bibis@mail.com", 1,1)); } } } diff --git a/ApartmentManager/HousingWebAPI/Controllers/ResidentsController.cs b/ApartmentManager/HousingWebAPI/Controllers/ResidentsController.cs index b744392..e461b1a 100644 --- a/ApartmentManager/HousingWebAPI/Controllers/ResidentsController.cs +++ b/ApartmentManager/HousingWebAPI/Controllers/ResidentsController.cs @@ -22,17 +22,26 @@ namespace HousingWebApi.Controllers return db.Residents; } - // GET: api/Residents/5 - [ResponseType(typeof(Resident))] - public IHttpActionResult GetResident(int id) + // GET: api/Residents/1 + + [Route("api/Residents/{id}")] + [ResponseType(typeof(ResidentList))] + public IQueryable GetResidents(int id) { - Resident resident = db.Residents.Find(id); - if (resident == null) - { - return NotFound(); - } - - return Ok(resident); + var roomlist = from resident in db.Residents + where (resident.ApartmentNr == id) + select new ResidentList + { + ResidentNr = resident.ResidentNr, + ApartmentNr = resident.ApartmentNr, + FirstName = resident.FirstName, + LastName = resident.LastName, + BirthDate = resident.BirthDate, + Phone = resident.Phone, + Email = resident.Email, + Picture = resident.Picture + }; + return roomlist; } // PUT: api/Residents/5 diff --git a/ApartmentManager/HousingWebAPI/HousingWebAPI.csproj b/ApartmentManager/HousingWebAPI/HousingWebAPI.csproj index 462519c..c6e5113 100644 --- a/ApartmentManager/HousingWebAPI/HousingWebAPI.csproj +++ b/ApartmentManager/HousingWebAPI/HousingWebAPI.csproj @@ -199,6 +199,7 @@ + @@ -254,6 +255,7 @@ + diff --git a/ApartmentManager/HousingWebAPI/ResidentList.cs b/ApartmentManager/HousingWebAPI/ResidentList.cs new file mode 100644 index 0000000..1fd4b30 --- /dev/null +++ b/ApartmentManager/HousingWebAPI/ResidentList.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace HousingWebApi +{ + public class ResidentList + { + public int ResidentNr { get; set; } + public int ApartmentNr { get; set; } + public string FirstName { get; set; } + public string LastName { get; set; } + public DateTime? BirthDate { get; set; } + public int? Phone { get; set; } + public string Email { get; set; } + public byte[] Picture { get; set; } + + } +} \ No newline at end of file diff --git a/ApartmentManager/HousingWebAPI/Web.config b/ApartmentManager/HousingWebAPI/Web.config index 309aba0..f50089d 100644 --- a/ApartmentManager/HousingWebAPI/Web.config +++ b/ApartmentManager/HousingWebAPI/Web.config @@ -79,6 +79,7 @@ - - + + + \ No newline at end of file diff --git a/ApartmentManager/HousingWebApi/Models/Resident.cs b/ApartmentManager/HousingWebApi/Models/Resident.cs index 367631c..4b07bd0 100644 --- a/ApartmentManager/HousingWebApi/Models/Resident.cs +++ b/ApartmentManager/HousingWebApi/Models/Resident.cs @@ -9,9 +9,13 @@ namespace HousingWebApi public partial class Resident { [Key] + [Column(Order = 0)] [DatabaseGenerated(DatabaseGeneratedOption.None)] public int ResidentNr { get; set; } + [Key] + [Column(Order = 1)] + [DatabaseGenerated(DatabaseGeneratedOption.None)] public int ApartmentNr { get; set; } [Required] diff --git a/HousingDatabase.ldf b/HousingDatabase.ldf deleted file mode 100644 index 80e00d5..0000000 Binary files a/HousingDatabase.ldf and /dev/null differ diff --git a/HousingDatabase.mdf b/HousingDatabase.mdf deleted file mode 100644 index 9fb615b..0000000 Binary files a/HousingDatabase.mdf and /dev/null differ -- cgit v1.2.3 From 27af544dc3add3c19b50053dcdab74fdca04352d Mon Sep 17 00:00:00 2001 From: Donatas Adamonis Date: Wed, 3 May 2017 22:10:52 +0200 Subject: qwe --- .../ApartmentManager/ApartmentManager.csproj | 5 +- .../ApartmentManager/Handler/ResidentsHandler.cs | 55 +++++++------- .../ApartmentManager/Model/CatalogSingleton.cs | 5 +- .../ApartmentManager/Model/Resident.cs | 8 +- .../Persistency/PersistenceFacade.cs | 86 ++++++++++++++++++++++ .../ApartmentManager/Persistency/Persistency.cs | 12 --- .../ApartmentManager/View/ResidentsPage.xaml | 2 +- .../ViewModel/ApartmenViewModel.cs | 1 + .../HousingWebAPI/HousingWebAPI.csproj | 1 - ApartmentManager/HousingWebAPI/Web.config | 1 + ApartmentManager/HousingWebApi/Models/Resident.cs | 6 +- 11 files changed, 128 insertions(+), 54 deletions(-) create mode 100644 ApartmentManager/ApartmentManager/Persistency/PersistenceFacade.cs delete mode 100644 ApartmentManager/ApartmentManager/Persistency/Persistency.cs diff --git a/ApartmentManager/ApartmentManager/ApartmentManager.csproj b/ApartmentManager/ApartmentManager/ApartmentManager.csproj index 24202c3..722865c 100644 --- a/ApartmentManager/ApartmentManager/ApartmentManager.csproj +++ b/ApartmentManager/ApartmentManager/ApartmentManager.csproj @@ -106,7 +106,7 @@ - + @@ -177,6 +177,9 @@ + + 5.2.3 + 5.3.1 diff --git a/ApartmentManager/ApartmentManager/Handler/ResidentsHandler.cs b/ApartmentManager/ApartmentManager/Handler/ResidentsHandler.cs index 77136fb..c04007f 100644 --- a/ApartmentManager/ApartmentManager/Handler/ResidentsHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/ResidentsHandler.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using Windows.UI.Popups; using ApartmentManager.Model; +using ApartmentManager.Persistency; using ApartmentManager.ViewModel; namespace ApartmentManager.Handler @@ -17,32 +18,45 @@ namespace ApartmentManager.Handler { ApartmentViewModel = apartmenViewModel; } + public void GetApartmentResidents() + { + Resident resident = new Resident(); + resident.ApartmentNr = ApartmentViewModel.ApartmentNumber; + var residentlist = new PersistenceFacade().GetApartmentResidents(resident); + ApartmentViewModel.CatalogSingleton.Residents.Clear(); + + foreach (var resident2 in residentlist) + { + ApartmentViewModel.CatalogSingleton.Residents.Add(resident2); + } + } public void CreateResident() { try { Resident resident = new Resident(); + resident.ResidentNr = ApartmentViewModel.CatalogSingleton.Residents.Count; + resident.ResidentNr++; resident.ApartmentNr = ApartmentViewModel.ApartmentNumber; - resident.Name = ApartmentViewModel.NewResident.Name; + resident.FirstName = ApartmentViewModel.NewResident.FirstName; resident.LastName = ApartmentViewModel.NewResident.LastName; resident.BirthDate = ApartmentViewModel.NewResident.BirthDate; resident.Email = ApartmentViewModel.NewResident.Email; resident.Picture = ApartmentViewModel.NewResident.Picture; resident.Phone = ApartmentViewModel.NewResident.Phone; - //new PersistenceFacade().CreateHotel(hotel); + new PersistenceFacade().CreateResident(resident); - ////HotelViewModel.Hotels.Hotels.Add(hotel); - //var hotelsFromDatabase = new PersistenceFacade().GetHotels(); + + var residentsFromDatabase = new PersistenceFacade().GetApartmentResidents(resident); + ApartmentViewModel.CatalogSingleton.Residents.Clear(); - //HotelViewModel.HotelCatalogSingleton.Hotels.Clear(); - //foreach (var hotel1 in hotelsFromDatabase) - //{ - // ApartmentViewModel.HotelCatalogSingleton.Hotels.Add(hotel1); - - //} + foreach (var resident2 in residentsFromDatabase) + { + ApartmentViewModel.CatalogSingleton.Residents.Add(resident2); + } } catch (Exception e) { @@ -56,7 +70,7 @@ namespace ApartmentManager.Handler { Resident resident = new Resident(); resident.ApartmentNr = ApartmentViewModel.ApartmentNumber; - resident.Name = ApartmentViewModel.NewResident.Name; + resident.FirstName = ApartmentViewModel.NewResident.FirstName; resident.LastName = ApartmentViewModel.NewResident.LastName; resident.BirthDate = ApartmentViewModel.NewResident.BirthDate; resident.Email = ApartmentViewModel.NewResident.Email; @@ -86,7 +100,7 @@ namespace ApartmentManager.Handler { Resident resident = new Resident(); resident.ApartmentNr = ApartmentViewModel.ApartmentNumber; - resident.Name = ApartmentViewModel.NewResident.Name; + resident.FirstName = ApartmentViewModel.NewResident.FirstName; resident.LastName = ApartmentViewModel.NewResident.LastName; resident.BirthDate = ApartmentViewModel.NewResident.BirthDate; resident.Email = ApartmentViewModel.NewResident.Email; @@ -109,21 +123,6 @@ namespace ApartmentManager.Handler { new MessageDialog(e.Message).ShowAsync(); } - } - public void GetApartmentResidents() - { - //Resident resident = new Resident(); - //resident.ApartmentNr = ApartmentViewModel.ApartmentNumber; - - - //var roomslist = new PersistenceFacade().GetHotelRooms(roomNumber); - //HotelViewModel.RoomsCatalogSingleton.Rooms.Clear(); - //foreach (var room in roomslist) - //{ - // HotelViewModel.RoomsCatalogSingleton.Rooms.Add(room); - //} - } - - + } } } diff --git a/ApartmentManager/ApartmentManager/Model/CatalogSingleton.cs b/ApartmentManager/ApartmentManager/Model/CatalogSingleton.cs index 249a78f..346d652 100644 --- a/ApartmentManager/ApartmentManager/Model/CatalogSingleton.cs +++ b/ApartmentManager/ApartmentManager/Model/CatalogSingleton.cs @@ -23,10 +23,7 @@ namespace ApartmentManager.Model Apartment = new ObservableCollection(); Apartment.Add(new Apartment(1,"30 Square meters",2,"200",0,"adresas")); Residents = new ObservableCollection(); - Residents.Add(new Resident("Bibis", "Kiausiai", 3214568, new DateTime(2017, 1, 5, 0, 0, 0), "Bibis@mail.com", 1,1)); - Residents.Add(new Resident("Bibis", "Kiausiai", 3214568, new DateTime(2017, 1, 5, 0, 0, 0), "Bibis@mail.com", 1,1)); - Residents.Add(new Resident("Bibis", "Kiausiai", 3214568, new DateTime(2017, 1, 5, 0, 0, 0), "Bibis@mail.com", 1,1)); - Residents.Add(new Resident("Bibis", "Kiausiai", 3214568, new DateTime(2017, 1, 5, 0, 0, 0), "Bibis@mail.com", 1,1)); + } } } diff --git a/ApartmentManager/ApartmentManager/Model/Resident.cs b/ApartmentManager/ApartmentManager/Model/Resident.cs index 5e859e6..f9cede7 100644 --- a/ApartmentManager/ApartmentManager/Model/Resident.cs +++ b/ApartmentManager/ApartmentManager/Model/Resident.cs @@ -9,7 +9,7 @@ namespace ApartmentManager.Model { public class Resident { - public string Name { get; set; } + public string FirstName { get; set; } public string LastName { get; set; } public int Phone { get; set; } public DateTime BirthDate { get; set; } @@ -19,9 +19,9 @@ namespace ApartmentManager.Model public int ResidentNr { get; set; } public Resident() { } - public Resident(string Name, string LastName, int Phone, DateTime BirthDate, string Email, int ApartmentNr, int ResidentNr) + public Resident(string FirstName, string LastName, int Phone, DateTime BirthDate, string Email, int ApartmentNr, int ResidentNr) { - this.Name = Name; + this.FirstName = FirstName; this.LastName = LastName; this.Phone = Phone; this.BirthDate = BirthDate; @@ -31,7 +31,7 @@ namespace ApartmentManager.Model } public override string ToString() { - return string.Format($"Name: {Name}, LastName: {LastName}, Birth Date: {BirthDate}, Phone {Phone}, Email {Email} "); + return string.Format($"Name: {FirstName}, LastName: {LastName}, Birth Date: {BirthDate}, Phone {Phone}, Email {Email} "); } } } diff --git a/ApartmentManager/ApartmentManager/Persistency/PersistenceFacade.cs b/ApartmentManager/ApartmentManager/Persistency/PersistenceFacade.cs new file mode 100644 index 0000000..882fd3a --- /dev/null +++ b/ApartmentManager/ApartmentManager/Persistency/PersistenceFacade.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Text; +using System.Threading.Tasks; +using Windows.UI.Popups; +using ApartmentManager.Model; +using Newtonsoft.Json; + +namespace ApartmentManager.Persistency +{ + class PersistenceFacade + { + + const string ServerUrl = "http://localhost:60916"; + HttpClientHandler handler; + + public PersistenceFacade() + { + handler = new HttpClientHandler(); + handler.UseDefaultCredentials = true; + } + + ///Get Get Residents/// + public List GetApartmentResidents(Resident resident) + { + using (var client = new HttpClient(handler)) + { + client.BaseAddress = new Uri(ServerUrl); + client.DefaultRequestHeaders.Clear(); + client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + try + { + string residentsBody = "api/residents/" + resident.ApartmentNr; + var response = client.GetAsync(residentsBody).Result; + + if (response.IsSuccessStatusCode) + { + var residentList = response.Content.ReadAsAsync>().Result; + return residentList.ToList(); + } + + } + catch (Exception ex) + { + new MessageDialog(ex.Message).ShowAsync(); + } + return null; + } + } + ///Get Get Residents/// + public void CreateResident(Resident resident) + { + 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(resident); + var response = client.PostAsync("api/Residents", + 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(); + } + } + + } + + } +} diff --git a/ApartmentManager/ApartmentManager/Persistency/Persistency.cs b/ApartmentManager/ApartmentManager/Persistency/Persistency.cs deleted file mode 100644 index ec46116..0000000 --- a/ApartmentManager/ApartmentManager/Persistency/Persistency.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ApartmentManager.Persistency -{ - class Persistency - { - } -} diff --git a/ApartmentManager/ApartmentManager/View/ResidentsPage.xaml b/ApartmentManager/ApartmentManager/View/ResidentsPage.xaml index 020d4cc..8c8d053 100644 --- a/ApartmentManager/ApartmentManager/View/ResidentsPage.xaml +++ b/ApartmentManager/ApartmentManager/View/ResidentsPage.xaml @@ -18,7 +18,7 @@ - + diff --git a/ApartmentManager/ApartmentManager/ViewModel/ApartmenViewModel.cs b/ApartmentManager/ApartmentManager/ViewModel/ApartmenViewModel.cs index 57aa003..3d76120 100644 --- a/ApartmentManager/ApartmentManager/ViewModel/ApartmenViewModel.cs +++ b/ApartmentManager/ApartmentManager/ViewModel/ApartmenViewModel.cs @@ -36,6 +36,7 @@ namespace ApartmentManager.ViewModel CreateResidentCommand = new RelayCommand(ResidentsHandler.CreateResident); DeleteResidentCommand = new RelayCommand(ResidentsHandler.DeleteResident); UpdateResidentCommand = new RelayCommand(ResidentsHandler.UpdateResident); + ResidentsHandler.GetApartmentResidents(); } public User NewUser diff --git a/ApartmentManager/HousingWebAPI/HousingWebAPI.csproj b/ApartmentManager/HousingWebAPI/HousingWebAPI.csproj index c6e5113..f824c8e 100644 --- a/ApartmentManager/HousingWebAPI/HousingWebAPI.csproj +++ b/ApartmentManager/HousingWebAPI/HousingWebAPI.csproj @@ -255,7 +255,6 @@ - diff --git a/ApartmentManager/HousingWebAPI/Web.config b/ApartmentManager/HousingWebAPI/Web.config index f50089d..abdcf7a 100644 --- a/ApartmentManager/HousingWebAPI/Web.config +++ b/ApartmentManager/HousingWebAPI/Web.config @@ -81,5 +81,6 @@ + \ No newline at end of file diff --git a/ApartmentManager/HousingWebApi/Models/Resident.cs b/ApartmentManager/HousingWebApi/Models/Resident.cs index 4b07bd0..00fc439 100644 --- a/ApartmentManager/HousingWebApi/Models/Resident.cs +++ b/ApartmentManager/HousingWebApi/Models/Resident.cs @@ -19,11 +19,11 @@ namespace HousingWebApi public int ApartmentNr { get; set; } [Required] - [StringLength(15)] + [StringLength(20)] public string FirstName { get; set; } [Required] - [StringLength(15)] + [StringLength(20)] public string LastName { get; set; } [Column(TypeName = "date")] @@ -31,7 +31,7 @@ namespace HousingWebApi public int? Phone { get; set; } - [StringLength(26)] + [StringLength(30)] public string Email { get; set; } [Column(TypeName = "image")] -- cgit v1.2.3