public ActionResult View(int id, string question, CommentForm comment) { ICaptchaService captchaService = new ReCaptchaService(); comment.PassesCaptchaValidation = captchaService.PassesCaptcha(Request, BlogValues.CaptchaPrivateKey()); int replyId = Int32.TryParse(Request.QueryString["replyId"], out replyId) ? replyId : -1; bool replyWithQuote = Boolean.TryParse(Request.QueryString["replyWithQuote"], out replyWithQuote) ? replyWithQuote : false; comment.ContainerId = id; comment.IpAddress = Request.UserHostAddress; comment.ParentCommentId = replyId != -1 ? (int?)replyId : null; int commentId = -1; if (comment.IsValid(new ModelStateWrapper(ModelState))) { commentId = PollService.CreatePollComment(comment); Response.Redirect("/Poll/" + id + "/" + question + "?fadeComment=" + commentId + "#comments"); } PollDetailView pollDetail = PollService.GetPoll(id, -1, false, -1); pollDetail.CommentForm = comment; return View("View", pollDetail); }
public ActionResult Contact(string name, string email, string message) { ICaptchaService captchaService = new ReCaptchaService(); if (!captchaService.PassesCaptcha(Request, BlogValues.CaptchaPrivateKey())) { ModelState.AddModelError("Captcha", "Failed Captcha test, please try again."); } if (name.IsNullEmptyOrWhitespace()) { ModelState.AddModelError("name", "Required."); } if (email.IsNullEmptyOrWhitespace()) { ModelState.AddModelError("email", "Required."); } if (!email.IsEmailAddress()) { ModelState.AddModelError("email", "Not a valid email address."); } if (message.IsNullEmptyOrWhitespace()) { ModelState.AddModelError("message", "Required."); } if (ModelState.IsValid) { MailAddress from = new MailAddress(email, name); MailAddress to = new MailAddress("*****@*****.**"); MailMessage mailMessage = new MailMessage(); mailMessage.From = from; mailMessage.To.Add(to); mailMessage.Subject = "Message From Contact Form (DominicPettifer.co.uk)"; mailMessage.Body = "Message sent from Contact form at DominicPettifer.co.uk...\n\n\"" + message + "\"\n\n" + "Name: " + name + "\n" + "Email: " + email; mailMessage.IsBodyHtml = false; SmtpClient client = new SmtpClient(); client.Send(mailMessage); return RedirectToAction("Contact", new { success = "true" }); } else { return View(); } }
public ActionResult View(int id, string blogTitle, CommentForm comment) { ICaptchaService captchaService = new ReCaptchaService(); comment.PassesCaptchaValidation = captchaService.PassesCaptcha(Request, BlogValues.CaptchaPrivateKey()); int replyId = Int32.TryParse(Request.QueryString["replyId"], out replyId) ? replyId : -1; bool replyWithQuote = Boolean.TryParse(Request.QueryString["replyWithQuote"], out replyWithQuote) ? replyWithQuote : false; int pageNumber = Int32.TryParse(Request.QueryString["page"], out pageNumber) ? pageNumber : 1; if (comment.IsValid(new ModelStateWrapper(this.ModelState))) { BlogService.CreateBlogComment(id, replyId != -1 ? (int?)replyId : null, comment); Response.Redirect("/Blog/" + id + "/" + blogTitle + "?awaitingApproval=true#postcomment"); } BlogPageView blogPageView = BlogService.GetBlogPage(id, pageNumber, replyId, replyWithQuote, false); blogPageView.CommentForm = comment; return View("View", blogPageView); }