Esempio n. 1
0
        public ActionResult Contact(ContactViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                //dynamic table = new Prospect();
                //dynamic o = new ExpandoObject();
                //{
                //    o.Email = viewModel.Email;
                //    o.Address1 = viewModel.Address1;
                //    o.Address2 = viewModel.Address2;
                //    o.City = viewModel.City;
                //    o.State = viewModel.State;
                //    o.Zip = viewModel.Zip;
                //    o.Phone = viewModel.Phone;
                //    o.Name = viewModel.Name;
                //    o.Company = viewModel.Company;
                //    o.Comment = viewModel.Comment;
                //    o.IpAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                //}
                //table.Insert(o);
                try
                {
                    SendEmail(viewModel);
                }
                catch
                {
                }
             //   return RedirectToAction("Contact", "Home");

            }
            ModelState.AddModelError(string.Empty, "Oops,  " + string.Join(" ; ", ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage)));
            return View(viewModel);
        }
        public void ContactShouldReturnCorrectViewModel()
        {
            HeaderViewModel header = new HeaderViewModel()
            {
                Heading = ContactHeading,
                SubHeading = ContactSubHeading
            };

            ContactViewModel contactModel = new ContactViewModel()
            {
                Header = header
            };

            var controller = new StaticPagesController();
            var result = controller.Contact() as ViewResult;
            Assert.AreEqual(contactModel.Header.Heading, (result.Model as ContactViewModel).Header.Heading);
            Assert.AreEqual(contactModel.Header.SubHeading, (result.Model as ContactViewModel).Header.SubHeading);
            Assert.AreEqual(contactModel.Header.BackgroundUrl, (result.Model as ContactViewModel).Header.BackgroundUrl);
        }
Esempio n. 3
0
        protected void SendEmail(ContactViewModel viewModel)
        {
            var to = ConfigurationManager.AppSettings["EmailSendTo"];
            var smtpEmailAddres = ConfigurationManager.AppSettings["SmtpEmailAddres"];
            var smtpEmailPassword = ConfigurationManager.AppSettings["SmtpEmailPassword"];

            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("name:{0}          <br/>email:{1}        <br/>phone:{2}         <br/>Comments:{3}   ",
                viewModel.Name, viewModel.Email, viewModel.Phone, viewModel.Comment);

            var client = new SmtpClient("smtp.gmail.com", 587)
            {
                Credentials = new NetworkCredential(smtpEmailAddres, smtpEmailPassword),
                EnableSsl = true
            };
            client.Send(smtpEmailAddres, to, "Vista Woodworking Website contact lead", sb.ToString());
            //Response.Redirect("../Public/Thankyou.aspx");
        }