Return proper http status codes on delete
This commit is contained in:
parent
41991a68dd
commit
1249950059
@ -14,7 +14,7 @@ namespace BL.Interfaces
|
||||
FoorumDTO Add(FoorumDTO foorum);
|
||||
FoorumDTO Update(FoorumDTO foorum);
|
||||
void Hide(int id, bool hide=true);
|
||||
void Delete(int id);
|
||||
FoorumDTO Delete(int id);
|
||||
void AddPost(int id, PostDTO post);
|
||||
|
||||
IEnumerable<FoorumDTO> SearchFoorumTitle(string query);
|
||||
|
@ -30,11 +30,17 @@ namespace BL.Services
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Delete(int id)
|
||||
public FoorumDTO Delete(int id)
|
||||
{
|
||||
var f = _foorumRepository.GetById(id);
|
||||
if (f == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_foorumRepository.Delete(f);
|
||||
_foorumRepository.SaveChanges();
|
||||
|
||||
return _factory.Create(f);
|
||||
}
|
||||
|
||||
public FoorumDTO Get(int id)
|
||||
@ -48,16 +54,22 @@ namespace BL.Services
|
||||
foreach (var f in _foorumRepository.GetAll())
|
||||
{
|
||||
yield return _factory.Create(f);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void Hide(int id, bool hide=true)
|
||||
public FoorumDTO Hide(int id, bool hide=true)
|
||||
{
|
||||
var f = _foorumRepository.GetById(id);
|
||||
if (f == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
f.Visible = !hide;
|
||||
_foorumRepository.Update(f);
|
||||
_foorumRepository.SaveChanges();
|
||||
|
||||
return _factory.Create(f);
|
||||
}
|
||||
|
||||
public IEnumerable<FoorumDTO> SearchFoorumAuthor(string query)
|
||||
|
@ -63,16 +63,25 @@ namespace WebApi.Controllers
|
||||
}
|
||||
|
||||
// DELETE api/<controller>/5
|
||||
public void Delete(int id, [FromUri]bool permanent=false)
|
||||
public IHttpActionResult Delete(int id, [FromUri]bool permanent=false)
|
||||
{
|
||||
FoorumDTO f = null;
|
||||
|
||||
if (permanent)
|
||||
{
|
||||
_foorumService.Delete(id);
|
||||
f =_foorumService.Delete(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
_foorumService.Hide(id);
|
||||
}
|
||||
f = _foorumService.Hide(id);
|
||||
}
|
||||
|
||||
if (f == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
return Ok(f);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user