public IHttpActionResult PostComment(Comment comment) { string UserId = (from r in db.Users where r.UserName == comment.CreatedBy select r.Id).FirstOrDefault(); comment.CreatedDate = DateTime.Now; comment.ModifiedDate = DateTime.Now; comment.ModifiedBy = comment.CreatedBy; comment.UserId = UserId; db.Comments.Add(comment); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = comment.Id }, comment); }
public IHttpActionResult PutComment(int id, Comment comment) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != comment.Id) { return BadRequest(); } db.Entry(comment).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CommentExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }