public ActionResult Index(SubmitCommentRenderingModel model)
        {
            var comment = BuildComment(model);
            var result  = ValidateCommentCore.Validate(comment, HttpContext.Request.Form);

            if (ModelState.IsValid && result.Success)
            {
                var submissionResult = SubmitCommentCore.Submit(comment);
                if (submissionResult.IsNull)
                {
                    Session["Submitted"] = false;
                }
                else
                {
                    Session["Submitted"] = true;
                }
                return(Redirect(HttpContext.Request.Url.AbsoluteUri));
            }

            foreach (var error in result.Errors)
            {
                ModelState.AddModelError(string.Empty, error);
            }

            TempData["ScrollTo"] = true;
            return(View("~/Views/WeBlog/SubmitComment.cshtml"));
        }
        protected virtual Comment BuildComment(SubmitCommentRenderingModel model)
        {
            var comment = new Comment
            {
                AuthorName  = model.UserName,
                Text        = model.Comment,
                AuthorEmail = model.Email
            };

            comment.Fields.Add(Constants.Fields.Website, model.Website);
            comment.Fields.Add(Constants.Fields.IpAddress, HttpContext.Request.UserHostAddress);
            return(comment);
        }
Example #3
0
 protected virtual void ValidateModelState(SubmitCommentRenderingModel model)
 {
     if (model.UserName == null)
     {
         ModelState.AddModelError("", "UserName");
     }
     if (model.Email == null)
     {
         ModelState.AddModelError("", "Email");
     }
     if (model.Comment == null)
     {
         ModelState.AddModelError("", "Comment");
     }
 }
Example #4
0
 protected virtual void ValidateModelState(SubmitCommentRenderingModel model)
 {
     if (model.UserName == null)
     {
         ModelState.AddModelError("", string.Format(Translator.Text("REQUIRED_FIELD"), "Name"));
     }
     if (model.Email == null)
     {
         ModelState.AddModelError("", string.Format(Translator.Text("REQUIRED_FIELD"), "Email"));
     }
     if (model.Comment == null)
     {
         ModelState.AddModelError("", string.Format(Translator.Text("REQUIRED_FIELD"), "Comment"));
     }
 }
Example #5
0
 public ActionResult Index(SubmitCommentRenderingModel model, bool captchaValid, string captchaErrorMessage)
 {
     if (ModelState.IsValid && captchaValid)
     {
         var comment          = BuildComment(model);
         var submissionResult = SubmitCommentCore.Submit(comment);
         if (submissionResult.IsNull)
         {
             Session["Submitted"] = false;
         }
         else
         {
             Session["Submitted"] = true;
         }
         return(Redirect(HttpContext.Request.Url.AbsoluteUri));
     }
     ValidateModelState(model);
     if (!captchaValid)
     {
         ModelState.AddModelError("", "The text you typed does not match the text in the image.");
     }
     TempData["ScrollTo"] = true;
     return(View("~/Views/WeBlog/SubmitComment.cshtml"));
 }