aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonatas Adamonis <dona0169@edu.easj.dk>2017-05-10 17:32:55 +0200
committerDonatas Adamonis <dona0169@edu.easj.dk>2017-05-10 17:32:55 +0200
commit3a34870caabcc05f7d07ad5d93b30d15169132ac (patch)
tree1c53fdf33d34d11a72f5ff48ea196dcf0cd4c0f3
parent32c56dd96469fcded2362daec6184126306127aa (diff)
final version of apartment resident page
-rw-r--r--ApartmentManager/ApartmentManager/Model/Resident.cs16
-rw-r--r--ApartmentManager/ApartmentManager/View/ApartmentResidentsPage.xaml6
-rw-r--r--ApartmentManager/HousingWebAPI/ApartmentResident.cs37
-rw-r--r--ApartmentManager/HousingWebAPI/Controllers/ApartmentResidentsController.cs133
-rw-r--r--ApartmentManager/HousingWebAPI/Models/ApartmentResident.cs2
-rw-r--r--ApartmentManager/HousingWebAPI/Models/ListApartmentResidents.cs42
-rw-r--r--ApartmentManager/HousingWebAPI/Models/database_firewall_rules.cs2
-rw-r--r--ApartmentManager/HousingWebAPI/ViewContext.cs41
-rw-r--r--ApartmentManager/HousingWebAPI/database_firewall_rules.cs38
-rw-r--r--ApartmentManager/HousingWebApi/DataModel.cs27
-rw-r--r--ApartmentManager/HousingWebApi/HousingWebAPI.csproj12
-rw-r--r--ApartmentManager/HousingWebApi/Models/AllResident.cs15
-rw-r--r--ApartmentManager/HousingWebApi/Web.config9
13 files changed, 65 insertions, 315 deletions
diff --git a/ApartmentManager/ApartmentManager/Model/Resident.cs b/ApartmentManager/ApartmentManager/Model/Resident.cs
index e5ee2fb..79bf6a1 100644
--- a/ApartmentManager/ApartmentManager/Model/Resident.cs
+++ b/ApartmentManager/ApartmentManager/Model/Resident.cs
@@ -17,8 +17,12 @@ namespace ApartmentManager.Model
public string Picture { get; set; }
public int ApartmentNr { get; set; }
public int ResidentNr { get; set; }
-
- public Resident() { }
+
+ public Resident()
+ {
+ Picture = "https://tracker.moodle.org/secure/attachment/30912/f3.png";
+ BirthDate = DateTimeOffset.Now;
+ }
public Resident(string firstName, string lastName, int phone, DateTimeOffset birthDate, string email, int apartmentNr ,int residentNr, string picture)
{
FirstName = firstName;
@@ -30,9 +34,9 @@ namespace ApartmentManager.Model
ResidentNr = residentNr;
Picture = picture;
}
- //public override string ToString()
- //{
- // return string.Format($"Name: {FirstName}, LastName: {LastName}, Birth Date: {BirthDate.Date}, Phone {Phone}, Email {Email} ");
- //}
+ public override string ToString()
+ {
+ return string.Format($"Name: {FirstName}, LastName: {LastName}, Birth Date: {BirthDate.Date}, Phone {Phone}, Email {Email} ");
+ }
}
}
diff --git a/ApartmentManager/ApartmentManager/View/ApartmentResidentsPage.xaml b/ApartmentManager/ApartmentManager/View/ApartmentResidentsPage.xaml
index 0214ba7..5928b69 100644
--- a/ApartmentManager/ApartmentManager/View/ApartmentResidentsPage.xaml
+++ b/ApartmentManager/ApartmentManager/View/ApartmentResidentsPage.xaml
@@ -60,7 +60,11 @@
<StackPanel Orientation="Horizontal">
<TextBlock Text="Birth Date :" Margin="0,0,10,0" FontSize="20" FontWeight="Bold"></TextBlock>
- <TextBlock Text="{Binding BirthDate}" Margin="0,0,10,0" FontSize="20"></TextBlock>
+ <TextBlock Text="{Binding BirthDate.Year}" FontSize="20"></TextBlock>
+ <TextBlock Text="-" FontSize="20"></TextBlock>
+ <TextBlock Text="{Binding BirthDate.Month}" FontSize="20"></TextBlock>
+ <TextBlock Text="-" FontSize="20"></TextBlock>
+ <TextBlock Text="{Binding BirthDate.Day}" FontSize="20"></TextBlock>
</StackPanel>
</StackPanel>
diff --git a/ApartmentManager/HousingWebAPI/ApartmentResident.cs b/ApartmentManager/HousingWebAPI/ApartmentResident.cs
deleted file mode 100644
index 092c95f..0000000
--- a/ApartmentManager/HousingWebAPI/ApartmentResident.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-namespace HousingWebApi
-{
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.ComponentModel.DataAnnotations.Schema;
- using System.Data.Entity.Spatial;
-
- public partial class ApartmentResident
- {
- [Key]
- [Column(Order = 0)]
- [DatabaseGenerated(DatabaseGeneratedOption.None)]
- public int ApartmentNumber { get; set; }
-
- [Key]
- [Column(Order = 1)]
- [StringLength(20)]
- public string FirstName { get; set; }
-
- [Key]
- [Column(Order = 2)]
- [StringLength(20)]
- public string LastName { get; set; }
-
- [Column(TypeName = "date")]
- public DateTime? BirthDate { get; set; }
-
- public int? PhoneNo { get; set; }
-
- [StringLength(30)]
- public string Email { get; set; }
-
- [Column(TypeName = "image")]
- public byte[] Picture { get; set; }
- }
-}
diff --git a/ApartmentManager/HousingWebAPI/Controllers/ApartmentResidentsController.cs b/ApartmentManager/HousingWebAPI/Controllers/ApartmentResidentsController.cs
deleted file mode 100644
index 4b5c82a..0000000
--- a/ApartmentManager/HousingWebAPI/Controllers/ApartmentResidentsController.cs
+++ /dev/null
@@ -1,133 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Data;
-using System.Data.Entity;
-using System.Data.Entity.Infrastructure;
-using System.Linq;
-using System.Net;
-using System.Net.Http;
-using System.Web.Http;
-using System.Web.Http.Description;
-using HousingWebApi;
-
-namespace HousingWebApi.Controllers
-{
- public class ApartmentResidentsController : ApiController
- {
- private ViewContext db = new ViewContext();
-
- // GET: api/ApartmentResidents
- public IQueryable<ApartmentResident> GetApartmentResidents()
- {
- return db.ApartmentResidents;
- }
-
- // GET: api/ApartmentResidents/5
- [ResponseType(typeof(ApartmentResident))]
- public IHttpActionResult GetApartmentResident(int id)
- {
- ApartmentResident apartmentResident = db.ApartmentResidents.Find(id);
- if (apartmentResident == null)
- {
- return NotFound();
- }
-
- return Ok(apartmentResident);
- }
-
- // PUT: api/ApartmentResidents/5
- [ResponseType(typeof(void))]
- public IHttpActionResult PutApartmentResident(int id, ApartmentResident apartmentResident)
- {
- if (!ModelState.IsValid)
- {
- return BadRequest(ModelState);
- }
-
- if (id != apartmentResident.ApartmentNumber)
- {
- return BadRequest();
- }
-
- db.Entry(apartmentResident).State = EntityState.Modified;
-
- try
- {
- db.SaveChanges();
- }
- catch (DbUpdateConcurrencyException)
- {
- if (!ApartmentResidentExists(id))
- {
- return NotFound();
- }
- else
- {
- throw;
- }
- }
-
- return StatusCode(HttpStatusCode.NoContent);
- }
-
- // POST: api/ApartmentResidents
- [ResponseType(typeof(ApartmentResident))]
- public IHttpActionResult PostApartmentResident(ApartmentResident apartmentResident)
- {
- if (!ModelState.IsValid)
- {
- return BadRequest(ModelState);
- }
-
- db.ApartmentResidents.Add(apartmentResident);
-
- try
- {
- db.SaveChanges();
- }
- catch (DbUpdateException)
- {
- if (ApartmentResidentExists(apartmentResident.ApartmentNumber))
- {
- return Conflict();
- }
- else
- {
- throw;
- }
- }
-
- return CreatedAtRoute("DefaultApi", new { id = apartmentResident.ApartmentNumber }, apartmentResident);
- }
-
- // DELETE: api/ApartmentResidents/5
- [ResponseType(typeof(ApartmentResident))]
- public IHttpActionResult DeleteApartmentResident(int id)
- {
- ApartmentResident apartmentResident = db.ApartmentResidents.Find(id);
- if (apartmentResident == null)
- {
- return NotFound();
- }
-
- db.ApartmentResidents.Remove(apartmentResident);
- db.SaveChanges();
-
- return Ok(apartmentResident);
- }
-
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- db.Dispose();
- }
- base.Dispose(disposing);
- }
-
- private bool ApartmentResidentExists(int id)
- {
- return db.ApartmentResidents.Count(e => e.ApartmentNumber == id) > 0;
- }
- }
-} \ No newline at end of file
diff --git a/ApartmentManager/HousingWebAPI/Models/ApartmentResident.cs b/ApartmentManager/HousingWebAPI/Models/ApartmentResident.cs
index f54e72b..092c95f 100644
--- a/ApartmentManager/HousingWebAPI/Models/ApartmentResident.cs
+++ b/ApartmentManager/HousingWebAPI/Models/ApartmentResident.cs
@@ -1,4 +1,4 @@
-namespace HousingWebApi.Models
+namespace HousingWebApi
{
using System;
using System.Collections.Generic;
diff --git a/ApartmentManager/HousingWebAPI/Models/ListApartmentResidents.cs b/ApartmentManager/HousingWebAPI/Models/ListApartmentResidents.cs
deleted file mode 100644
index 5d5bffd..0000000
--- a/ApartmentManager/HousingWebAPI/Models/ListApartmentResidents.cs
+++ /dev/null
@@ -1,42 +0,0 @@
-namespace HousingWebApi.Models
-{
- using System;
- using System.Data.Entity;
- using System.ComponentModel.DataAnnotations.Schema;
- using System.Linq;
-
- public partial class ListApartmentResidents : DbContext
- {
- public ListApartmentResidents()
- : base("name=ListApartmentResidents")
- {
- base.Configuration.ProxyCreationEnabled = false;
- }
-
- public virtual DbSet<ApartmentResident> ApartmentResidents { get; set; }
- public virtual DbSet<database_firewall_rules> database_firewall_rules { get; set; }
-
- protected override void OnModelCreating(DbModelBuilder modelBuilder)
- {
- modelBuilder.Entity<ApartmentResident>()
- .Property(e => e.FirstName)
- .IsUnicode(false);
-
- modelBuilder.Entity<ApartmentResident>()
- .Property(e => e.LastName)
- .IsUnicode(false);
-
- modelBuilder.Entity<ApartmentResident>()
- .Property(e => e.Email)
- .IsUnicode(false);
-
- modelBuilder.Entity<database_firewall_rules>()
- .Property(e => e.start_ip_address)
- .IsUnicode(false);
-
- modelBuilder.Entity<database_firewall_rules>()
- .Property(e => e.end_ip_address)
- .IsUnicode(false);
- }
- }
-}
diff --git a/ApartmentManager/HousingWebAPI/Models/database_firewall_rules.cs b/ApartmentManager/HousingWebAPI/Models/database_firewall_rules.cs
index 4ea6055..3b5d6a5 100644
--- a/ApartmentManager/HousingWebAPI/Models/database_firewall_rules.cs
+++ b/ApartmentManager/HousingWebAPI/Models/database_firewall_rules.cs
@@ -1,4 +1,4 @@
-namespace HousingWebApi.Models
+namespace HousingWebApi
{
using System;
using System.Collections.Generic;
diff --git a/ApartmentManager/HousingWebAPI/ViewContext.cs b/ApartmentManager/HousingWebAPI/ViewContext.cs
deleted file mode 100644
index 9b50fc3..0000000
--- a/ApartmentManager/HousingWebAPI/ViewContext.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-namespace HousingWebApi
-{
- using System;
- using System.Data.Entity;
- using System.ComponentModel.DataAnnotations.Schema;
- using System.Linq;
-
- public partial class ViewContext : DbContext
- {
- public ViewContext()
- : base("name=ViewContext")
- {
- }
-
- public virtual DbSet<ApartmentResident> ApartmentResidents { get; set; }
- public virtual DbSet<database_firewall_rules> database_firewall_rules { get; set; }
-
- protected override void OnModelCreating(DbModelBuilder modelBuilder)
- {
- modelBuilder.Entity<ApartmentResident>()
- .Property(e => e.FirstName)
- .IsUnicode(false);
-
- modelBuilder.Entity<ApartmentResident>()
- .Property(e => e.LastName)
- .IsUnicode(false);
-
- modelBuilder.Entity<ApartmentResident>()
- .Property(e => e.Email)
- .IsUnicode(false);
-
- modelBuilder.Entity<database_firewall_rules>()
- .Property(e => e.start_ip_address)
- .IsUnicode(false);
-
- modelBuilder.Entity<database_firewall_rules>()
- .Property(e => e.end_ip_address)
- .IsUnicode(false);
- }
- }
-}
diff --git a/ApartmentManager/HousingWebAPI/database_firewall_rules.cs b/ApartmentManager/HousingWebAPI/database_firewall_rules.cs
deleted file mode 100644
index 3b5d6a5..0000000
--- a/ApartmentManager/HousingWebAPI/database_firewall_rules.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-namespace HousingWebApi
-{
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.ComponentModel.DataAnnotations.Schema;
- using System.Data.Entity.Spatial;
-
- [Table("sys.database_firewall_rules")]
- public partial class database_firewall_rules
- {
- [Key]
- [Column(Order = 0)]
- public int id { get; set; }
-
- [Key]
- [Column(Order = 1)]
- public string name { get; set; }
-
- [Key]
- [Column(Order = 2)]
- [StringLength(45)]
- public string start_ip_address { get; set; }
-
- [Key]
- [Column(Order = 3)]
- [StringLength(45)]
- public string end_ip_address { get; set; }
-
- [Key]
- [Column(Order = 4)]
- public DateTime create_date { get; set; }
-
- [Key]
- [Column(Order = 5)]
- public DateTime modify_date { get; set; }
- }
-}
diff --git a/ApartmentManager/HousingWebApi/DataModel.cs b/ApartmentManager/HousingWebApi/DataModel.cs
index a07e1fc..fa16d44 100644
--- a/ApartmentManager/HousingWebApi/DataModel.cs
+++ b/ApartmentManager/HousingWebApi/DataModel.cs
@@ -18,6 +18,9 @@ namespace HousingWebApi
public virtual DbSet<PastContractOwner> PastContractOwners { get; set; }
public virtual DbSet<Resident> Residents { get; set; }
public virtual DbSet<User> Users { get; set; }
+ public virtual DbSet<AllResident> AllResidents { get; set; }
+ public virtual DbSet<ApartmentResident> ApartmentResidents { get; set; }
+ public virtual DbSet<database_firewall_rules> database_firewall_rules { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
@@ -144,6 +147,30 @@ namespace HousingWebApi
modelBuilder.Entity<User>()
.Property(e => e.SecondEmail)
.IsUnicode(false);
+
+ modelBuilder.Entity<AllResident>()
+ .Property(e => e.FirstName)
+ .IsUnicode(false);
+
+ modelBuilder.Entity<ApartmentResident>()
+ .Property(e => e.FirstName)
+ .IsUnicode(false);
+
+ modelBuilder.Entity<ApartmentResident>()
+ .Property(e => e.LastName)
+ .IsUnicode(false);
+
+ modelBuilder.Entity<ApartmentResident>()
+ .Property(e => e.Email)
+ .IsUnicode(false);
+
+ modelBuilder.Entity<database_firewall_rules>()
+ .Property(e => e.start_ip_address)
+ .IsUnicode(false);
+
+ modelBuilder.Entity<database_firewall_rules>()
+ .Property(e => e.end_ip_address)
+ .IsUnicode(false);
}
}
}
diff --git a/ApartmentManager/HousingWebApi/HousingWebAPI.csproj b/ApartmentManager/HousingWebApi/HousingWebAPI.csproj
index da913ec..3c002fd 100644
--- a/ApartmentManager/HousingWebApi/HousingWebAPI.csproj
+++ b/ApartmentManager/HousingWebApi/HousingWebAPI.csproj
@@ -151,10 +151,9 @@
</Reference>
</ItemGroup>
<ItemGroup>
- <Compile Include="ApartmentResident.cs" />
- <Compile Include="Controllers\ApartmentResidentsController.cs" />
- <Compile Include="database_firewall_rules.cs" />
+ <Compile Include="Models\AllResident.cs" />
<Compile Include="Models\Apartment.cs" />
+ <Compile Include="Models\ApartmentResident.cs" />
<Compile Include="Controllers\ApartmentsController.cs" />
<Compile Include="Controllers\DefectsController.cs" />
<Compile Include="Controllers\PastContractOwnersController.cs" />
@@ -193,20 +192,17 @@
<Compile Include="Areas\HelpPage\SampleGeneration\TextSample.cs" />
<Compile Include="Areas\HelpPage\XmlDocumentationProvider.cs" />
<Compile Include="Controllers\HomeController.cs" />
- <Compile Include="DataModel.cs" />
- <Compile Include="Models\ApartmentResident.cs" />
<Compile Include="Models\database_firewall_rules.cs" />
+ <Compile Include="DataModel.cs" />
<Compile Include="Models\Defect.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
- <Compile Include="Models\ListApartmentResidents.cs" />
<Compile Include="Models\PastContractOwner.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="Models\Resident.cs" />
<Compile Include="Models\ResidentList.cs" />
+ <Compile Include="Models\Resident.cs" />
<Compile Include="Models\User.cs" />
- <Compile Include="ViewContext.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Areas\HelpPage\HelpPage.css" />
diff --git a/ApartmentManager/HousingWebApi/Models/AllResident.cs b/ApartmentManager/HousingWebApi/Models/AllResident.cs
new file mode 100644
index 0000000..655ee84
--- /dev/null
+++ b/ApartmentManager/HousingWebApi/Models/AllResident.cs
@@ -0,0 +1,15 @@
+namespace HousingWebApi
+{
+ using System;
+ using System.Collections.Generic;
+ using System.ComponentModel.DataAnnotations;
+ using System.ComponentModel.DataAnnotations.Schema;
+ using System.Data.Entity.Spatial;
+
+ public partial class AllResident
+ {
+ [Key]
+ [StringLength(20)]
+ public string FirstName { get; set; }
+ }
+}
diff --git a/ApartmentManager/HousingWebApi/Web.config b/ApartmentManager/HousingWebApi/Web.config
index cab739c..8261278 100644
--- a/ApartmentManager/HousingWebApi/Web.config
+++ b/ApartmentManager/HousingWebApi/Web.config
@@ -79,10 +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;application name=EntityFramework" providerName="System.Data.SqlClient" />
- <add name="ApartmentResidents" 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" />
- <add name="ViewContext" 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" />
- <add name="ListApartmentResidents" 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
+
+<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