public async Task<IHttpActionResult> Create(Comment model) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var user = db.Users.Find(User.Identity.GetUserId()); model.AuthorName = user.UserName; model.Created = DateTimeOffset.UtcNow; db.Comments.Add(model); await db.SaveChangesAsync(); return Ok(); }
public async Task<IHttpActionResult> Edit (Comment model) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var oldComment = db.Comments.AsNoTracking().FirstOrDefault(c => c.Id == model.Id); if (oldComment.Body != model.Body) { oldComment.Body = model.Body; oldComment.Updated = DateTimeOffset.UtcNow; await db.SaveChangesAsync(); } return Ok(); }