public async Task <IActionResult> UpdateBlogPost([FromRoute] int id, [FromBody] BlogPost blogPost) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != blogPost.PostId) { return(BadRequest(ModelState)); } if (!BlogPostExist(id)) { return(NotFound()); } _blogPostsContext.Entry(blogPost).State = EntityState.Modified; try { _dataRepository.Update(blogPost); var save = await _dataRepository.SaveAsync(blogPost); } catch (DbUpdateConcurrencyException ex) { throw ex; } return(NoContent()); }
public async Task <IActionResult> PutBlogPost([FromRoute] int id, [FromBody] BlogPost blogPost) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != blogPost.PostId) { return(BadRequest()); } _context.Entry(blogPost).State = EntityState.Modified; try { _repo.Update(blogPost); var save = await _repo.SaveAsync(blogPost); } catch (DbUpdateConcurrencyException) { if (!BlogPostExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutBlogPost([FromRoute] int id, [FromBody] BlogPost blogPost) { _logger.LogInformation(LoggingEvents.UpdateBlogPostWithId, "Updating BlogPost with Id: {0}", id); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != blogPost.PostId) { _logger.LogWarning(LoggingEvents.UpdateBlogPostWithIdNotFound, "Update for BlogPost with Id: {0} BAD REQUEST", id); return(BadRequest()); } _context.Entry(blogPost).State = EntityState.Modified; try { _repo.Update(blogPost); await _repo.SaveAsync(blogPost); } catch (DbUpdateConcurrencyException) { if (!BlogPostExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }