public ActionResult Comments(int id, string name, string email, string body) { Post post = GetPost(id); Comment comment = new Comment(); comment.Post = post; comment.DateTime = DateTime.Now; comment.Name = name; comment.Email = email; comment.Body = body; if (((comment.Name == "") && (comment.Body == "")) || (comment.Body == " ")) { return RedirectToAction("Details", new { id = id }); } model.Comments.Add(comment); model.SaveChanges(); // Here user object with updated data return RedirectToAction("Details", new { id = id }); }
public ActionResult Edit(Comment comment) { if (ModelState.IsValid) { db.Entry(comment).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(comment); }
public ActionResult Create(Comment comment) { if (ModelState.IsValid) { comment.CommentDate = DateTime.Now; db.Comments.Add(comment); db.SaveChanges(); return RedirectToAction("Index"); } return View(comment); }
public void InsertOrUpdate(Comment comment) { if (comment.Id == default(System.Guid)) { // New entity comment.Id = Guid.NewGuid(); context.Comments.Add(comment); } else { // Existing entity context.Entry(comment).State = EntityState.Modified; } }
public ActionResult Create(int id) { Comment model = new Comment { PostId = id }; return View(model); }