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."); } }
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."); } }