// GET: MailRecipients public async Task <ActionResult> Index() { var model = new MailRecipientsViewModel(); // Get a list of all the recipients: var recipients = await db.MailRecipients.ToListAsync(); foreach (var item in recipients) { // Put the relevant data into the ViewModel: var newRecipient = new SelectRecipientEditorViewModel() { MailRecipientId = item.MailRecipientId, FullName = item.FullName, Company = item.Company, Email = item.Email, LastMailedDate = item.getLastEmailDate().HasValue ? item.getLastEmailDate().Value.ToShortDateString() : "", Selected = true }; // Add to the list contained by the "wrapper" ViewModel: model.MailRecipients.Add(newRecipient); } // Pass to the view and return: return(View(model)); }
public async Task <ActionResult> Index() { var model = new MailRecipientsViewModel(); var recipients = await db.MailRecipients.ToListAsync(); foreach (var item in recipients) { var newRecipient = new SelectRecipientEditorViewModel() { MailRecipientId = item.MailRecipientId, Email = item.Email, LastMailedDate = item.getLastEmailDate().HasValue ? item.getLastEmailDate().Value.ToShortDateString():"", Selected = true }; model.MailRecipients.Add(newRecipient); } return(View(model)); }
public ActionResult SendMail(MailRecipientsViewModel recipients) { // Retrieve the ids of the recipients selected: var selectedIds = recipients.getSelectedRecipientIds(); // Grab the recipient records: var selectedMailRecipients = this.LoadRecipientsFromIds(selectedIds); // Build the message container for each: var messageContainers = this.createRecipientMailMessages(selectedMailRecipients); // Send the mail: var sender = new MailSender(); var sent = sender.SendMail(messageContainers); // Save a record of each mail sent: this.SaveSentMail(sent); // Reload the index form: return(RedirectToAction("Index")); }
public ActionResult SendMail(MailRecipientsViewModel recipients) { //// Retrieve the ids of the recipients selected: //var selectedIds = recipients.getSelectedRecipientIds(); //// Grab the recipient records: //var selectedMailRecipients = this.LoadRecipientsFromIds(selectedIds); //// Build the message container for each: //var messageContainers = this.createRecipientMailMessages(selectedMailRecipients); //// Send the mail: //var sender = new MailSender(); //var sent = sender.SendMail(messageContainers); //// Save a record of each mail sent: //this.SaveSentMail(sent); //// Reload the index form: //return RedirectToAction("Index"); // Mail-sending code will happen here . . . System.Threading.Thread.Sleep(2000); return(RedirectToAction("Index")); }
public ActionResult SendMail(MailRecipientsViewModel recipients) { System.Threading.Thread.Sleep(2000); return(RedirectToAction("Index")); }