public async Task <IActionResult> UpdateComment(int id, PostComment comment) { if (id != comment.Id) { return(BadRequest()); } _context.Entry(comment).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CommentExists(id)) { return(NotFound()); } else { throw; } } CommentWrapper commentWrapper = new CommentWrapper(comment, GetRequestedUrl()); return(Ok(new { commentWrapper, updated = true })); }
public async Task <IActionResult> UpdateOnePost(int id, Post post) { if (id != post.Id) { return(BadRequest()); } _context.Entry(post).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PostExists(id)) { return(NotFound()); } else { throw; } } return(Ok(new PostWrapper(_context.Posts.Where(p => p.Id == id).FirstOrDefault(), GetRequestedUrl()))); }