public bool AddComment(Comment comment) { comment.Date = DateTime.Now; context.Comments.Add(comment); context.SaveChanges(); return true; }
public ActionResult Add(Comment comment) { if (ModelState.IsValid) { repository.AddComment(comment); return RedirectToAction("Index", new { id = comment.Post.PostId}); } else return View("Index", new { id = comment.Post.PostId }); }
public HttpResponseMessage PostComment(Comment comment) { comment.Owner = manager.FindById(User.Identity.GetUserId()); if (ModelState.IsValid && repository.AddComment(comment)) { HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, comment); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = comment.CommentId })); return response; } else return Request.CreateResponse(HttpStatusCode.BadRequest); }