public async Task <IEnumerable <EmployerFeedbackRefreshMessage> > GetRefreshData(long accountId) { var mappedUsersTask = GetAccountUsersForFeedback(accountId); var accCommitmentsTask = _commitmentApiClient.GetEmployerApprenticeships(accountId); var accCommitments = await accCommitmentsTask; var commitmentUkprns = accCommitments .GroupBy(acc => acc.ProviderId) .Select(group => group.Key); var providers = await _emailDetailsRepository.GetProvidersByUkprn(commitmentUkprns); var validCommitments = accCommitments .Where(app => app != null) .Where(app => app.HasHadDataLockSuccess == true) .Where(app => app.PaymentStatus == PaymentStatus.Active || app.PaymentStatus == PaymentStatus.Paused) .Where(app => providers.Any(p => p.Ukprn == app.ProviderId)) .GroupBy(app => new { app.EmployerAccountId, app.ProviderId }) .Select(app => app.First()); var mappedUsers = await mappedUsersTask; var messages = validCommitments .SelectMany(c => mappedUsers.Select(mu => new EmployerFeedbackRefreshMessage { ProviderId = c.ProviderId, User = mu })); return(messages); }
private static async Task <List <DAS.Commitments.Api.Types.Apprenticeship.Apprenticeship> > GetApprenticeshipsForAccount(long employerAccountId, IEmployerCommitmentApi employerCommitmentsApi) { var apiApprenticeships = await employerCommitmentsApi.GetEmployerApprenticeships( employerAccountId, new ApprenticeshipSearchQuery { ApprenticeshipStatuses = new List <ApprenticeshipStatus> { ApprenticeshipStatus.WaitingToStart, ApprenticeshipStatus.Live } }) ?? new ApprenticeshipSearchResponse(); var pageNumber = 2; var apprenticeships = apiApprenticeships.Apprenticeships.ToList(); if (apiApprenticeships.TotalPages > 1) { while (pageNumber != apiApprenticeships.TotalPages) { var pageOfApprenticeshipSearchResponse = await employerCommitmentsApi.GetEmployerApprenticeships( employerAccountId, new ApprenticeshipSearchQuery { ApprenticeshipStatuses = new List <ApprenticeshipStatus> { ApprenticeshipStatus.WaitingToStart, ApprenticeshipStatus.Live }, PageNumber = pageNumber }); apprenticeships.AddRange(pageOfApprenticeshipSearchResponse.Apprenticeships); pageNumber++; } } return(apprenticeships); }
public async Task <GetAllApprenticeshipsResponse> Handle(GetAllApprenticeshipsRequest message) { var apprenticeship = await _commitmentsApi.GetEmployerApprenticeships(message.AccountId); return(new GetAllApprenticeshipsResponse { Apprenticeships = apprenticeship.Where(m => m .PaymentStatus != PaymentStatus.PendingApproval) .ToList() }); }
public async Task <ApprenticeshipSearchQueryResponse> Handle(ApprenticeshipSearchQueryRequest message) { var accountId = _hashingService.DecodeValue(message.HashedLegalEntityId); var data = await _commitmentsApi.GetEmployerApprenticeships(accountId, message.Query); return(new ApprenticeshipSearchQueryResponse { Apprenticeships = data.Apprenticeships.ToList(), SearchKeyword = data.SearchKeyword, Facets = data.Facets, TotalApprenticeships = data.TotalApprenticeships, TotalApprenticeshipsBeforeFilter = data.TotalApprenticeshipsBeforeFilter, PageNumber = data.PageNumber, TotalPages = data.TotalPages, PageSize = data.PageSize }); }