From 30f9eae5903c4eaf99523cbfc49c0eeaef35520d Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Tue, 30 May 2017 10:56:11 +0200 Subject: Fixed deleting defect pictures. --- .../Controllers/DefectPicturesController.cs | 37 ++++++++-------------- .../HousingWebApi/HousingWebApi.csproj | 2 +- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/ApartmentManager/HousingWebApi/Controllers/DefectPicturesController.cs b/ApartmentManager/HousingWebApi/Controllers/DefectPicturesController.cs index 2c42471..f149bfe 100644 --- a/ApartmentManager/HousingWebApi/Controllers/DefectPicturesController.cs +++ b/ApartmentManager/HousingWebApi/Controllers/DefectPicturesController.cs @@ -16,15 +16,21 @@ namespace HousingWebApi.Controllers { private DataModel db = new DataModel(); - [Route("api/DefectPictures/{id}")] - public IQueryable GetResidents(int id) + //GET: api/DefectPicturesById + [Route("api/DefectPicturesById/{id}")] + public IQueryable GetDefectPicturesById(int id) { - var pictureslist = from defectPicture in db.DefectPictures - where (defectPicture.DefectId == id) - select defectPicture; - return pictureslist; + var picturesList = from defectPicture in db.DefectPictures + where (defectPicture.DefectId == id) + select defectPicture; + return picturesList; + } + + // GET: api/DefectPictures + public IQueryable GetDefectPictures() + { + return db.DefectPictures; } - // GET: api/DefectPictures/5 [ResponseType(typeof(DefectPicture))] @@ -84,22 +90,7 @@ namespace HousingWebApi.Controllers } db.DefectPictures.Add(defectPicture); - - try - { - db.SaveChanges(); - } - catch (DbUpdateException) - { - if (DefectPictureExists(defectPicture.PictureId)) - { - return Conflict(); - } - else - { - throw; - } - } + db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = defectPicture.PictureId }, defectPicture); } diff --git a/ApartmentManager/HousingWebApi/HousingWebApi.csproj b/ApartmentManager/HousingWebApi/HousingWebApi.csproj index b009a06..407d4b0 100644 --- a/ApartmentManager/HousingWebApi/HousingWebApi.csproj +++ b/ApartmentManager/HousingWebApi/HousingWebApi.csproj @@ -151,6 +151,7 @@ + @@ -193,7 +194,6 @@ - -- cgit v1.2.3