diff --git a/BL/Interfaces/IFoorumService.cs b/BL/Interfaces/IFoorumService.cs index 3f06df6..faed0d5 100644 --- a/BL/Interfaces/IFoorumService.cs +++ b/BL/Interfaces/IFoorumService.cs @@ -13,7 +13,7 @@ namespace BL.Interfaces FoorumDTO Get(int id); FoorumDTO Add(FoorumDTO foorum); FoorumDTO Update(FoorumDTO foorum); - void Hide(int id); + void Hide(int id, bool hide=true); void Delete(int id); void AddPost(int id, PostDTO post); diff --git a/BL/Services/FoorumService.cs b/BL/Services/FoorumService.cs index a46f946..889915f 100644 --- a/BL/Services/FoorumService.cs +++ b/BL/Services/FoorumService.cs @@ -32,7 +32,9 @@ namespace BL.Services public void Delete(int id) { - throw new NotImplementedException(); + var f = _foorumRepository.GetById(id); + _foorumRepository.Delete(f); + _foorumRepository.SaveChanges(); } public FoorumDTO Get(int id) @@ -50,9 +52,12 @@ namespace BL.Services } - public void Hide(int id) + public void Hide(int id, bool hide=true) { - throw new NotImplementedException(); + var f = _foorumRepository.GetById(id); + f.Visible = !hide; + _foorumRepository.Update(f); + _foorumRepository.SaveChanges(); } public IEnumerable SearchFoorumAuthor(string query) diff --git a/WebApi/Controllers/FoorumController.cs b/WebApi/Controllers/FoorumController.cs index 44c5316..1325160 100644 --- a/WebApi/Controllers/FoorumController.cs +++ b/WebApi/Controllers/FoorumController.cs @@ -54,12 +54,25 @@ namespace WebApi.Controllers public IHttpActionResult Put(int id, [FromBody]FoorumDTO foorum) { foorum.FoorumId = id; - return Ok(_foorumService.Update(foorum)); + var updatedFoorum = _foorumService.Update(foorum); + if (updatedFoorum == null) + { + return NotFound(); + } + return Ok(updatedFoorum); } // DELETE api//5 - public void Delete(int id) + public void Delete(int id, [FromUri]bool permanent=false) { + if (permanent) + { + _foorumService.Delete(id); + } + else + { + _foorumService.Hide(id); + } } } } \ No newline at end of file diff --git a/WebApi/index.html b/WebApi/index.html index 8b1cd7c..c13d547 100644 --- a/WebApi/index.html +++ b/WebApi/index.html @@ -3,10 +3,15 @@
- +
- + + +
+ + +