Ejemplo n.º 1
0
        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.");
            }
        }
Ejemplo n.º 2
0
        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.");
            }
        }