public IHttpActionResult PutBlog(int id, [FromBody] BlogFullDTO value) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != value.BlogId) { return(BadRequest()); } try { this._blogService.UpdateBlog(value); } catch (DbUpdateConcurrencyException) { if (this._blogService.GetBlogById(id) != null) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public Blog RecreateFromBlogDTO(BlogFullDTO BlogDTO) { return(new Blog() { BlogId = BlogDTO.BlogId, Body = BlogDTO.Body, Comments = BlogDTO.Comments.Select(x => _commentFactory.RecreateFromCommentFullDTO(x)).ToList() }); }
public IHttpActionResult GetBlog(int id) { BlogFullDTO blogDTO = this._blogService.GetBlogById(id); if (blogDTO == null) { return(NotFound()); } return(Ok(blogDTO)); }
public IHttpActionResult PostBlog([FromBody] BlogFullDTO value) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { this._blogService.AddBlog(value); } catch (Exception ex) { return(BadRequest(ex.Message)); } return(CreatedAtRoute("DefaultApi", new { id = value.BlogId }, value)); }
public void DeleteBlog(BlogFullDTO blogDTO) { this._blogRepository.Delete(this._blogFactory.RecreateFromBlogDTO(blogDTO)); this._blogRepository.SaveChanges(); }