/// <summary> /// For the supplied contact us form model, this method creates /// the message and sends it off to the send grid send method. /// </summary> public static void SendContactForm(ContactUsDataModel c) { SendGridMessage msg = new SendGridMessage(); msg.From = new EmailAddress(SiteSettingsConstant.GeneralFromEmail); msg.Subject = SiteSettingsConstant.ContactUsSubjectLine; msg.AddTo(SiteSettingsConstant.GeneralToEmail); StringBuilder sbtext = new StringBuilder(); StringBuilder sbhtml = new StringBuilder(); sbhtml.Append("<h2>The Recipy Bot</h2><hr/><p>You have a new message from the Recipy Bot.</p><br/>"); foreach (var property in c.GetType().GetProperties()) { if (property.Name == "Email") { // Set the reply to field of the email to the contact persons email address for ease of use msg.ReplyTo = new EmailAddress(property.GetValue(c, null).ToString()); } sbtext.Append(property.Name + ": " + property.GetValue(c, null) + "\r\n"); sbhtml.Append("<p><span style='font-weight:bold;'>" + property.Name + ":</span> " + property.GetValue(c, null) + "<p>"); } // Email footer sbhtml.Append("<br /><p>Thanks,</p><p><b>The Recipy Bot</b></p>"); msg.PlainTextContent = sbtext.ToString(); msg.HtmlContent = sbhtml.ToString(); SendMessage(msg).ConfigureAwait(false); }
private ContactUsViewModel CreateReactModel(ContactUsDataModel contactus) { var contactEnquiries = new List <ContactEnquiryViewModel>(); var ctaSection = new CtaSectionViewModel(); if (contactus.ContactEnquiries != null && contactus.ContactEnquiries.Any()) { foreach (var enquiry in contactus.ContactEnquiries) { var openings = new List <OpeningTimesViewModel>(); foreach (var opening in enquiry.OpeningTimes) { var thisOpenings = new OpeningTimesViewModel { Days = opening.Key, Times = opening.Value }; openings.Add(thisOpenings); } var thisEnquiry = new ContactEnquiryViewModel { Title = enquiry.Title, Phone = enquiry.PhoneNumber, OpeningTimes = openings }; contactEnquiries.Add(thisEnquiry); } var thisCtaSection = new CtaSectionViewModel { IconClass = contactus.Icon != null ? contactus.Icon.Value : string.Empty, Text = contactus.Text, CTALink = contactus.CTALink != null && (contactus.CTALink != null || !string.IsNullOrEmpty(contactus.CTALink.Url)) ? contactus.CTALink.Url : string.Empty, CTAText = contactus.CTALink != null && (contactus.CTALink != null || !string.IsNullOrEmpty(contactus.CTALink.Text)) ? contactus.CTALink.Text : string.Empty }; ctaSection = thisCtaSection; } return(new ContactUsViewModel { WhiteTheme = contactus.WhiteTheme.Equals("1"), VerticalDisplay = contactus.VerticalDisplay.Equals("1"), ContactEnquiries = contactEnquiries, CTASection = ctaSection }); }
public ActionResult Contact(ContactUsDataModel contactUsFormData) { if (ModelState.IsValid) { try { EmailService.SendContactForm(contactUsFormData); return(View("ContactSuccess")); } catch (Exception e) { System.Diagnostics.Trace.TraceError("Contact page post exception message - " + e.Message); return(View("Error")); } } return(View()); }