public ActionResult Create(int id = -1) { if (id == -1) return HttpNotFound(); PostModels post = db.Posts.Find(id); if (post == null) return HttpNotFound(); CommentModels comment = new CommentModels(); comment.postId = id; return View(comment); }
public ActionResult Create(CommentModels commentmodels) { if (db.Posts.Find(commentmodels.postId) == null) return HttpNotFound(); commentmodels.commentDate = DateTime.Now; if (ModelState.IsValid) { db.Comments.Add(commentmodels); db.SaveChanges(); return RedirectToAction("Index"); } return RedirectToAction("../Posts/Index"); //return View(commentmodels); }
public ActionResult Edit(CommentModels commentmodels) { if (ModelState.IsValid) { db.Entry(commentmodels).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(commentmodels); }