diff options
9 files changed, 68 insertions, 56 deletions
diff --git a/ApartmentManager/ApartmentManager/Handler/ResidentsHandler.cs b/ApartmentManager/ApartmentManager/Handler/ResidentsHandler.cs index c04007f..d406880 100644 --- a/ApartmentManager/ApartmentManager/Handler/ResidentsHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/ResidentsHandler.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; @@ -7,6 +8,7 @@ using Windows.UI.Popups; using ApartmentManager.Model; using ApartmentManager.Persistency; using ApartmentManager.ViewModel; +using Newtonsoft.Json; namespace ApartmentManager.Handler { @@ -22,14 +24,17 @@ namespace ApartmentManager.Handler { Resident resident = new Resident(); resident.ApartmentNr = ApartmentViewModel.ApartmentNumber; + + var residentsFromDatabase = ApiClient.GetData("api/ApartmentResidents/" + resident.ApartmentNr); + IEnumerable<Resident> residentlist = JsonConvert.DeserializeObject<IEnumerable<Resident>>(residentsFromDatabase); - var residentlist = new PersistenceFacade().GetApartmentResidents(resident); ApartmentViewModel.CatalogSingleton.Residents.Clear(); - + ApartmentViewModel.NewResident = new Resident(); foreach (var resident2 in residentlist) { ApartmentViewModel.CatalogSingleton.Residents.Add(resident2); } + } public void CreateResident() @@ -37,8 +42,7 @@ namespace ApartmentManager.Handler try { Resident resident = new Resident(); - resident.ResidentNr = ApartmentViewModel.CatalogSingleton.Residents.Count; - resident.ResidentNr++; + resident.ApartmentNr = ApartmentViewModel.ApartmentNumber; resident.FirstName = ApartmentViewModel.NewResident.FirstName; resident.LastName = ApartmentViewModel.NewResident.LastName; @@ -47,13 +51,14 @@ namespace ApartmentManager.Handler resident.Picture = ApartmentViewModel.NewResident.Picture; resident.Phone = ApartmentViewModel.NewResident.Phone; - new PersistenceFacade().CreateResident(resident); + ApiClient.PostData("api/residents/", resident); - - var residentsFromDatabase = new PersistenceFacade().GetApartmentResidents(resident); - ApartmentViewModel.CatalogSingleton.Residents.Clear(); + var residentsFromDatabase = ApiClient.GetData("api/ApartmentResidents/" + resident.ApartmentNr); + IEnumerable<Resident> residentlist = JsonConvert.DeserializeObject<IEnumerable<Resident>>(residentsFromDatabase); - foreach (var resident2 in residentsFromDatabase) + ApartmentViewModel.CatalogSingleton.Residents.Clear(); + ApartmentViewModel.NewResident = new Resident(); + foreach (var resident2 in residentlist) { ApartmentViewModel.CatalogSingleton.Residents.Add(resident2); } @@ -69,6 +74,7 @@ namespace ApartmentManager.Handler try { Resident resident = new Resident(); + resident.ResidentNr = ApartmentViewModel.NewResident.ResidentNr; resident.ApartmentNr = ApartmentViewModel.ApartmentNumber; resident.FirstName = ApartmentViewModel.NewResident.FirstName; resident.LastName = ApartmentViewModel.NewResident.LastName; @@ -77,17 +83,17 @@ namespace ApartmentManager.Handler resident.Picture = ApartmentViewModel.NewResident.Picture; resident.Phone = ApartmentViewModel.NewResident.Phone; - //new PersistenceFacade().CreateHotel(hotel); + ApiClient.DeleteData("api/residents/" + resident.ResidentNr); - ////HotelViewModel.Hotels.Hotels.Add(hotel); - //var hotelsFromDatabase = new PersistenceFacade().GetHotels(); + var residentsFromDatabase = ApiClient.GetData("api/ApartmentResidents/" + resident.ApartmentNr); + IEnumerable<Resident> residentlist = JsonConvert.DeserializeObject<IEnumerable<Resident>>(residentsFromDatabase); - //HotelViewModel.HotelCatalogSingleton.Hotels.Clear(); - //foreach (var hotel1 in hotelsFromDatabase) - //{ - // ApartmentViewModel.HotelCatalogSingleton.Hotels.Add(hotel1); - - //} + ApartmentViewModel.CatalogSingleton.Residents.Clear(); + ApartmentViewModel.NewResident = new Resident(); + foreach (var resident2 in residentlist) + { + ApartmentViewModel.CatalogSingleton.Residents.Add(resident2); + } } catch (Exception e) { @@ -99,6 +105,7 @@ namespace ApartmentManager.Handler try { Resident resident = new Resident(); + resident.ResidentNr = ApartmentViewModel.NewResident.ResidentNr; resident.ApartmentNr = ApartmentViewModel.ApartmentNumber; resident.FirstName = ApartmentViewModel.NewResident.FirstName; resident.LastName = ApartmentViewModel.NewResident.LastName; @@ -107,17 +114,16 @@ namespace ApartmentManager.Handler resident.Picture = ApartmentViewModel.NewResident.Picture; resident.Phone = ApartmentViewModel.NewResident.Phone; - //new PersistenceFacade().CreateHotel(hotel); - - ////HotelViewModel.Hotels.Hotels.Add(hotel); - //var hotelsFromDatabase = new PersistenceFacade().GetHotels(); - - //HotelViewModel.HotelCatalogSingleton.Hotels.Clear(); - //foreach (var hotel1 in hotelsFromDatabase) - //{ - // ApartmentViewModel.HotelCatalogSingleton.Hotels.Add(hotel1); + ApiClient.PutData("api/residents/" + resident.ResidentNr,resident); + var residentsFromDatabase = ApiClient.GetData("api/ApartmentResidents/" + resident.ApartmentNr); + IEnumerable<Resident> residentlist = JsonConvert.DeserializeObject<IEnumerable<Resident>>(residentsFromDatabase); - //} + ApartmentViewModel.CatalogSingleton.Residents.Clear(); + ApartmentViewModel.NewResident = new Resident(); + foreach (var resident2 in residentlist) + { + ApartmentViewModel.CatalogSingleton.Residents.Add(resident2); + } } catch (Exception e) { diff --git a/ApartmentManager/ApartmentManager/Model/Resident.cs b/ApartmentManager/ApartmentManager/Model/Resident.cs index f9cede7..e9f39cd 100644 --- a/ApartmentManager/ApartmentManager/Model/Resident.cs +++ b/ApartmentManager/ApartmentManager/Model/Resident.cs @@ -19,7 +19,7 @@ namespace ApartmentManager.Model public int ResidentNr { get; set; } public Resident() { } - public Resident(string FirstName, 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.FirstName = FirstName; this.LastName = LastName; diff --git a/ApartmentManager/ApartmentManager/Persistency/ApiClient.cs b/ApartmentManager/ApartmentManager/Persistency/ApiClient.cs index e803005..2faa07a 100644 --- a/ApartmentManager/ApartmentManager/Persistency/ApiClient.cs +++ b/ApartmentManager/ApartmentManager/Persistency/ApiClient.cs @@ -24,6 +24,7 @@ namespace ApartmentManager.Persistency if (response.IsSuccessStatusCode) { return response.Content.ReadAsStringAsync().Result; + } else return null; } diff --git a/ApartmentManager/ApartmentManager/View/ResidentsPage.xaml b/ApartmentManager/ApartmentManager/View/ResidentsPage.xaml index 8c8d053..c68b1bc 100644 --- a/ApartmentManager/ApartmentManager/View/ResidentsPage.xaml +++ b/ApartmentManager/ApartmentManager/View/ResidentsPage.xaml @@ -29,7 +29,7 @@ <TextBox Text="{Binding NewResident.Phone, Mode=TwoWay}" /> <StackPanel Orientation="Horizontal"> <Button Margin="0,10,12,10" Content="Create" Width="125" Command="{Binding CreateResidentCommand}"/> - <Button Margin="0,10,0,10" Content="Delte" Width="125" Command="{Binding DeleteResidentCommand}"/> + <Button Margin="0,10,0,10" Content="Delete" Width="125" Command="{Binding DeleteResidentCommand}"/> <Button Margin="13,10,0,10" Content="Update" Width="125" Command="{Binding UpdateResidentCommand}"/> </StackPanel> </StackPanel> diff --git a/ApartmentManager/HousingWebApi/Controllers/ResidentsController.cs b/ApartmentManager/HousingWebApi/Controllers/ResidentsController.cs index e461b1a..f100211 100644 --- a/ApartmentManager/HousingWebApi/Controllers/ResidentsController.cs +++ b/ApartmentManager/HousingWebApi/Controllers/ResidentsController.cs @@ -22,9 +22,21 @@ namespace HousingWebApi.Controllers return db.Residents; } + // GET: api/Users/5 + [ResponseType(typeof(Resident))] + public IHttpActionResult GetResident(int id) + { + Resident resident = db.Residents.Find(id); + if (resident == null) + { + return NotFound(); + } + + return Ok(resident); + } // GET: api/Residents/1 - - [Route("api/Residents/{id}")] + + [Route("api/ApartmentResidents/{id}")] [ResponseType(typeof(ResidentList))] public IQueryable<ResidentList> GetResidents(int id) { diff --git a/ApartmentManager/HousingWebApi/DataModel.cs b/ApartmentManager/HousingWebApi/DataModel.cs index b4e7556..1f66066 100644 --- a/ApartmentManager/HousingWebApi/DataModel.cs +++ b/ApartmentManager/HousingWebApi/DataModel.cs @@ -71,51 +71,51 @@ namespace HousingWebApi modelBuilder.Entity<Resident>() .Property(e => e.FirstName) - .IsFixedLength(); + .IsUnicode(false); modelBuilder.Entity<Resident>() .Property(e => e.LastName) - .IsFixedLength(); + .IsUnicode(false); modelBuilder.Entity<Resident>() .Property(e => e.Email) - .IsFixedLength(); + .IsUnicode(false); modelBuilder.Entity<User>() .Property(e => e.Username) - .IsFixedLength(); + .IsUnicode(false); modelBuilder.Entity<User>() .Property(e => e.Password) - .IsFixedLength(); + .IsUnicode(false); modelBuilder.Entity<User>() .Property(e => e.FirstName) - .IsFixedLength(); + .IsUnicode(false); modelBuilder.Entity<User>() .Property(e => e.LastName) - .IsFixedLength(); + .IsUnicode(false); modelBuilder.Entity<User>() .Property(e => e.Phone) - .IsFixedLength(); + .IsUnicode(false); modelBuilder.Entity<User>() .Property(e => e.Email) - .IsFixedLength(); + .IsUnicode(false); modelBuilder.Entity<User>() .Property(e => e.SecondName) - .IsFixedLength(); + .IsUnicode(false); modelBuilder.Entity<User>() .Property(e => e.SecondLastName) - .IsFixedLength(); + .IsUnicode(false); modelBuilder.Entity<User>() .Property(e => e.SecondEmail) - .IsFixedLength(); + .IsUnicode(false); } } } 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 @@ </Reference> </ItemGroup> <ItemGroup> + <Compile Include="Models\Apartment.cs" /> <Compile Include="Controllers\ApartmentsController.cs" /> <Compile Include="Controllers\DefectsController.cs" /> <Compile Include="Controllers\PastContractOwnersController.cs" /> <Compile Include="Controllers\ResidentsController.cs" /> <Compile Include="Controllers\UsersController.cs" /> - <Compile Include="Models\Apartment.cs" /> <Compile Include="App_Start\BundleConfig.cs" /> <Compile Include="App_Start\FilterConfig.cs" /> <Compile Include="App_Start\RouteConfig.cs" /> @@ -198,8 +198,8 @@ <Compile Include="Models\PastContractOwner.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Models\Resident.cs" /> - <Compile Include="Models\User.cs" /> <Compile Include="ResidentList.cs" /> + <Compile Include="Models\User.cs" /> </ItemGroup> <ItemGroup> <Content Include="Areas\HelpPage\HelpPage.css" /> diff --git a/ApartmentManager/HousingWebApi/Models/Resident.cs b/ApartmentManager/HousingWebApi/Models/Resident.cs index 00fc439..a34cf80 100644 --- a/ApartmentManager/HousingWebApi/Models/Resident.cs +++ b/ApartmentManager/HousingWebApi/Models/Resident.cs @@ -9,13 +9,8 @@ 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/ApartmentManager/HousingWebApi/Web.config b/ApartmentManager/HousingWebApi/Web.config index 50e386b..8261278 100644 --- a/ApartmentManager/HousingWebApi/Web.config +++ b/ApartmentManager/HousingWebApi/Web.config @@ -20,7 +20,7 @@ <httpModules> <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" /> </httpModules> - <customErrors mode="Off"/> + <customErrors mode="Off" /> </system.web> <system.webServer> <handlers> @@ -79,7 +79,5 @@ <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> </providers> </entityFramework> - <connectionStrings> - - <add name="DataModel" connectionString="data source=housingdb.database.windows.net;initial catalog=housingdb;persist security info=True;user id=deltaadmin;password=Delta123!;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" /></connectionStrings> -</configuration>
\ No newline at end of file + +<connectionStrings><add name="DataModel" connectionString="data source=housingdb.database.windows.net;initial catalog=housingdb;persist security info=True;user id=deltaadmin;password=Delta123!;multipleactiveresultsets=True;application name=EntityFramework" providerName="System.Data.SqlClient" /></connectionStrings></configuration>
\ No newline at end of file |