Exemple #1
0
        public async Task <ActionResult> Contact(SendAMessageViewModel sendAMessageViewModel)
        {
            try
            {
                sendAMessageViewModel.PhoneNumber  = Sanitizer.GetSafeHtmlFragment(sendAMessageViewModel.PhoneNumber);
                sendAMessageViewModel.Message      = Sanitizer.GetSafeHtmlFragment(sendAMessageViewModel.Message);
                sendAMessageViewModel.Name         = Sanitizer.GetSafeHtmlFragment(sendAMessageViewModel.Name);
                sendAMessageViewModel.Subject      = Sanitizer.GetSafeHtmlFragment(sendAMessageViewModel.Subject);
                sendAMessageViewModel.EmailAddress = Sanitizer.GetSafeHtmlFragment(sendAMessageViewModel.EmailAddress);

                var messageBuilder = new EmailBuilder()
                {
                    To         = MailingList.ToAllStaff,
                    Subject    = "Inquiry",
                    IsBodyHtml = true,
                    Body       = BuildMailTemplate.CreateContactUsTemplate(sendAMessageViewModel)
                };
                await EmailBuilder.SendEmailAsync(messageBuilder, sendAMessageViewModel.EmailAddress);

                return(Json(new { status = TransactionStatusEnum.success, subject = "Sent", message = "Your message has been sent successfully" }, JsonRequestBehavior.AllowGet));
            }

            catch (Exception ex)
            {
                return(Json(new { status = TransactionStatusEnum.fail, subject = "Failed", message = ex.Message.ToString() }, JsonRequestBehavior.AllowGet));

                //return Json(new { status = TransactionStatusEnum.fail, subject = "Failed", message = "Oops! Something went wrong while sending your message. Please try again" }, JsonRequestBehavior.AllowGet);
            }
        }
        public static string CreateContactUsTemplate(SendAMessageViewModel sendAMessageViewModel)
        {
            string body = string.Empty;

            using (var reader = new StreamReader(HttpContext.Current.Server.MapPath("~/MailTemplates/ContactUsTemplate.html")))
            {
                body = reader.ReadToEnd();
            }
            body = body.Replace("{name}", sendAMessageViewModel.Name);
            body = body.Replace("{email}", (sendAMessageViewModel.EmailAddress != "" ? sendAMessageViewModel.EmailAddress : " Email address not provided"));
            body = body.Replace("{date}", DateTime.Now.Date.ToShortDateString());
            body = body.Replace("{phonenumber}", sendAMessageViewModel.PhoneNumber);
            body = body.Replace("{subject}", sendAMessageViewModel.Subject);
            body = body.Replace("{message}", sendAMessageViewModel.Message);
            return(body);
        }
Exemple #3
0
        public ActionResult Contact()
        {
            var sendAMessageViewModel = new SendAMessageViewModel();

            return(View(sendAMessageViewModel));
        }