public async Task <ActionResult> InformationRequest(InformationRequestModel model) { try { await _notificationService.SendInformationRequestEmail(model, AppSettings.Theme); return(View("SuccessfullRequest")); } catch (Exception) { ViewBag.ErrorMessage = "Hubo un error en la solicitud. Por favor intente nuevamente más tarde"; return(View(model)); } }
private string GetInformationRequestEmailBody(InformationRequestModel request, string theme, string filename) { string body = string.Empty; var templatePath = String.Format("~/EmailTemplates/{0}/{1}.html", theme, filename); using (StreamReader reader = new StreamReader(HttpContext.Current.Server.MapPath(templatePath))) { body = reader.ReadToEnd(); } body = body.Replace("{Name}", request.Name); body = body.Replace("{Date}", String.Format("{0} {1}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString())); body = body.Replace("{Cause}", request.Cause); body = body.Replace("{Text}", request.Text); body = body.Replace("{Email}", request.Email); body = body.Replace("{PhoneNumber}", request.PhoneNumber); body = body.Replace("{webURL}", _urlHelper.BaseFullUrl()); body = body.Replace("{imageURL}", _urlHelper.ContentFullPath(@"~/Content/themes/Jovenes/images/")); return(body); }
public async Task SendInformationRequestEmail(InformationRequestModel request, string theme) { var receivers = ConfigurationManager.AppSettings["RequestInformationReceivers"].Split(','); foreach (var receiver in receivers) { var mail = new MailMessage(ConfigurationManager.AppSettings["EmailSentFrom"], receiver); mail.Subject = "Nueva consulta"; mail.Body = GetInformationRequestEmailBody(request, theme, "InfoRequestToAdminEmail"); mail.IsBodyHtml = true; await _emailService.SendMailAsync(mail); } var mailSuccessfulQuery = new MailMessage(ConfigurationManager.AppSettings["EmailSentFrom"], request.Email); mailSuccessfulQuery.Subject = "Consulta Exitosa"; mailSuccessfulQuery.Body = GetInformationRequestEmailBody(request, theme, "InfoRequestAutomaticResponseEmail"); mailSuccessfulQuery.IsBodyHtml = true; await _emailService.SendMailAsync(mailSuccessfulQuery); }
public ActionResult InformationRequest() { InformationRequestModel model = new InformationRequestModel(); if (PointExContext.User != null) { switch (PointExContext.Role) { case RolesNames.Beneficiary: var beneficiary = _currentUser.Beneficiary; model.Name = beneficiary.Name; break; case RolesNames.Shop: var shop = PointExContext.Shop; model.Name = string.Format("[Shop] {0}", shop.Name); model.PhoneNumber = shop.Phone; break; } model.Email = PointExContext.User.Email; } return(View(model)); }