public ActionResult Send([Bind(Prefix = "Submission")] ContactFormSubmission s)
        {
            ContactFormData vd = new ContactFormData()
            {
                Submission = s
            };

            vd.Modal = false;
            vd.Errors = new List<string>();

            if (ModelState.IsValid)
            {
                s.DateStamp = DateTime.Now;
                bool emailSent = true;
                try
                {
                    _smtpService.SendToMe(new MailAddress(s.EmailAddress, s.Name), EmmaMorris.ContactMeSubject, s.Message);
                }
                catch
                {
                    emailSent = false;
                }
                s.EmailSent = emailSent;
                _contactFormSubmissionWriter.Save(s);

                _cookieHandler.LastContactFormSubmissionID = s.SubmissionId;

                return RedirectToAction("Index", "Home", new { msg = HomeController.Message.emailsent });
            }
            else
            {
                vd.Errors = ModelState.Values.Where(v => v.Errors.Any()).SelectMany(v => v.Errors).Select(e => e.ErrorMessage).ToList();
            }

            vd.MainSideBarData = mainSideBarData();

            return View("Index", vd);
        }
示例#2
0
 public static MvcHtmlString ContactForm(this HtmlHelper html, ContactFormData data)
 {
     return html.Partial("ContactForm", data);
 }