Ejemplo n.º 1
0
        public virtual ActionResult ContactForm(ContactFormViewModel viewModel)
        {
            bool success;
            if (ModelState.IsValid)
            {
                using (var message = new MailMessage())
                {
                    message.From = new MailAddress("*****@*****.**");
                    message.ReplyToList.Add(new MailAddress(viewModel.Email));
                    message.To.Add(new MailAddress(viewModel.EmailTo));
                    message.Subject = string.Format("[Fataco.com] Message from {0}", viewModel.Name);
                    message.IsBodyHtml = true;
                    message.Body = EmailHelper.FormatMessage(viewModel);

                    try
                    {
                        SmtpClient client = new SmtpClient();
                        client.Send(message);
                        success = true;
                    }
                    catch (Exception)
                    {
                        success = false;
                    }
                }
            }
            else
            {
                success = false;
            }
            System.Globalization.CultureInfo c = (System.Globalization.CultureInfo)Session["Culture"];
            if (c.Name == "en")
            {

                return new JsonResult
                {
                    Data = new
                    {
                        success = success,
                        message = success ? "Your message successfully send." : "Sorry there has been an error while sending your message, please try again later."
                    }
                };
            }
            else {

                return new JsonResult
                {
                    Data = new
                    {
                        success = success,
                        message = success ? "Yêu cầu của bạn đã được gởi tới FATACO" : "Xin lổi, Yêu cầu của bạn chưa được gởi đi, vui lòng thử lại lần nữa."
                    }
                };
            }
        }
Ejemplo n.º 2
0
        public static string FormatMessage(ContactFormViewModel contactForm)
        {
            var builder = new StringBuilder();
            builder.AppendFormat("<div>From: {0}</div>", contactForm.Name);
            builder.AppendFormat("<div>Email: {0}</div>", contactForm.Email);

            if (!string.IsNullOrWhiteSpace(contactForm.Message))
            {
                builder.AppendFormat("<div><br/>{0}</div>", contactForm.Message);
            }

            return builder.ToString();
        }
Ejemplo n.º 3
0
        public virtual ActionResult ContactForm(ContactFormViewModel viewModel)
        {
            bool success;
            if (ModelState.IsValid)
            {
                using (var message = new MailMessage())
                {
                    message.From = new MailAddress("*****@*****.**");
                    message.ReplyToList.Add(new MailAddress(viewModel.Email));
                    message.To.Add(new MailAddress(viewModel.EmailTo));
                    message.Subject = string.Format("[BetterCmsDemo.com] Message from {0}", viewModel.Name);
                    message.IsBodyHtml = true;
                    message.Body = EmailHelper.FormatMessage(viewModel);

                    try
                    {
                        SmtpClient client = new SmtpClient();
                        client.Send(message);
                        success = true;
                    }
                    catch (Exception)
                    {
                        success = false;
                    }
                }
            }
            else
            {
                success = false;
            }

            return new JsonResult
            {
                Data = new
                {
                    success = success,
                    message = success ? "Your message successfully send." : "Sorry there has been an error while sending your message, please try again later."
                }
            };
        }