public async Task <IEnumerable <EmployerAccountUser> > GetAccountUsers(long accountId)
        {
            var teamMembers = await _accountApiClient.GetAccountUsers(accountId);

            var users = teamMembers.Select(model => (EmployerAccountUser)model);

            return(users);
        }
        public async Task <TeamMember> GetUserRoleOnAccount(string accountId, string userId)
        {
            var accounts = await _client.GetAccountUsers(accountId);

            if (accounts == null || !accounts.Any())
            {
                return(null);
            }

            var teamMember = accounts.FirstOrDefault(c => c.UserRef.Equals(userId, StringComparison.CurrentCultureIgnoreCase));

            if (teamMember == null)
            {
                return(null);
            }

            Role usrRoleResult;

            Enum.TryParse(teamMember.Role, true, out usrRoleResult);

            return(new TeamMember
            {
                HashedAccountId = accountId,
                Email = teamMember.Email,
                UserRef = teamMember.UserRef,
                Role = usrRoleResult
            });
        }
Exemplo n.º 3
0
        private async Task <IEnumerable <ProviderUser> > GetProvider(long ukprn)
        {
            var users = await _emailService.GetUsersAsync(ukprn);

            if (users == null)
            {
                _logger.Warn($"Can't find and user for provider {ukprn}.");
                return(new List <ProviderUser>());
            }

            var accountUserResult = (await _retryPolicy.ExecuteAndCaptureAsync(() => _providerAccountClient.GetAccountUsers(ukprn)));
            var accountUser       = accountUserResult.Result?.ToArray();

            foreach (var user in users)
            {
                var u = accountUser
                        ?.FirstOrDefault(m => user.Email.Trim().ToLower() == m.EmailAddress.Trim()
                                         ?.ToLower());

                user.ReceiveNotifications = u == null || u.ReceiveNotifications;
                user.Ukprn = ukprn;
            }

            return(users);
        }
        public async Task <IEnumerable <UserDetails> > GetAccountUsers(long accountId)
        {
            var teamMembers = await _accountApiClient.GetAccountUsers(accountId);

            var users = teamMembers.Select <TeamMemberViewModel, UserDetails>(model => model);

            return(users);
        }
        private async Task <IEnumerable <User> > GetAccountUsersForFeedback(long accountId)
        {
            var users = await _accountApiClient.GetAccountUsers(accountId);

            return(users
                   .Where(au => au.CanReceiveNotifications)
                   .Select(au => MapTeamMemberToUser(au, accountId)));
        }
        private async Task <string> getUserRole(EmployerIdentifier employerAccount, string userId)
        {
            var accounts = await _accountApiClient.GetAccountUsers(employerAccount.AccountId);

            if (accounts == null || !accounts.Any())
            {
                return(null);
            }
            var teamMember = accounts.FirstOrDefault(c => String.Equals(c.UserRef, userId, StringComparison.CurrentCultureIgnoreCase));

            return(teamMember?.Role);
        }
        private async Task <ICollection <TeamMemberViewModel> > GetAccountTeamMembers(string resultHashedAccountId)
        {
            try
            {
                _logger.Debug(
                    $"{nameof(IAccountApiClient)}.{nameof(_accountApiClient.GetAccountUsers)}(\"{resultHashedAccountId}\");");
                var teamMembers = await _accountApiClient.GetAccountUsers(resultHashedAccountId);

                return(teamMembers);
            }
            catch (Exception e)
            {
                _logger.Error(e, $"Account Team Member with id {resultHashedAccountId} not found");
                return(new List <TeamMemberViewModel>());
            }
        }
        public async Task Handle(SendEmailToEmployerCommand message, IMessageHandlerContext context)
        {
            bool IsOwnerOrTransactor(string role)
            {
                return(role.Equals(Owner, StringComparison.InvariantCultureIgnoreCase) ||
                       role.Equals(Transactor, StringComparison.InvariantCultureIgnoreCase));
            }

            try
            {
                _logger.LogInformation($"Getting AccountUsers for {message.AccountId}");

                var emails = new List <string>();
                var users  = await _accountApiClient.GetAccountUsers(message.AccountId);

                if (string.IsNullOrWhiteSpace(message.EmailAddress))
                {
                    _logger.LogInformation("Sending emails to all AccountUsers who can recieve emails");
                    emails.AddRange(users.Where(x =>
                                                x.CanReceiveNotifications && !string.IsNullOrWhiteSpace(x.Email) &&
                                                IsOwnerOrTransactor(x.Role))
                                    .Select(x => x.Email));
                }
                else if (users.Any(x => message.EmailAddress.Equals(x.Email, StringComparison.InvariantCultureIgnoreCase) &&
                                   x.CanReceiveNotifications))
                {
                    _logger.LogInformation("Sending email to the explicit user in message");
                    emails.Add(message.EmailAddress);
                }

                if (emails.Any())
                {
                    _logger.LogInformation($"Calling SendEmailCommand for {emails.Count()} emails");
                    await Task.WhenAll(emails.Select(email =>
                                                     context.Send(new SendEmailCommand(message.Template, email, message.Tokens))));
                }
                else
                {
                    _logger.LogWarning($"No Email Addresses found to send Template {message.Template} for AccountId {message.AccountId}");
                }
            }
            catch (Exception e)
            {
                _logger.LogError($"Error processing {nameof(SendEmailToEmployerCommand)}", e);
                throw;
            }
        }
        private async Task <UserModel> ToUserModel(long accountId)
        {
            var usersResult = await _retryPolicy.ExecuteAndCaptureAsync(() => _accountApi.GetAccountUsers(accountId));

            if (usersResult.Outcome == OutcomeType.Failure)
            {
                _logger.Error(usersResult.FinalException, $"Unable to get employer users for account: {accountId} from account api");
            }
            if (usersResult.Result == null || !usersResult.Result.Any())
            {
                _logger.Warn($"No users found for account: {accountId}");
            }

            return(new UserModel
            {
                AccountId = accountId,
                Users = usersResult.Result
            });
        }
        public async Task <IEnumerable <MembershipContext> > GetMemberships(string hashedAccountId)
        {
            try
            {
                var users = await _accountApiClient.GetAccountUsers(hashedAccountId).ConfigureAwait(false);

                return
                    (users
                     .Select(m => new MembershipContext
                {
                    HashedAccountId = hashedAccountId,
                    UserEmail = m.Email,
                    UserRef = m.UserRef
                }));
            }
            catch (Exception ex)
            {
                _logger.Warn(ex, $"Unable to find users for account {hashedAccountId}");
                return(new List <MembershipContext>());
            }
        }
Exemplo n.º 11
0
        public async Task <GetUserAccountRoleResponse> Handle(GetUserAccountRoleQuery request, CancellationToken cancellationToken)
        {
            var accounts = await _client.GetAccountUsers(request.HashedAccountId);

            if (accounts == null || !accounts.Any())
            {
                return(null);
            }

            var teamMember = accounts.FirstOrDefault(c => c.UserRef.Equals(request.UserId, StringComparison.CurrentCultureIgnoreCase));

            if (teamMember == null)
            {
                return(null);
            }

            return(new GetUserAccountRoleResponse()
            {
                Role = teamMember.Role
            });
        }
 public async Task <ICollection <TeamMemberViewModel> > GetAccountUsers(string accountId)
 {
     return(await _inner.GetAccountUsers(accountId));
 }