From cb5917247c407e207e649641d829c5b5563a84c1 Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Thu, 18 May 2017 07:31:30 +0200 Subject: Remade data model and controllers to match the new database design. --- .../Controllers/AllResidentsController.cs | 133 +++++++++++++++++++++ .../Controllers/ApartmentChangesController.cs | 133 +++++++++++++++++++++ .../Controllers/ApartmentResidentsController.cs | 133 +++++++++++++++++++++ .../Controllers/ApartmentsController.cs | 8 +- .../Controllers/ChangeCommentsController.cs | 133 +++++++++++++++++++++ .../Controllers/ChangeDocumentsController.cs | 133 +++++++++++++++++++++ .../Controllers/DefectCommentsController.cs | 133 +++++++++++++++++++++ .../Controllers/DefectPicturesController.cs | 133 +++++++++++++++++++++ .../HousingWebApi/Controllers/DefectsController.cs | 8 +- .../Controllers/PastContractOwnersController.cs | 133 --------------------- .../Controllers/PastUsersController.cs | 133 +++++++++++++++++++++ .../Controllers/ResidentsController.cs | 31 +---- .../HousingWebApi/Controllers/UsersController.cs | 37 +++--- ApartmentManager/HousingWebApi/DataModel.cs | 131 +++++++++++--------- .../HousingWebApi/HousingWebApi.csproj | 26 ++-- ApartmentManager/HousingWebApi/Models/Apartment.cs | 28 +++-- .../HousingWebApi/Models/ApartmentChange.cs | 44 +++++++ .../HousingWebApi/Models/ChangeComment.cs | 22 ++++ .../HousingWebApi/Models/ChangeDocument.cs | 22 ++++ ApartmentManager/HousingWebApi/Models/Defect.cs | 39 +++--- .../HousingWebApi/Models/DefectComment.cs | 22 ++++ .../HousingWebApi/Models/DefectPicture.cs | 22 ++++ .../HousingWebApi/Models/PastContractOwner.cs | 17 --- ApartmentManager/HousingWebApi/Models/PastUser.cs | 49 ++++++++ ApartmentManager/HousingWebApi/Models/Resident.cs | 21 ++-- .../HousingWebApi/Models/ResidentList.cs | 20 ---- ApartmentManager/HousingWebApi/Models/User.cs | 41 ++----- .../Models/database_firewall_rules.cs | 38 ------ ApartmentManager/HousingWebApi/Web.config | 5 +- 29 files changed, 1426 insertions(+), 402 deletions(-) create mode 100644 ApartmentManager/HousingWebApi/Controllers/AllResidentsController.cs create mode 100644 ApartmentManager/HousingWebApi/Controllers/ApartmentChangesController.cs create mode 100644 ApartmentManager/HousingWebApi/Controllers/ApartmentResidentsController.cs create mode 100644 ApartmentManager/HousingWebApi/Controllers/ChangeCommentsController.cs create mode 100644 ApartmentManager/HousingWebApi/Controllers/ChangeDocumentsController.cs create mode 100644 ApartmentManager/HousingWebApi/Controllers/DefectCommentsController.cs create mode 100644 ApartmentManager/HousingWebApi/Controllers/DefectPicturesController.cs delete mode 100644 ApartmentManager/HousingWebApi/Controllers/PastContractOwnersController.cs create mode 100644 ApartmentManager/HousingWebApi/Controllers/PastUsersController.cs create mode 100644 ApartmentManager/HousingWebApi/Models/ApartmentChange.cs create mode 100644 ApartmentManager/HousingWebApi/Models/ChangeComment.cs create mode 100644 ApartmentManager/HousingWebApi/Models/ChangeDocument.cs create mode 100644 ApartmentManager/HousingWebApi/Models/DefectComment.cs create mode 100644 ApartmentManager/HousingWebApi/Models/DefectPicture.cs delete mode 100644 ApartmentManager/HousingWebApi/Models/PastContractOwner.cs create mode 100644 ApartmentManager/HousingWebApi/Models/PastUser.cs delete mode 100644 ApartmentManager/HousingWebApi/Models/ResidentList.cs delete mode 100644 ApartmentManager/HousingWebApi/Models/database_firewall_rules.cs diff --git a/ApartmentManager/HousingWebApi/Controllers/AllResidentsController.cs b/ApartmentManager/HousingWebApi/Controllers/AllResidentsController.cs new file mode 100644 index 0000000..046a385 --- /dev/null +++ b/ApartmentManager/HousingWebApi/Controllers/AllResidentsController.cs @@ -0,0 +1,133 @@ +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 AllResidentsController : ApiController + { + private DataModel db = new DataModel(); + + // GET: api/AllResidents + public IQueryable GetAllResidents() + { + return db.AllResidents; + } + + // GET: api/AllResidents/5 + [ResponseType(typeof(AllResident))] + public IHttpActionResult GetAllResident(string id) + { + AllResident allResident = db.AllResidents.Find(id); + if (allResident == null) + { + return NotFound(); + } + + return Ok(allResident); + } + + // PUT: api/AllResidents/5 + [ResponseType(typeof(void))] + public IHttpActionResult PutAllResident(string id, AllResident allResident) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + if (id != allResident.FirstName) + { + return BadRequest(); + } + + db.Entry(allResident).State = EntityState.Modified; + + try + { + db.SaveChanges(); + } + catch (DbUpdateConcurrencyException) + { + if (!AllResidentExists(id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return StatusCode(HttpStatusCode.NoContent); + } + + // POST: api/AllResidents + [ResponseType(typeof(AllResident))] + public IHttpActionResult PostAllResident(AllResident allResident) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + db.AllResidents.Add(allResident); + + try + { + db.SaveChanges(); + } + catch (DbUpdateException) + { + if (AllResidentExists(allResident.FirstName)) + { + return Conflict(); + } + else + { + throw; + } + } + + return CreatedAtRoute("DefaultApi", new { id = allResident.FirstName }, allResident); + } + + // DELETE: api/AllResidents/5 + [ResponseType(typeof(AllResident))] + public IHttpActionResult DeleteAllResident(string id) + { + AllResident allResident = db.AllResidents.Find(id); + if (allResident == null) + { + return NotFound(); + } + + db.AllResidents.Remove(allResident); + db.SaveChanges(); + + return Ok(allResident); + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + db.Dispose(); + } + base.Dispose(disposing); + } + + private bool AllResidentExists(string id) + { + return db.AllResidents.Count(e => e.FirstName == id) > 0; + } + } +} \ No newline at end of file diff --git a/ApartmentManager/HousingWebApi/Controllers/ApartmentChangesController.cs b/ApartmentManager/HousingWebApi/Controllers/ApartmentChangesController.cs new file mode 100644 index 0000000..f96385a --- /dev/null +++ b/ApartmentManager/HousingWebApi/Controllers/ApartmentChangesController.cs @@ -0,0 +1,133 @@ +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 ApartmentChangesController : ApiController + { + private DataModel db = new DataModel(); + + // GET: api/ApartmentChanges + public IQueryable GetApartmentChanges() + { + return db.ApartmentChanges; + } + + // GET: api/ApartmentChanges/5 + [ResponseType(typeof(ApartmentChange))] + public IHttpActionResult GetApartmentChange(int id) + { + ApartmentChange apartmentChange = db.ApartmentChanges.Find(id); + if (apartmentChange == null) + { + return NotFound(); + } + + return Ok(apartmentChange); + } + + // PUT: api/ApartmentChanges/5 + [ResponseType(typeof(void))] + public IHttpActionResult PutApartmentChange(int id, ApartmentChange apartmentChange) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + if (id != apartmentChange.ChangeId) + { + return BadRequest(); + } + + db.Entry(apartmentChange).State = EntityState.Modified; + + try + { + db.SaveChanges(); + } + catch (DbUpdateConcurrencyException) + { + if (!ApartmentChangeExists(id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return StatusCode(HttpStatusCode.NoContent); + } + + // POST: api/ApartmentChanges + [ResponseType(typeof(ApartmentChange))] + public IHttpActionResult PostApartmentChange(ApartmentChange apartmentChange) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + db.ApartmentChanges.Add(apartmentChange); + + try + { + db.SaveChanges(); + } + catch (DbUpdateException) + { + if (ApartmentChangeExists(apartmentChange.ChangeId)) + { + return Conflict(); + } + else + { + throw; + } + } + + return CreatedAtRoute("DefaultApi", new { id = apartmentChange.ChangeId }, apartmentChange); + } + + // DELETE: api/ApartmentChanges/5 + [ResponseType(typeof(ApartmentChange))] + public IHttpActionResult DeleteApartmentChange(int id) + { + ApartmentChange apartmentChange = db.ApartmentChanges.Find(id); + if (apartmentChange == null) + { + return NotFound(); + } + + db.ApartmentChanges.Remove(apartmentChange); + db.SaveChanges(); + + return Ok(apartmentChange); + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + db.Dispose(); + } + base.Dispose(disposing); + } + + private bool ApartmentChangeExists(int id) + { + return db.ApartmentChanges.Count(e => e.ChangeId == id) > 0; + } + } +} \ No newline at end of file diff --git a/ApartmentManager/HousingWebApi/Controllers/ApartmentResidentsController.cs b/ApartmentManager/HousingWebApi/Controllers/ApartmentResidentsController.cs new file mode 100644 index 0000000..a754255 --- /dev/null +++ b/ApartmentManager/HousingWebApi/Controllers/ApartmentResidentsController.cs @@ -0,0 +1,133 @@ +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 DataModel db = new DataModel(); + + // GET: api/ApartmentResidents + public IQueryable 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/Controllers/ApartmentsController.cs b/ApartmentManager/HousingWebApi/Controllers/ApartmentsController.cs index a3de905..90af553 100644 --- a/ApartmentManager/HousingWebApi/Controllers/ApartmentsController.cs +++ b/ApartmentManager/HousingWebApi/Controllers/ApartmentsController.cs @@ -44,7 +44,7 @@ namespace HousingWebApi.Controllers return BadRequest(ModelState); } - if (id != apartment.ApartmentNumber) + if (id != apartment.ApartmentId) { return BadRequest(); } @@ -87,7 +87,7 @@ namespace HousingWebApi.Controllers } catch (DbUpdateException) { - if (ApartmentExists(apartment.ApartmentNumber)) + if (ApartmentExists(apartment.ApartmentId)) { return Conflict(); } @@ -97,7 +97,7 @@ namespace HousingWebApi.Controllers } } - return CreatedAtRoute("DefaultApi", new { id = apartment.ApartmentNumber }, apartment); + return CreatedAtRoute("DefaultApi", new { id = apartment.ApartmentId }, apartment); } // DELETE: api/Apartments/5 @@ -127,7 +127,7 @@ namespace HousingWebApi.Controllers private bool ApartmentExists(int id) { - return db.Apartments.Count(e => e.ApartmentNumber == id) > 0; + return db.Apartments.Count(e => e.ApartmentId == id) > 0; } } } \ No newline at end of file diff --git a/ApartmentManager/HousingWebApi/Controllers/ChangeCommentsController.cs b/ApartmentManager/HousingWebApi/Controllers/ChangeCommentsController.cs new file mode 100644 index 0000000..bebff8e --- /dev/null +++ b/ApartmentManager/HousingWebApi/Controllers/ChangeCommentsController.cs @@ -0,0 +1,133 @@ +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 ChangeCommentsController : ApiController + { + private DataModel db = new DataModel(); + + // GET: api/ChangeComments + public IQueryable GetChangeComments() + { + return db.ChangeComments; + } + + // GET: api/ChangeComments/5 + [ResponseType(typeof(ChangeComment))] + public IHttpActionResult GetChangeComment(int id) + { + ChangeComment changeComment = db.ChangeComments.Find(id); + if (changeComment == null) + { + return NotFound(); + } + + return Ok(changeComment); + } + + // PUT: api/ChangeComments/5 + [ResponseType(typeof(void))] + public IHttpActionResult PutChangeComment(int id, ChangeComment changeComment) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + if (id != changeComment.CommentId) + { + return BadRequest(); + } + + db.Entry(changeComment).State = EntityState.Modified; + + try + { + db.SaveChanges(); + } + catch (DbUpdateConcurrencyException) + { + if (!ChangeCommentExists(id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return StatusCode(HttpStatusCode.NoContent); + } + + // POST: api/ChangeComments + [ResponseType(typeof(ChangeComment))] + public IHttpActionResult PostChangeComment(ChangeComment changeComment) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + db.ChangeComments.Add(changeComment); + + try + { + db.SaveChanges(); + } + catch (DbUpdateException) + { + if (ChangeCommentExists(changeComment.CommentId)) + { + return Conflict(); + } + else + { + throw; + } + } + + return CreatedAtRoute("DefaultApi", new { id = changeComment.CommentId }, changeComment); + } + + // DELETE: api/ChangeComments/5 + [ResponseType(typeof(ChangeComment))] + public IHttpActionResult DeleteChangeComment(int id) + { + ChangeComment changeComment = db.ChangeComments.Find(id); + if (changeComment == null) + { + return NotFound(); + } + + db.ChangeComments.Remove(changeComment); + db.SaveChanges(); + + return Ok(changeComment); + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + db.Dispose(); + } + base.Dispose(disposing); + } + + private bool ChangeCommentExists(int id) + { + return db.ChangeComments.Count(e => e.CommentId == id) > 0; + } + } +} \ No newline at end of file diff --git a/ApartmentManager/HousingWebApi/Controllers/ChangeDocumentsController.cs b/ApartmentManager/HousingWebApi/Controllers/ChangeDocumentsController.cs new file mode 100644 index 0000000..406ab33 --- /dev/null +++ b/ApartmentManager/HousingWebApi/Controllers/ChangeDocumentsController.cs @@ -0,0 +1,133 @@ +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 ChangeDocumentsController : ApiController + { + private DataModel db = new DataModel(); + + // GET: api/ChangeDocuments + public IQueryable GetChangeDocuments() + { + return db.ChangeDocuments; + } + + // GET: api/ChangeDocuments/5 + [ResponseType(typeof(ChangeDocument))] + public IHttpActionResult GetChangeDocument(int id) + { + ChangeDocument changeDocument = db.ChangeDocuments.Find(id); + if (changeDocument == null) + { + return NotFound(); + } + + return Ok(changeDocument); + } + + // PUT: api/ChangeDocuments/5 + [ResponseType(typeof(void))] + public IHttpActionResult PutChangeDocument(int id, ChangeDocument changeDocument) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + if (id != changeDocument.DocumentId) + { + return BadRequest(); + } + + db.Entry(changeDocument).State = EntityState.Modified; + + try + { + db.SaveChanges(); + } + catch (DbUpdateConcurrencyException) + { + if (!ChangeDocumentExists(id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return StatusCode(HttpStatusCode.NoContent); + } + + // POST: api/ChangeDocuments + [ResponseType(typeof(ChangeDocument))] + public IHttpActionResult PostChangeDocument(ChangeDocument changeDocument) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + db.ChangeDocuments.Add(changeDocument); + + try + { + db.SaveChanges(); + } + catch (DbUpdateException) + { + if (ChangeDocumentExists(changeDocument.DocumentId)) + { + return Conflict(); + } + else + { + throw; + } + } + + return CreatedAtRoute("DefaultApi", new { id = changeDocument.DocumentId }, changeDocument); + } + + // DELETE: api/ChangeDocuments/5 + [ResponseType(typeof(ChangeDocument))] + public IHttpActionResult DeleteChangeDocument(int id) + { + ChangeDocument changeDocument = db.ChangeDocuments.Find(id); + if (changeDocument == null) + { + return NotFound(); + } + + db.ChangeDocuments.Remove(changeDocument); + db.SaveChanges(); + + return Ok(changeDocument); + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + db.Dispose(); + } + base.Dispose(disposing); + } + + private bool ChangeDocumentExists(int id) + { + return db.ChangeDocuments.Count(e => e.DocumentId == id) > 0; + } + } +} \ No newline at end of file diff --git a/ApartmentManager/HousingWebApi/Controllers/DefectCommentsController.cs b/ApartmentManager/HousingWebApi/Controllers/DefectCommentsController.cs new file mode 100644 index 0000000..ae5222d --- /dev/null +++ b/ApartmentManager/HousingWebApi/Controllers/DefectCommentsController.cs @@ -0,0 +1,133 @@ +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 DefectCommentsController : ApiController + { + private DataModel db = new DataModel(); + + // GET: api/DefectComments + public IQueryable GetDefectComments() + { + return db.DefectComments; + } + + // GET: api/DefectComments/5 + [ResponseType(typeof(DefectComment))] + public IHttpActionResult GetDefectComment(int id) + { + DefectComment defectComment = db.DefectComments.Find(id); + if (defectComment == null) + { + return NotFound(); + } + + return Ok(defectComment); + } + + // PUT: api/DefectComments/5 + [ResponseType(typeof(void))] + public IHttpActionResult PutDefectComment(int id, DefectComment defectComment) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + if (id != defectComment.PictureId) + { + return BadRequest(); + } + + db.Entry(defectComment).State = EntityState.Modified; + + try + { + db.SaveChanges(); + } + catch (DbUpdateConcurrencyException) + { + if (!DefectCommentExists(id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return StatusCode(HttpStatusCode.NoContent); + } + + // POST: api/DefectComments + [ResponseType(typeof(DefectComment))] + public IHttpActionResult PostDefectComment(DefectComment defectComment) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + db.DefectComments.Add(defectComment); + + try + { + db.SaveChanges(); + } + catch (DbUpdateException) + { + if (DefectCommentExists(defectComment.PictureId)) + { + return Conflict(); + } + else + { + throw; + } + } + + return CreatedAtRoute("DefaultApi", new { id = defectComment.PictureId }, defectComment); + } + + // DELETE: api/DefectComments/5 + [ResponseType(typeof(DefectComment))] + public IHttpActionResult DeleteDefectComment(int id) + { + DefectComment defectComment = db.DefectComments.Find(id); + if (defectComment == null) + { + return NotFound(); + } + + db.DefectComments.Remove(defectComment); + db.SaveChanges(); + + return Ok(defectComment); + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + db.Dispose(); + } + base.Dispose(disposing); + } + + private bool DefectCommentExists(int id) + { + return db.DefectComments.Count(e => e.PictureId == id) > 0; + } + } +} \ No newline at end of file diff --git a/ApartmentManager/HousingWebApi/Controllers/DefectPicturesController.cs b/ApartmentManager/HousingWebApi/Controllers/DefectPicturesController.cs new file mode 100644 index 0000000..288a660 --- /dev/null +++ b/ApartmentManager/HousingWebApi/Controllers/DefectPicturesController.cs @@ -0,0 +1,133 @@ +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 DefectPicturesController : ApiController + { + private DataModel db = new DataModel(); + + // GET: api/DefectPictures + public IQueryable GetDefectPictures() + { + return db.DefectPictures; + } + + // GET: api/DefectPictures/5 + [ResponseType(typeof(DefectPicture))] + public IHttpActionResult GetDefectPicture(int id) + { + DefectPicture defectPicture = db.DefectPictures.Find(id); + if (defectPicture == null) + { + return NotFound(); + } + + return Ok(defectPicture); + } + + // PUT: api/DefectPictures/5 + [ResponseType(typeof(void))] + public IHttpActionResult PutDefectPicture(int id, DefectPicture defectPicture) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + if (id != defectPicture.PictureId) + { + return BadRequest(); + } + + db.Entry(defectPicture).State = EntityState.Modified; + + try + { + db.SaveChanges(); + } + catch (DbUpdateConcurrencyException) + { + if (!DefectPictureExists(id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return StatusCode(HttpStatusCode.NoContent); + } + + // POST: api/DefectPictures + [ResponseType(typeof(DefectPicture))] + public IHttpActionResult PostDefectPicture(DefectPicture defectPicture) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + db.DefectPictures.Add(defectPicture); + + try + { + db.SaveChanges(); + } + catch (DbUpdateException) + { + if (DefectPictureExists(defectPicture.PictureId)) + { + return Conflict(); + } + else + { + throw; + } + } + + return CreatedAtRoute("DefaultApi", new { id = defectPicture.PictureId }, defectPicture); + } + + // DELETE: api/DefectPictures/5 + [ResponseType(typeof(DefectPicture))] + public IHttpActionResult DeleteDefectPicture(int id) + { + DefectPicture defectPicture = db.DefectPictures.Find(id); + if (defectPicture == null) + { + return NotFound(); + } + + db.DefectPictures.Remove(defectPicture); + db.SaveChanges(); + + return Ok(defectPicture); + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + db.Dispose(); + } + base.Dispose(disposing); + } + + private bool DefectPictureExists(int id) + { + return db.DefectPictures.Count(e => e.PictureId == id) > 0; + } + } +} \ No newline at end of file diff --git a/ApartmentManager/HousingWebApi/Controllers/DefectsController.cs b/ApartmentManager/HousingWebApi/Controllers/DefectsController.cs index aa6f519..c5f2909 100644 --- a/ApartmentManager/HousingWebApi/Controllers/DefectsController.cs +++ b/ApartmentManager/HousingWebApi/Controllers/DefectsController.cs @@ -44,7 +44,7 @@ namespace HousingWebApi.Controllers return BadRequest(ModelState); } - if (id != defect.DefectNumber) + if (id != defect.DefectId) { return BadRequest(); } @@ -87,7 +87,7 @@ namespace HousingWebApi.Controllers } catch (DbUpdateException) { - if (DefectExists(defect.DefectNumber)) + if (DefectExists(defect.DefectId)) { return Conflict(); } @@ -97,7 +97,7 @@ namespace HousingWebApi.Controllers } } - return CreatedAtRoute("DefaultApi", new { id = defect.DefectNumber }, defect); + return CreatedAtRoute("DefaultApi", new { id = defect.DefectId }, defect); } // DELETE: api/Defects/5 @@ -127,7 +127,7 @@ namespace HousingWebApi.Controllers private bool DefectExists(int id) { - return db.Defects.Count(e => e.DefectNumber == id) > 0; + return db.Defects.Count(e => e.DefectId == id) > 0; } } } \ No newline at end of file diff --git a/ApartmentManager/HousingWebApi/Controllers/PastContractOwnersController.cs b/ApartmentManager/HousingWebApi/Controllers/PastContractOwnersController.cs deleted file mode 100644 index d1f3e00..0000000 --- a/ApartmentManager/HousingWebApi/Controllers/PastContractOwnersController.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 PastContractOwnersController : ApiController - { - private DataModel db = new DataModel(); - - // GET: api/PastContractOwners - public IQueryable GetPastContractOwners() - { - return db.PastContractOwners; - } - - // GET: api/PastContractOwners/5 - [ResponseType(typeof(PastContractOwner))] - public IHttpActionResult GetPastContractOwner(int id) - { - PastContractOwner pastContractOwner = db.PastContractOwners.Find(id); - if (pastContractOwner == null) - { - return NotFound(); - } - - return Ok(pastContractOwner); - } - - // PUT: api/PastContractOwners/5 - [ResponseType(typeof(void))] - public IHttpActionResult PutPastContractOwner(int id, PastContractOwner pastContractOwner) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - if (id != pastContractOwner.Id) - { - return BadRequest(); - } - - db.Entry(pastContractOwner).State = EntityState.Modified; - - try - { - db.SaveChanges(); - } - catch (DbUpdateConcurrencyException) - { - if (!PastContractOwnerExists(id)) - { - return NotFound(); - } - else - { - throw; - } - } - - return StatusCode(HttpStatusCode.NoContent); - } - - // POST: api/PastContractOwners - [ResponseType(typeof(PastContractOwner))] - public IHttpActionResult PostPastContractOwner(PastContractOwner pastContractOwner) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - db.PastContractOwners.Add(pastContractOwner); - - try - { - db.SaveChanges(); - } - catch (DbUpdateException) - { - if (PastContractOwnerExists(pastContractOwner.Id)) - { - return Conflict(); - } - else - { - throw; - } - } - - return CreatedAtRoute("DefaultApi", new { id = pastContractOwner.Id }, pastContractOwner); - } - - // DELETE: api/PastContractOwners/5 - [ResponseType(typeof(PastContractOwner))] - public IHttpActionResult DeletePastContractOwner(int id) - { - PastContractOwner pastContractOwner = db.PastContractOwners.Find(id); - if (pastContractOwner == null) - { - return NotFound(); - } - - db.PastContractOwners.Remove(pastContractOwner); - db.SaveChanges(); - - return Ok(pastContractOwner); - } - - protected override void Dispose(bool disposing) - { - if (disposing) - { - db.Dispose(); - } - base.Dispose(disposing); - } - - private bool PastContractOwnerExists(int id) - { - return db.PastContractOwners.Count(e => e.Id == id) > 0; - } - } -} \ No newline at end of file diff --git a/ApartmentManager/HousingWebApi/Controllers/PastUsersController.cs b/ApartmentManager/HousingWebApi/Controllers/PastUsersController.cs new file mode 100644 index 0000000..7c2cf0e --- /dev/null +++ b/ApartmentManager/HousingWebApi/Controllers/PastUsersController.cs @@ -0,0 +1,133 @@ +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 PastUsersController : ApiController + { + private DataModel db = new DataModel(); + + // GET: api/PastUsers + public IQueryable GetPastUsers() + { + return db.PastUsers; + } + + // GET: api/PastUsers/5 + [ResponseType(typeof(PastUser))] + public IHttpActionResult GetPastUser(string id) + { + PastUser pastUser = db.PastUsers.Find(id); + if (pastUser == null) + { + return NotFound(); + } + + return Ok(pastUser); + } + + // PUT: api/PastUsers/5 + [ResponseType(typeof(void))] + public IHttpActionResult PutPastUser(string id, PastUser pastUser) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + if (id != pastUser.Username) + { + return BadRequest(); + } + + db.Entry(pastUser).State = EntityState.Modified; + + try + { + db.SaveChanges(); + } + catch (DbUpdateConcurrencyException) + { + if (!PastUserExists(id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return StatusCode(HttpStatusCode.NoContent); + } + + // POST: api/PastUsers + [ResponseType(typeof(PastUser))] + public IHttpActionResult PostPastUser(PastUser pastUser) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + db.PastUsers.Add(pastUser); + + try + { + db.SaveChanges(); + } + catch (DbUpdateException) + { + if (PastUserExists(pastUser.Username)) + { + return Conflict(); + } + else + { + throw; + } + } + + return CreatedAtRoute("DefaultApi", new { id = pastUser.Username }, pastUser); + } + + // DELETE: api/PastUsers/5 + [ResponseType(typeof(PastUser))] + public IHttpActionResult DeletePastUser(string id) + { + PastUser pastUser = db.PastUsers.Find(id); + if (pastUser == null) + { + return NotFound(); + } + + db.PastUsers.Remove(pastUser); + db.SaveChanges(); + + return Ok(pastUser); + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + db.Dispose(); + } + base.Dispose(disposing); + } + + private bool PastUserExists(string id) + { + return db.PastUsers.Count(e => e.Username == id) > 0; + } + } +} \ No newline at end of file diff --git a/ApartmentManager/HousingWebApi/Controllers/ResidentsController.cs b/ApartmentManager/HousingWebApi/Controllers/ResidentsController.cs index 9cd3932..ebb0188 100644 --- a/ApartmentManager/HousingWebApi/Controllers/ResidentsController.cs +++ b/ApartmentManager/HousingWebApi/Controllers/ResidentsController.cs @@ -22,7 +22,7 @@ namespace HousingWebApi.Controllers return db.Residents; } - // GET: api/Users/5 + // GET: api/Residents/5 [ResponseType(typeof(Resident))] public IHttpActionResult GetResident(int id) { @@ -34,27 +34,6 @@ namespace HousingWebApi.Controllers return Ok(resident); } - //GET: api/Residents/1 - - [Route("api/ApartmentResidents/{id}")] - [ResponseType(typeof(ResidentList))] - public IQueryable GetResidents(int id) - { - 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 [ResponseType(typeof(void))] @@ -65,7 +44,7 @@ namespace HousingWebApi.Controllers return BadRequest(ModelState); } - if (id != resident.ResidentNr) + if (id != resident.ResidentId) { return BadRequest(); } @@ -108,7 +87,7 @@ namespace HousingWebApi.Controllers } catch (DbUpdateException) { - if (ResidentExists(resident.ResidentNr)) + if (ResidentExists(resident.ResidentId)) { return Conflict(); } @@ -118,7 +97,7 @@ namespace HousingWebApi.Controllers } } - return CreatedAtRoute("DefaultApi", new { id = resident.ResidentNr }, resident); + return CreatedAtRoute("DefaultApi", new { id = resident.ResidentId }, resident); } // DELETE: api/Residents/5 @@ -148,7 +127,7 @@ namespace HousingWebApi.Controllers private bool ResidentExists(int id) { - return db.Residents.Count(e => e.ResidentNr == id) > 0; + return db.Residents.Count(e => e.ResidentId == id) > 0; } } } \ No newline at end of file diff --git a/ApartmentManager/HousingWebApi/Controllers/UsersController.cs b/ApartmentManager/HousingWebApi/Controllers/UsersController.cs index a8c03af..4db8e9d 100644 --- a/ApartmentManager/HousingWebApi/Controllers/UsersController.cs +++ b/ApartmentManager/HousingWebApi/Controllers/UsersController.cs @@ -1,9 +1,14 @@ -using System.Data.Entity; +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 { @@ -17,23 +22,9 @@ namespace HousingWebApi.Controllers return db.Users; } - // GET: api/Users/by-username/username - [ResponseType(typeof(User))] - [Route("api/Users/by-username/{username}")] - public IHttpActionResult GetUserByUsername(string username) - { - User user = db.Users.SingleOrDefault(u => u.Username == username); - if (user == null) - { - return NotFound(); - } - - return Ok(user); - } - // GET: api/Users/5 [ResponseType(typeof(User))] - public IHttpActionResult GetUser(int id) + public IHttpActionResult GetUser(string id) { User user = db.Users.Find(id); if (user == null) @@ -46,14 +37,14 @@ namespace HousingWebApi.Controllers // PUT: api/Users/5 [ResponseType(typeof(void))] - public IHttpActionResult PutUser(int id, User user) + public IHttpActionResult PutUser(string id, User user) { if (!ModelState.IsValid) { return BadRequest(ModelState); } - if (id != user.ApartmentNr) + if (id != user.Username) { return BadRequest(); } @@ -96,7 +87,7 @@ namespace HousingWebApi.Controllers } catch (DbUpdateException) { - if (UserExists(user.ApartmentNr)) + if (UserExists(user.Username)) { return Conflict(); } @@ -106,12 +97,12 @@ namespace HousingWebApi.Controllers } } - return CreatedAtRoute("DefaultApi", new { id = user.ApartmentNr }, user); + return CreatedAtRoute("DefaultApi", new { id = user.Username }, user); } // DELETE: api/Users/5 [ResponseType(typeof(User))] - public IHttpActionResult DeleteUser(int id) + public IHttpActionResult DeleteUser(string id) { User user = db.Users.Find(id); if (user == null) @@ -134,9 +125,9 @@ namespace HousingWebApi.Controllers base.Dispose(disposing); } - private bool UserExists(int id) + private bool UserExists(string id) { - return db.Users.Count(e => e.ApartmentNr == id) > 0; + return db.Users.Count(e => e.Username == id) > 0; } } } \ No newline at end of file diff --git a/ApartmentManager/HousingWebApi/DataModel.cs b/ApartmentManager/HousingWebApi/DataModel.cs index fa16d44..0b953a6 100644 --- a/ApartmentManager/HousingWebApi/DataModel.cs +++ b/ApartmentManager/HousingWebApi/DataModel.cs @@ -14,62 +14,77 @@ namespace HousingWebApi } public virtual DbSet Apartments { get; set; } + public virtual DbSet ApartmentChanges { get; set; } + public virtual DbSet ChangeComments { get; set; } + public virtual DbSet ChangeDocuments { get; set; } public virtual DbSet Defects { get; set; } - public virtual DbSet PastContractOwners { get; set; } + public virtual DbSet DefectComments { get; set; } + public virtual DbSet DefectPictures { get; set; } + public virtual DbSet PastUsers { get; set; } public virtual DbSet Residents { get; set; } public virtual DbSet Users { get; set; } public virtual DbSet AllResidents { get; set; } public virtual DbSet ApartmentResidents { get; set; } - public virtual DbSet database_firewall_rules { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { - modelBuilder.Entity() - .Property(e => e.Size) - .HasPrecision(18, 0); - - modelBuilder.Entity() - .Property(e => e.MonthlyCharge) - .IsUnicode(false); - modelBuilder.Entity() .Property(e => e.Address) .IsUnicode(false); modelBuilder.Entity() - .Property(e => e.PlanPicture) - .IsUnicode(false); + .HasMany(e => e.ApartmentChanges) + .WithRequired(e => e.Apartment) + .WillCascadeOnDelete(false); modelBuilder.Entity() .HasMany(e => e.Defects) .WithRequired(e => e.Apartment) - .HasForeignKey(e => e.ApartmentNr) + .WillCascadeOnDelete(false); + + modelBuilder.Entity() + .HasMany(e => e.PastUsers) + .WithRequired(e => e.Apartment) .WillCascadeOnDelete(false); modelBuilder.Entity() .HasMany(e => e.Residents) .WithRequired(e => e.Apartment) - .HasForeignKey(e => e.ApartmentNr) .WillCascadeOnDelete(false); modelBuilder.Entity() - .HasOptional(e => e.User) - .WithRequired(e => e.Apartment); + .HasMany(e => e.Users) + .WithRequired(e => e.Apartment) + .WillCascadeOnDelete(false); - modelBuilder.Entity() + modelBuilder.Entity() .Property(e => e.Name) .IsUnicode(false); - modelBuilder.Entity() - .Property(e => e.Picture) + modelBuilder.Entity() + .Property(e => e.Description) .IsUnicode(false); - modelBuilder.Entity() - .Property(e => e.Picture2) + modelBuilder.Entity() + .Property(e => e.Status) + .IsUnicode(false); + + modelBuilder.Entity() + .HasMany(e => e.ChangeComments) + .WithRequired(e => e.ApartmentChange) + .WillCascadeOnDelete(false); + + modelBuilder.Entity() + .HasMany(e => e.ChangeDocuments) + .WithRequired(e => e.ApartmentChange) + .WillCascadeOnDelete(false); + + modelBuilder.Entity() + .Property(e => e.Comment) .IsUnicode(false); modelBuilder.Entity() - .Property(e => e.Picture3) + .Property(e => e.Name) .IsUnicode(false); modelBuilder.Entity() @@ -77,16 +92,46 @@ namespace HousingWebApi .IsUnicode(false); modelBuilder.Entity() - .Property(e => e.Comment) + .Property(e => e.Status) .IsUnicode(false); modelBuilder.Entity() - .Property(e => e.Status) + .HasMany(e => e.DefectComments) + .WithRequired(e => e.Defect) + .WillCascadeOnDelete(false); + + modelBuilder.Entity() + .HasMany(e => e.DefectPictures) + .WithRequired(e => e.Defect) + .WillCascadeOnDelete(false); + + modelBuilder.Entity() + .Property(e => e.Picture) .IsUnicode(false); - modelBuilder.Entity() - .Property(e => e.ApartmentNr) - .IsFixedLength(); + modelBuilder.Entity() + .Property(e => e.Username) + .IsUnicode(false); + + modelBuilder.Entity() + .Property(e => e.Password) + .IsUnicode(false); + + modelBuilder.Entity() + .Property(e => e.FirstName) + .IsUnicode(false); + + modelBuilder.Entity() + .Property(e => e.LastName) + .IsUnicode(false); + + modelBuilder.Entity() + .Property(e => e.Phone) + .IsUnicode(false); + + modelBuilder.Entity() + .Property(e => e.Email) + .IsUnicode(false); modelBuilder.Entity() .Property(e => e.FirstName) @@ -97,11 +142,11 @@ namespace HousingWebApi .IsUnicode(false); modelBuilder.Entity() - .Property(e => e.Email) + .Property(e => e.Phone) .IsUnicode(false); modelBuilder.Entity() - .Property(e => e.Picture) + .Property(e => e.Email) .IsUnicode(false); modelBuilder.Entity() @@ -112,10 +157,6 @@ namespace HousingWebApi .Property(e => e.Password) .IsUnicode(false); - modelBuilder.Entity() - .Property(e => e.Type) - .IsUnicode(false); - modelBuilder.Entity() .Property(e => e.FirstName) .IsUnicode(false); @@ -132,22 +173,6 @@ namespace HousingWebApi .Property(e => e.Email) .IsUnicode(false); - modelBuilder.Entity() - .Property(e => e.SecondName) - .IsUnicode(false); - - modelBuilder.Entity() - .Property(e => e.SecondLastName) - .IsUnicode(false); - - modelBuilder.Entity() - .Property(e => e.SecondPhone) - .IsUnicode(false); - - modelBuilder.Entity() - .Property(e => e.SecondEmail) - .IsUnicode(false); - modelBuilder.Entity() .Property(e => e.FirstName) .IsUnicode(false); @@ -163,14 +188,6 @@ namespace HousingWebApi modelBuilder.Entity() .Property(e => e.Email) .IsUnicode(false); - - modelBuilder.Entity() - .Property(e => e.start_ip_address) - .IsUnicode(false); - - modelBuilder.Entity() - .Property(e => e.end_ip_address) - .IsUnicode(false); } } } diff --git a/ApartmentManager/HousingWebApi/HousingWebApi.csproj b/ApartmentManager/HousingWebApi/HousingWebApi.csproj index e47c402..18a8c73 100644 --- a/ApartmentManager/HousingWebApi/HousingWebApi.csproj +++ b/ApartmentManager/HousingWebApi/HousingWebApi.csproj @@ -151,14 +151,14 @@ + + + - - - - - + + @@ -191,16 +191,26 @@ + + + + + + + - + + + + + Global.asax - + - diff --git a/ApartmentManager/HousingWebApi/Models/Apartment.cs b/ApartmentManager/HousingWebApi/Models/Apartment.cs index 7481344..d1ac1d5 100644 --- a/ApartmentManager/HousingWebApi/Models/Apartment.cs +++ b/ApartmentManager/HousingWebApi/Models/Apartment.cs @@ -6,40 +6,48 @@ namespace HousingWebApi using System.ComponentModel.DataAnnotations.Schema; using System.Data.Entity.Spatial; + [Table("Apartment")] public partial class Apartment { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] public Apartment() { + ApartmentChanges = new HashSet(); Defects = new HashSet(); + PastUsers = new HashSet(); Residents = new HashSet(); + Users = new HashSet(); } - [Key] [DatabaseGenerated(DatabaseGeneratedOption.None)] - public int ApartmentNumber { get; set; } + public int ApartmentId { get; set; } - public decimal Size { get; set; } + public double? Size { get; set; } - public int NumberOfRooms { get; set; } + public int? NumberOfRooms { get; set; } - [StringLength(10)] - public string MonthlyCharge { get; set; } + public double? MonthlyCharge { get; set; } public int? Floor { get; set; } - [StringLength(50)] + [StringLength(100)] public string Address { get; set; } - [StringLength(200)] - public string PlanPicture { get; set; } + public byte[] PlanPicture { get; set; } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection ApartmentChanges { get; set; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] public virtual ICollection Defects { get; set; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection PastUsers { get; set; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] public virtual ICollection Residents { get; set; } - public virtual User User { get; set; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection Users { get; set; } } } diff --git a/ApartmentManager/HousingWebApi/Models/ApartmentChange.cs b/ApartmentManager/HousingWebApi/Models/ApartmentChange.cs new file mode 100644 index 0000000..e14a35e --- /dev/null +++ b/ApartmentManager/HousingWebApi/Models/ApartmentChange.cs @@ -0,0 +1,44 @@ +namespace HousingWebApi +{ + using System; + using System.Collections.Generic; + using System.ComponentModel.DataAnnotations; + using System.ComponentModel.DataAnnotations.Schema; + using System.Data.Entity.Spatial; + + [Table("ApartmentChange")] + public partial class ApartmentChange + { + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] + public ApartmentChange() + { + ChangeComments = new HashSet(); + ChangeDocuments = new HashSet(); + } + + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.None)] + public int ChangeId { get; set; } + + public int ApartmentId { get; set; } + + [StringLength(50)] + public string Name { get; set; } + + [Column(TypeName = "date")] + public DateTime? UploadDate { get; set; } + + public string Description { get; set; } + + [StringLength(50)] + public string Status { get; set; } + + public virtual Apartment Apartment { get; set; } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection ChangeComments { get; set; } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection ChangeDocuments { get; set; } + } +} diff --git a/ApartmentManager/HousingWebApi/Models/ChangeComment.cs b/ApartmentManager/HousingWebApi/Models/ChangeComment.cs new file mode 100644 index 0000000..3c5d8d8 --- /dev/null +++ b/ApartmentManager/HousingWebApi/Models/ChangeComment.cs @@ -0,0 +1,22 @@ +namespace HousingWebApi +{ + using System; + using System.Collections.Generic; + using System.ComponentModel.DataAnnotations; + using System.ComponentModel.DataAnnotations.Schema; + using System.Data.Entity.Spatial; + + [Table("ChangeComment")] + public partial class ChangeComment + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.None)] + public int CommentId { get; set; } + + public int ChangeId { get; set; } + + public string Comment { get; set; } + + public virtual ApartmentChange ApartmentChange { get; set; } + } +} diff --git a/ApartmentManager/HousingWebApi/Models/ChangeDocument.cs b/ApartmentManager/HousingWebApi/Models/ChangeDocument.cs new file mode 100644 index 0000000..9e910dc --- /dev/null +++ b/ApartmentManager/HousingWebApi/Models/ChangeDocument.cs @@ -0,0 +1,22 @@ +namespace HousingWebApi +{ + using System; + using System.Collections.Generic; + using System.ComponentModel.DataAnnotations; + using System.ComponentModel.DataAnnotations.Schema; + using System.Data.Entity.Spatial; + + [Table("ChangeDocument")] + public partial class ChangeDocument + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.None)] + public int DocumentId { get; set; } + + public int ChangeId { get; set; } + + public byte[] Document { get; set; } + + public virtual ApartmentChange ApartmentChange { get; set; } + } +} diff --git a/ApartmentManager/HousingWebApi/Models/Defect.cs b/ApartmentManager/HousingWebApi/Models/Defect.cs index b439078..5200124 100644 --- a/ApartmentManager/HousingWebApi/Models/Defect.cs +++ b/ApartmentManager/HousingWebApi/Models/Defect.cs @@ -6,41 +6,38 @@ namespace HousingWebApi using System.ComponentModel.DataAnnotations.Schema; using System.Data.Entity.Spatial; + [Table("Defect")] public partial class Defect { - [Key] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] + public Defect() + { + DefectComments = new HashSet(); + DefectPictures = new HashSet(); + } + [DatabaseGenerated(DatabaseGeneratedOption.None)] - public int DefectNumber { get; set; } + public int DefectId { get; set; } - public int ApartmentNr { get; set; } + public int ApartmentId { get; set; } - [Required] [StringLength(50)] public string Name { get; set; } [Column(TypeName = "date")] - public DateTime DateUploaded { get; set; } - - [Required] - [StringLength(200)] - public string Picture { get; set; } - - [StringLength(200)] - public string Picture2 { get; set; } - - [StringLength(200)] - public string Picture3 { get; set; } + public DateTime? UploadDate { get; set; } - [Column(TypeName = "text")] - [Required] public string Description { get; set; } - [Column(TypeName = "text")] - public string Comment { get; set; } - - [StringLength(10)] + [StringLength(50)] public string Status { get; set; } public virtual Apartment Apartment { get; set; } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection DefectComments { get; set; } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection DefectPictures { get; set; } } } diff --git a/ApartmentManager/HousingWebApi/Models/DefectComment.cs b/ApartmentManager/HousingWebApi/Models/DefectComment.cs new file mode 100644 index 0000000..b05f790 --- /dev/null +++ b/ApartmentManager/HousingWebApi/Models/DefectComment.cs @@ -0,0 +1,22 @@ +namespace HousingWebApi +{ + using System; + using System.Collections.Generic; + using System.ComponentModel.DataAnnotations; + using System.ComponentModel.DataAnnotations.Schema; + using System.Data.Entity.Spatial; + + [Table("DefectComment")] + public partial class DefectComment + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.None)] + public int PictureId { get; set; } + + public int DefectId { get; set; } + + public string Picture { get; set; } + + public virtual Defect Defect { get; set; } + } +} diff --git a/ApartmentManager/HousingWebApi/Models/DefectPicture.cs b/ApartmentManager/HousingWebApi/Models/DefectPicture.cs new file mode 100644 index 0000000..6a83338 --- /dev/null +++ b/ApartmentManager/HousingWebApi/Models/DefectPicture.cs @@ -0,0 +1,22 @@ +namespace HousingWebApi +{ + using System; + using System.Collections.Generic; + using System.ComponentModel.DataAnnotations; + using System.ComponentModel.DataAnnotations.Schema; + using System.Data.Entity.Spatial; + + [Table("DefectPicture")] + public partial class DefectPicture + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.None)] + public int PictureId { get; set; } + + public int DefectId { get; set; } + + public byte[] Picture { get; set; } + + public virtual Defect Defect { get; set; } + } +} diff --git a/ApartmentManager/HousingWebApi/Models/PastContractOwner.cs b/ApartmentManager/HousingWebApi/Models/PastContractOwner.cs deleted file mode 100644 index 273952a..0000000 --- a/ApartmentManager/HousingWebApi/Models/PastContractOwner.cs +++ /dev/null @@ -1,17 +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 PastContractOwner - { - [DatabaseGenerated(DatabaseGeneratedOption.None)] - public int Id { get; set; } - - [StringLength(10)] - public string ApartmentNr { get; set; } - } -} diff --git a/ApartmentManager/HousingWebApi/Models/PastUser.cs b/ApartmentManager/HousingWebApi/Models/PastUser.cs new file mode 100644 index 0000000..f258d34 --- /dev/null +++ b/ApartmentManager/HousingWebApi/Models/PastUser.cs @@ -0,0 +1,49 @@ +namespace HousingWebApi +{ + using System; + using System.Collections.Generic; + using System.ComponentModel.DataAnnotations; + using System.ComponentModel.DataAnnotations.Schema; + using System.Data.Entity.Spatial; + + [Table("PastUser")] + public partial class PastUser + { + [Key] + [StringLength(30)] + public string Username { get; set; } + + public int ApartmentId { get; set; } + + [Required] + [StringLength(30)] + public string Password { get; set; } + + public bool IsBm { get; set; } + + [StringLength(30)] + public string FirstName { get; set; } + + [StringLength(30)] + public string LastName { get; set; } + + [Column(TypeName = "date")] + public DateTime? BirthDate { get; set; } + + [StringLength(20)] + public string Phone { get; set; } + + [StringLength(50)] + public string Email { get; set; } + + public byte[] Picture { get; set; } + + [Column(TypeName = "date")] + public DateTime? MoveInDate { get; set; } + + [Column(TypeName = "date")] + public DateTime? MoveOutDate { get; set; } + + public virtual Apartment Apartment { get; set; } + } +} diff --git a/ApartmentManager/HousingWebApi/Models/Resident.cs b/ApartmentManager/HousingWebApi/Models/Resident.cs index 319a697..c9a698f 100644 --- a/ApartmentManager/HousingWebApi/Models/Resident.cs +++ b/ApartmentManager/HousingWebApi/Models/Resident.cs @@ -6,31 +6,30 @@ namespace HousingWebApi using System.ComponentModel.DataAnnotations.Schema; using System.Data.Entity.Spatial; + [Table("Resident")] public partial class Resident { - [Key] - public int ResidentNr { get; set; } + [DatabaseGenerated(DatabaseGeneratedOption.None)] + public int ResidentId { get; set; } - public int ApartmentNr { get; set; } + public int ApartmentId { get; set; } - [Required] - [StringLength(20)] + [StringLength(30)] public string FirstName { get; set; } - [Required] - [StringLength(20)] + [StringLength(30)] public string LastName { get; set; } [Column(TypeName = "date")] public DateTime? BirthDate { get; set; } - public int? Phone { get; set; } + [StringLength(20)] + public string Phone { get; set; } - [StringLength(30)] + [StringLength(50)] public string Email { get; set; } - [StringLength(220)] - public string Picture { get; set; } + public byte[] Picture { get; set; } public virtual Apartment Apartment { get; set; } } diff --git a/ApartmentManager/HousingWebApi/Models/ResidentList.cs b/ApartmentManager/HousingWebApi/Models/ResidentList.cs deleted file mode 100644 index 9423bc1..0000000 --- a/ApartmentManager/HousingWebApi/Models/ResidentList.cs +++ /dev/null @@ -1,20 +0,0 @@ -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 string Picture { get; set; } - - } -} \ No newline at end of file diff --git a/ApartmentManager/HousingWebApi/Models/User.cs b/ApartmentManager/HousingWebApi/Models/User.cs index e260ede..019e788 100644 --- a/ApartmentManager/HousingWebApi/Models/User.cs +++ b/ApartmentManager/HousingWebApi/Models/User.cs @@ -6,58 +6,43 @@ namespace HousingWebApi using System.ComponentModel.DataAnnotations.Schema; using System.Data.Entity.Spatial; + [Table("User")] public partial class User { [Key] - [DatabaseGenerated(DatabaseGeneratedOption.None)] - public int ApartmentNr { get; set; } - - [Required] - [StringLength(15)] + [StringLength(30)] public string Username { get; set; } + public int ApartmentId { get; set; } + [Required] - [StringLength(15)] + [StringLength(30)] public string Password { get; set; } - [Required] - [StringLength(1)] - public string Type { get; set; } + public bool IsBm { get; set; } - [Required] - [StringLength(20)] + [StringLength(30)] public string FirstName { get; set; } - [Required] - [StringLength(20)] + [StringLength(30)] public string LastName { get; set; } [Column(TypeName = "date")] public DateTime? BirthDate { get; set; } - [StringLength(12)] + [StringLength(20)] public string Phone { get; set; } - [StringLength(30)] + [StringLength(50)] public string Email { get; set; } - [Column(TypeName = "image")] public byte[] Picture { get; set; } - [StringLength(20)] - public string SecondName { get; set; } - - [StringLength(20)] - public string SecondLastName { get; set; } - [Column(TypeName = "date")] - public DateTime? SecondBirthDate { get; set; } - - [StringLength(12)] - public string SecondPhone { get; set; } + public DateTime? MoveInDate { get; set; } - [StringLength(30)] - public string SecondEmail { get; set; } + [Column(TypeName = "date")] + public DateTime? MoveOutDate { get; set; } public virtual Apartment Apartment { get; set; } } diff --git a/ApartmentManager/HousingWebApi/Models/database_firewall_rules.cs b/ApartmentManager/HousingWebApi/Models/database_firewall_rules.cs deleted file mode 100644 index 3b5d6a5..0000000 --- a/ApartmentManager/HousingWebApi/Models/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/Web.config b/ApartmentManager/HousingWebApi/Web.config index 8261278..d4ce313 100644 --- a/ApartmentManager/HousingWebApi/Web.config +++ b/ApartmentManager/HousingWebApi/Web.config @@ -79,5 +79,6 @@ - - \ No newline at end of file + + + \ No newline at end of file -- cgit v1.2.3