Exemplo n.º 1
0
        public async Task <ActionResult> Contact(Models.ContactFormModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    string ip    = Request.UserHostAddress,
                           agent = Request.UserAgent;

                    var helper = new AkismetHelper(AppSettings.AkismetApiKey, AppSettings.AkismetRegisteredSite);

                    var errors = await helper.ProcessFormAsync(model.Name, model.Email, model.Message, "contact-form", ip, agent);

                    if (errors == null || errors.Count() == 0)
                    {
                        try
                        {
                            if (!helper.IsSpam)
                            {
                                string name    = HtmlUtility.WhitewashMarkup(model.Name);
                                string email   = HtmlUtility.WhitewashMarkup(model.Email);
                                string message = HtmlUtility.SanitizeReduceMarkup(model.Message);

                                string mailHtml      = string.Format("<h4>Name:</h4>\n<p>{0}</p>\n<h4>Email:</h4>\n<p>{1}</p>\n<h4>Message:</h4>\n<div>{2}</div>", name, email, message);
                                string mailplaintext = string.Format("Name: {0}\nEmail: {1}\nMessage: {2}", name, email, message);

                                await SendEmailAsync("ContactNotification", AppSettings.ContactEmail, "MKG Contact Notification", mailHtml, mailplaintext);
                            }
                        }
                        catch (Exception ex)
                        {
                            HandleException(ex);
                        }

                        TempData.Clear();
                        TempData.Add(Alert.Success, "<b>Thank you!</b> Your message was received. You should hear from me shortly.");

                        return(RedirectToAction("index", "home"));
                    }
                    else
                    {
                        foreach (var err in errors)
                        {
                            ModelState.AddModelError("", err);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }

            // If we're still here, something is invalid or an error has occurred. Redisplay the form.

            return(View(model));
        }
Exemplo n.º 2
0
 public ActionResult Contact(Models.ContactFormModel contactForm)
 {
     if (ModelState.IsValid)
     {
         return(View("Thanks"));
     }
     else
     {
         return(View(contactForm));
     }
 }
Exemplo n.º 3
0
        public ActionResult Contact()
        {
            var model = new Models.ContactFormModel();

            if (SessionManager.IsLoggedIn)
            {
                model.Email    = SessionManager.Email;
                model.UserName = SessionManager.UserName;
            }

            return(View(model));
        }