public async Task <ActionResult> SendMail(WheelYourBalanceSendMailModel model) { if (ModelState.IsValid) { try { var id = Save(model.Name, model.Email); if (id != Guid.Empty) { if (SaveWheel(id)) { var template = System.IO.File.ReadAllText(Path.Combine(Server.MapPath("~/Content/EmailTemplates/WheelYourBalance"), "Index.html")); template = template.Replace("{Name}", model.Name); template = template.Replace("{ImagePath}", $"http://natagerman.ru/Content/WheelYourBalance/{id}.png"); var wheel = (WheelYourBalanceViewModel)Session["WheelYourBalance"]; var wData = string.Empty; for (var i = 0; i < wheel.Spheres.Count; i++) { wData += $"<tr>"; wData += $"<td style='color: {wheel.Spheres.ToList()[i].Color};'>"; wData += $"{wheel.Spheres.ToList()[i].Name}: "; wData += "</td>"; wData += $"<td style='color: {wheel.Spheres.ToList()[i].Color};'>"; wData += $"{(double)wheel.Spheres.ToList()[i].Questions.Sum(x => x.Mark) / wheel.Spheres.ToList()[i].Questions.Count}"; wData += "</td>"; wData += "</tr>"; } template = template.Replace("{wData}", wData); await MessageUtil.SendEmailAsync(model.Email, "Благодарим за прохождение теста! [результат внутри]", "Ваше колесо баланса", template); Session["WheelYourBalance"] = null; return(RedirectToAction("SendMailSuccess", model)); } else { ModelState.AddModelError("", "Что то пошло не так!"); } } } catch (Exception e) { Console.WriteLine(e); } } return(View(model)); }
public ActionResult SendMailSuccess(WheelYourBalanceSendMailModel model) { return(View(model)); }