public async Task SendEmailToAllProviderRecipients(long providerId, ProviderEmailRequest message) { List <string> recipients; var accountUsers = (await _accountOrchestrator.GetAccountUsers(providerId)).ToList(); if (message.ExplicitEmailAddresses != null && message.ExplicitEmailAddresses.Any()) { _logger.Info("Explicit recipients requested for email"); recipients = message.ExplicitEmailAddresses.ToList(); } else { recipients = accountUsers.Any(u => !u.IsSuperUser) ? accountUsers.Where(x => !x.IsSuperUser).Select(x => x.EmailAddress).ToList() : accountUsers.Select(x => x.EmailAddress).ToList(); } var optedOutList = accountUsers.Where(x => !x.ReceiveNotifications).Select(x => x.EmailAddress).ToList(); var finalRecipients = recipients.Where(x => !optedOutList.Any(y => x.Equals(y, StringComparison.CurrentCultureIgnoreCase))) .ToList(); var commands = finalRecipients.Select(x => new SendNotificationCommand { Email = CreateEmailForRecipient(x, message) }); await Task.WhenAll(commands.Select(x => _mediator.Send(x))); _logger.Info($"Sent email to {finalRecipients.Count} recipients for ukprn: {providerId}", providerId); }
public async Task GetAccountUsers_WhenAccountDoesntExist_ThrowsException() { Repository = new Mock <IAccountRepository>(); Orchestrator = new AccountOrchestrator(Repository.Object); await Assert.ThrowsAsync <AccountNotFoundException>( async() => await Orchestrator.GetAccountUsers(Account.Id)); }
public async Task <IActionResult> GetUsers(Guid accountId) { var accounts = await Orchestrator.GetAccountUsers(accountId); return(Ok(accounts)); }