public JsonResult SendEmailToClients(DestinataryTypeViewModel model) { try { if (ModelState.IsValid) { IEnumerable <String> emails = this.FindDestinatariesByCategory(model); Session["DestinatariesEmails"] = emails; String template = Session["FinalTemplate"].ToString(); if (emails.Count() == 0) { return(Json(new { Result = "NOOK_EMPTY", Redirect = string.Empty, Error = "El grupo seleccionado aún no posee destinatarios", Description = string.Empty })); } if (!String.IsNullOrEmpty(template)) { SendGridMailing sg = new SendGridMailing(); sg.Execute(template, emails.Distinct().ToList()); } return(Json(new { Result = "OK", Redirect = "/Emails/ThankYouPage", Error = string.Empty, Description = string.Empty })); } return(Json(new { Result = "NOOK", Redirect = string.Empty, Error = "Debe seleccionar al menos un grupo como destinatario", Description = string.Empty })); } catch (Exception ex) { return(Json(new { Result = "NOOK", Redirect = string.Empty, Error = "Ha surgido un error inesperado. Por favor vuelva a intentar", Description = ex.Message })); } }
public ActionResult Create(Client client) { if (clientRepository.IsEmailAlreadyInUse(client)) { ModelState.AddModelError("Email", "El email ya está en uso"); } else if (ModelState.IsValid) { var password = client.Password; clientRepository.HashPassword(client); clientRepository.InsertClient(client); clientRepository.Save(); SendGridMailing sg = new SendGridMailing(); var templatePath = Server.MapPath(@"~/Templates/EmailBienvenida.html"); sg.Execute(templatePath, client.Email, password); return(RedirectToAction("Index", new { sortOrder = string.Empty, searchString = string.Empty })); } return(View(client)); }