private IEnumerable <RecipientData> GetRecipients(IEnumerable <RoleType> roles, long clientId) { foreach (var role in roles) { switch (role) { case RoleType.Admin: { var recipients = _admins.GetAll() .Select(user => new RecipientData(user.Email, user.Language, RoleType.Admin)); foreach (var recipient in recipients) { yield return(recipient); } break; } case RoleType.Manager: { var recipients = _managers.GetAll() .Select(user => new RecipientData(user.Email, user.Language, RoleType.Manager)); foreach (var recipient in recipients) { yield return(recipient); } break; } case RoleType.Client: var client = _clients.Get(clientId); foreach (var email in EmailsHelper.SplitAndTrimEmails(client.Emails)) { yield return(new RecipientData(email, client.Language, role)); } break; case RoleType.Sender: case RoleType.Broker: case RoleType.Forwarder: case RoleType.Carrier: throw new NotSupportedException("Only client and admin can be recipient of client event"); default: throw new InvalidOperationException("Unknown role " + role); } } }
public void Send(long applicationId, long userId) { var bill = _bills.Get(applicationId); var application = _applications.Get(applicationId); var subject = string.Format("Счет на оплату № {0} от {1}", bill.Number, bill.SaveDate.ToString("dd MMMM yyyy")); var body = subject; var from = EmailsHelper.DefaultFrom; var to = _admins.GetAll().Select(x => x.Email).ToArray() .Union(EmailsHelper.SplitAndTrimEmails(application.ClientEmails)) .Distinct() .ToArray(); var files = new[] { _pdf.Get(applicationId) }; foreach (var item in to) { _mail.Send(new EmailMessage(subject, body, from, item, userId) { Files = files, }); } }
private IEnumerable <RecipientData> GetRecipients(IEnumerable <RoleType> roles, EventDataForEntity data) { foreach (var role in roles) { switch (role) { case RoleType.Admin: { var recipients = _admins.GetAll() .Select(user => new RecipientData(user.Email, user.Language, RoleType.Admin)); foreach (var recipient in recipients) { yield return(recipient); } } break; case RoleType.Manager: { var recipients = _managers.GetAll() .Select(user => new RecipientData(user.Email, user.Language, RoleType.Manager)); foreach (var recipient in recipients) { yield return(recipient); } } break; case RoleType.Broker: var brokerId = _awbs.Get(data.EntityId).Single().BrokerId; if (brokerId.HasValue) { var broker = _brokers.Get(brokerId.Value); yield return(new RecipientData(broker.Email, broker.Language, role)); } break; case RoleType.Sender: foreach (var email in _awbs.GetSenderEmails(data.EntityId)) { yield return(new RecipientData(email.Email, email.Language, RoleType.Client)); } break; case RoleType.Client: foreach (var emailData in _awbs.GetClientEmails(data.EntityId)) { foreach (var email in EmailsHelper.SplitAndTrimEmails(emailData.Email)) { yield return(new RecipientData(email, emailData.Language, RoleType.Client)); } } break; case RoleType.Forwarder: foreach (var email in _awbs.GetForwarderEmails(data.EntityId)) { yield return(new RecipientData(email.Email, email.Language, RoleType.Client)); } break; case RoleType.Carrier: foreach (var email in _awbs.GetCarrierEmails(data.EntityId)) { yield return(new RecipientData(email.Email, email.Language, RoleType.Client)); } break; default: throw new InvalidOperationException("Unknown role " + role); } } }
public EmailMessage(string subject, string body, string from, string to, long?emailSenderUserId) : this(subject, body, from, EmailsHelper.SplitAndTrimEmails(to), emailSenderUserId) { }
private IEnumerable <RecipientData> GetRecipients(ApplicationData application, IEnumerable <RoleType> roles) { foreach (var role in roles) { switch (role) { case RoleType.Admin: foreach ( var recipient in _admins.GetAll().Select(user => new RecipientData(user.Email, user.Language, RoleType.Admin))) { yield return(recipient); } break; case RoleType.Manager: foreach ( var recipient in _managers.GetAll().Select(user => new RecipientData(user.Email, user.Language, RoleType.Manager))) { yield return(recipient); } break; case RoleType.Sender: if (application.SenderId.HasValue) { var sender = _senders.Get(application.SenderId.Value); yield return(new RecipientData(sender.Email, sender.Language, role)); } break; case RoleType.Broker: if (application.AirWaybillId.HasValue) { var awb = _awbs.Get(application.AirWaybillId.Value).Single(); if (awb.BrokerId.HasValue) { var broker = _brokers.Get(awb.BrokerId.Value); yield return(new RecipientData(broker.Email, broker.Language, role)); } } break; case RoleType.Forwarder: var forwarder = _forwarders.Get(application.ForwarderId); yield return(new RecipientData(forwarder.Email, forwarder.Language, role)); break; case RoleType.Carrier: var carrier = _carriers.Get(application.CarrierId); yield return(new RecipientData(carrier.Email, carrier.Language, role)); break; case RoleType.Client: var client = _clients.Get(application.ClientId); foreach (var email in EmailsHelper.SplitAndTrimEmails(client.Emails)) { yield return(new RecipientData(email, client.Language, role)); } break; default: throw new InvalidOperationException("Unknown role " + role); } } }