AspNetEmailExample.Models.MailRecipientsViewModel.getSelectedRecipientIds C# (CSharp) Method

getSelectedRecipientIds() public method

public getSelectedRecipientIds ( ) : IEnumerable
return IEnumerable
        public IEnumerable<int> getSelectedRecipientIds()
        {
            return (from r in this.MailRecipients
                    where r.Selected
                    select r.MailRecipientId).ToList();
        }

Usage Example

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