public IHttpActionResult Post(EmailRecipientsModel model) { if (model.SendDate == null) { model.SendDate = DateTime.Now; } if (model.To == null) { model.To = new List <EmailAddress>(); } if (model.UserId != null) { foreach (int recipientid in model.UserId) { var user = db.User.Where(u => u.Id == recipientid).FirstOrDefault(); if (user != null) { model.To.Add(new EmailAddress { Address = user.Email, DisplayName = user.Name }); } } } var recipients = model.To.Select(t => new EmailToSendAddress { EmailAddress = t.Address, DisplayName = t.DisplayName }).ToList(); if (recipients.Count > 0) { var EmailToSend = new EmailToSend { Body = model.Body, Subject = model.Subject, SendDate = model.SendDate.Value, IsSent = false, CreatedDate = DateTime.Now, EmailAddress = recipients, Retry = 0 }; db.EmailToSend.Add(EmailToSend); db.SaveChanges(); return(Ok(EmailToSend.Id)); } return(NotFound()); }
public ActionResult EmailRecipients(EmailRecipientsModel model) { return(View()); }