public ActionResult Index(HomePageViewModel model) { if (!string.IsNullOrEmpty(Request.Form["hdnorderNow"]) && ModelState.IsValid) { // They're going ahead with the order, save their quote for reference? /*Quote newQuote = new Quote * { * Cost = model.HomePageQuoteViewModel.Cost, * IsMetro = model.HomePageQuoteViewModel.IsMetro, * Quantity = model.HomePageQuoteViewModel.Quantity * }; * db.Quotes.Add(newQuote); * db.SaveChanges();*///Removed for now HttpContext.Session["homePageModel"] = model.HomePageQuoteViewModel; return(RedirectToAction("Create", "Orders", new { prepopulated = true })); } if (!string.IsNullOrEmpty(Request.Form["hdnemailQuote"]) && ModelState.IsValid) { EmailQuotes model1 = new EmailQuotes(); HttpContext.Session["homePageModel1"] = model.HomePageQuoteViewModel; return(View("EmailQuote", model1)); } return(View()); }
public async Task <ActionResult> EmailQuote(EmailQuotes model1) { { InstantQuoteViewModel model = (InstantQuoteViewModel)HttpContext.Session["homePageModel1"]; if (ModelState.IsValid && (model.NeedsPrint == true)) { var url = @"\home\index"; var linkText = "Click here"; var body = "Hi {6}, </br><p>Here is your quote: </p></br><p>Quantity: {0}</p><p>Metro Area: {1}</p><p>Is printing required: {2}" + "</p><p>Print Size: {3}</p><p>Double Sided: {4}</p><p>Price: {5}</p></br><p>Thank you for your interest. Please reply to this email to place an order.</p><p>Kind Regards,</p>SG Fast Flyers."; string attach = Server.MapPath(@"\Content\Documents\SGFastFlyers_Letterbox_Printing_&_Delivery_Details.pdf"); string href = String.Format("<a href='{0}'>{1}</a>", url, linkText); string yourEncodedHtml = "Quote Sent Successfully.<br/>" + href + " to send another one if you like.<br/><p>Have a great day.<p/>"; var html = new MvcHtmlString(yourEncodedHtml); var message = new MailMessage(); message.To.Add(new MailAddress(model1.Email)); // replace with valid value message.Bcc.Add(new MailAddress(Config.sgEmail)); message.From = new MailAddress(Config.sgEmail); // replace with valid value message.Subject = "Your Quote"; message.Body = string.Format(body, model.Quantity, (model.IsMetro == true ? Config.Yes : Config.No), (model.NeedsPrint == true ? Config.Yes : Config.No), model.PrintSize, (model.IsDoubleSided == true ? Config.Yes : Config.No), model.FormattedCost, model1.FirstName); message.IsBodyHtml = true; message.Attachments.Add(new Attachment(attach)); try { using (SmtpClient smtp = new SmtpClient()) { smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.SpecifiedPickupDirectory; await smtp.SendMailAsync(message); } ViewBag.Status = html; ModelState.Clear(); } catch (Exception) { ViewBag.Status = "Problem while sending email, Please check details."; } } if (ModelState.IsValid && (model.NeedsPrint == false)) { var url = @"\home\index"; var linkText = "Click here"; var body = "Hi {0}, </br><p>Here is your quote: </p></br><p>Quantity: {1}</p><p>Metro Area: {2}</p>" + "<p>Price: {3}</p></br><p>Thank you for your interest. Please reply to this email to place an order.</p><p>Kind Regards,</p>SG Fast Flyers."; string attach = Server.MapPath(@"\Content\Documents\SGFastFlyers_Letterbox_Printing_&_Delivery_Details.pdf"); string href = String.Format("<a href='{0}'>{1}</a>", url, linkText); string yourEncodedHtml = "Quote Sent Successfully.<br/>" + href + " to send another one if you like.<br/><p>Have a great day.<p/>"; var html = new MvcHtmlString(yourEncodedHtml); var message = new MailMessage(); message.To.Add(new MailAddress(model1.Email)); // replace with valid value message.Bcc.Add(new MailAddress(Config.sgEmail)); message.From = new MailAddress(Config.sgEmail); // replace with valid value message.Subject = "Your Quote"; message.Body = string.Format(body, model1.FirstName, model.Quantity, (model.IsMetro == true ? Config.Yes : Config.No), model.FormattedCost); message.IsBodyHtml = true; message.Attachments.Add(new Attachment(attach)); try { using (SmtpClient smtp = new SmtpClient()) { await smtp.SendMailAsync(message); } ViewBag.Status = html; ModelState.Clear(); } catch (Exception) { ViewBag.Status = "Problem while sending email, Please check details."; } } return(View()); } }