void AddTemplates(SpeakerSendMailModel sendMailModel) { var mailTemplates = mailService.GetMailTemplates(); if (mailTemplates.Any()) { var mt = mailTemplates.First(); sendMailModel.TemplateList = new SelectList(mailTemplates, "Id", "Description"); var model = new { sendMailModel.FirstName, sendMailModel.LastName, SpeakerUrl = GetSpeakerUrl(sendMailModel.Id) }; sendMailModel.Subject = mt.Subject.NamedFormat(model); sendMailModel.Body = mt.Body.NamedFormat(model); } }
public ActionResult SendMail(Guid id, SpeakerSendMailModel model) { var speaker = speakerService.GetSpeaker(id); if (string.IsNullOrWhiteSpace(speaker.Contact.EMail)) { ModelState.AddModelError("", "Für den Sprecher ist keine Mail hinterlegt"); } if (ModelState.IsValid) { try { mailService.SendMail(speaker.Contact.EMail, model.Subject, model.Body); return RedirectToAction("Details", new {id}); } catch (Exception e) { ModelState.AddModelError("", string.Format("{0}: {1} ", e.GetType().Name, e.Message)); } } var sendMailModel = speakerService.GetSpeaker(id).MapFrom<Speaker, SpeakerSendMailModel>(); AddTemplates(sendMailModel); return View(sendMailModel); }