public IHttpActionResult PutComment(int id, [FromBody] CommentFullDTO value) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != value.BlogId) { return(BadRequest()); } try { this._blogService.UpdateComment(value); } catch (DbUpdateConcurrencyException) { if (this._blogService.GetCommentById(id) != null) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public Comment RecreateFromCommentFullDTO(CommentFullDTO commentFullDTO) { return(new Comment() { BlogId = commentFullDTO.BlogId, Body = commentFullDTO.Body, CommentId = commentFullDTO.CommentId, User = commentFullDTO.User }); }
public IHttpActionResult GetComment(int id) { CommentFullDTO commentDTO = this._blogService.GetCommentById(id); if (commentDTO == null) { return(NotFound()); } return(Ok(commentDTO)); }
public IHttpActionResult PostComment([FromBody] CommentFullDTO value) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { this._blogService.AddComment(value); } catch (Exception ex) { return(BadRequest(ex.Message)); } return(CreatedAtRoute("DefaultApi", new { id = value.CommentId }, value)); }
public void DeleteComment(CommentFullDTO commentDTO) { this._commentRepository.Delete(this._commentFactory.RecreateFromCommentFullDTO(commentDTO)); this._commentRepository.SaveChanges(); }