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);
}