Пример #1
0
 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);
 }
Пример #2
0
 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);
 }
Пример #3
0
 public ActionResult Edit(CommentModels commentmodels)
 {
     if (ModelState.IsValid)
     {
         db.Entry(commentmodels).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(commentmodels);
 }