Example #1
0
        public ActionResult AddComment(Comment comment)
        {
            var validationResult = this.commentAppService.Add(comment);

            if (validationResult.IsValid == false)
            {
                ControllerHelpers.AddErrors(validationResult.Errors, ModelState);
            }

            return(RedirectToAction("Post", new { id = comment.PostId }));
        }
Example #2
0
        public ActionResult Save(Comment comment)
        {
            if (comment == null)
            {
                throw new InvalidOperationException();
            }

            if (comment.Id > 0)
            {
                var validationResult = this.commentAppService.Update(comment);
                if (validationResult.IsValid == false)
                {
                    ViewBag.Error = "There are erros, please correct and try again.";
                    ControllerHelpers.AddErrors(validationResult.Errors, ModelState);
                }
                else
                {
                    ViewBag.Message = "Comment successful updated.";
                }
            }
            else
            {
                var validationResult = this.commentAppService.Add(comment);
                if (validationResult.IsValid == false)
                {
                    ViewBag.Error = "There are erros, please correct and try again.";
                    ControllerHelpers.AddErrors(validationResult.Errors, ModelState);
                    RedirectToAction("New");
                }
                else
                {
                    ViewBag.Message = "Comment successful added.";
                }
            }

            return(RedirectToAction("Edit", new { id = comment.Id }));
        }