public ActionResult Add(CommentViewModel viewModel) { try { if (ModelState.IsValid) { var comment = new Comment { Id = viewModel.Id, Name = viewModel.Name, Email = viewModel.Email, Description = viewModel.Description, CreateDate = DateTime.Now, PostId = viewModel.PostId }; _db.Comments.Add(comment); _db.SaveChanges(); return Content(Boolean.TrueString); } return Content(ExceptionHelper.ModelStateErrorFormat(ModelState)); } catch (Exception ex) { ExceptionHelper.ExceptionMessageFormat(ex, true); return Content("Sorry! Unable to add this comment."); } }
// // GET: /Comment/Delete/By ID public ActionResult Delete(int id) { try { var comment = _db.Comments.Find(id); if (comment != null) { var commentViewModel = new CommentViewModel { Id = comment.Id, Name = comment.Name, Email = comment.Email, Description = comment.Description, CreateDate = comment.CreateDate, PostId = comment.PostId }; return PartialView("_Delete", commentViewModel); } else { return RedirectToAction("Index", "Comment"); } } catch (Exception ex) { ExceptionHelper.ExceptionMessageFormat(ex, true); return RedirectToAction("Index", "Comment"); } }
public ActionResult Edit(CommentViewModel viewModel) { try { if (ModelState.IsValid) { var comment = new Comment { Id = viewModel.Id, Name = viewModel.Name, Email = viewModel.Email, Description = viewModel.Description }; _db.Entry(comment).State = EntityState.Modified; _db.SaveChanges(); return Content(Boolean.TrueString); } return Content(ExceptionHelper.ModelStateErrorFormat(ModelState)); } catch (Exception ex) { ExceptionHelper.ExceptionMessageFormat(ex, true); return Content("Sorry! Unable to edit this comment."); } }