public async Task <DetailsViewModel> Map(DetailsRequest source)
        {
            GetCohortResponse cohort;

            var cohortTask = _commitmentsApiClient.GetCohort(source.CohortId);
            var draftApprenticeshipsTask = _commitmentsApiClient.GetDraftApprenticeships(source.CohortId);
            var agreementStatusTask      = _pasAccountsApiClient.GetAgreement(source.ProviderId);
            var emailOverlapsTask        = _commitmentsApiClient.GetEmailOverlapChecks(source.CohortId);

            await Task.WhenAll(cohortTask, draftApprenticeshipsTask, agreementStatusTask, emailOverlapsTask);

            cohort = await cohortTask;
            var draftApprenticeships = (await draftApprenticeshipsTask).DraftApprenticeships;
            var agreementStatus      = await agreementStatusTask;
            var emailOverlaps        = (await emailOverlapsTask).ApprenticeshipEmailOverlaps.ToList();

            var courses = await GroupCourses(draftApprenticeships, emailOverlaps, cohort);

            var viewOrApprove     = cohort.WithParty == Party.Provider ? "Approve" : "View";
            var isAgreementSigned = agreementStatus.Status == PAS.Account.Api.Types.ProviderAgreementStatus.Agreed;

            return(new DetailsViewModel
            {
                ProviderId = source.ProviderId,
                CohortReference = source.CohortReference,
                WithParty = cohort.WithParty,
                AccountLegalEntityHashedId = _encodingService.Encode(cohort.AccountLegalEntityId, EncodingType.PublicAccountLegalEntityId),
                LegalEntityName = cohort.LegalEntityName,
                ProviderName = cohort.ProviderName,
                TransferSenderHashedId = cohort.TransferSenderId == null ? null : _encodingService.Encode(cohort.TransferSenderId.Value, EncodingType.PublicAccountId),
                EncodedPledgeApplicationId = cohort.PledgeApplicationId == null ? null : _encodingService.Encode(cohort.PledgeApplicationId.Value, EncodingType.PledgeApplicationId),
                Message = cohort.LatestMessageCreatedByEmployer,
                Courses = courses,
                PageTitle = draftApprenticeships.Count > 1
                    ? $"{viewOrApprove} {draftApprenticeships.Count} apprentices' details"
                    : $"{viewOrApprove} apprentice details",
                IsApprovedByEmployer = cohort.IsApprovedByEmployer,
                IsAgreementSigned = isAgreementSigned,
                IsCompleteForProvider = cohort.IsCompleteForProvider,
                HasEmailOverlaps = emailOverlaps.Any(),
                ShowAddAnotherApprenticeOption = !cohort.IsLinkedToChangeOfPartyRequest,
                AllowBulkUpload = cohort.LevyStatus == ApprenticeshipEmployerType.Levy &&
                                  cohort.WithParty == Party.Provider &&
                                  !cohort.IsLinkedToChangeOfPartyRequest,
                IsLinkedToChangeOfPartyRequest = cohort.IsLinkedToChangeOfPartyRequest,
                Status = GetCohortStatus(cohort, draftApprenticeships)
            });
        }
Exemple #2
0
        public async Task <CohortsViewModel> Map(CohortsByProviderRequest source)
        {
            async Task <(CohortSummary[] Cohorts, bool HasRelationship, ProviderAgreementStatus providerAgreementStatus)> GetData()
            {
                var getCohortsTask = _commitmentsApiClient.GetCohorts(new GetCohortsRequest {
                    ProviderId = source.ProviderId
                });
                var hasRelationshipTask = _providerRelationshipsApiClient.HasRelationshipWithPermission(new HasRelationshipWithPermissionRequest {
                    Ukprn = source.ProviderId, Operation = Operation.CreateCohort
                });
                var providerAgreement = _pasAccountApiClient.GetAgreement(source.ProviderId);

                await Task.WhenAll(getCohortsTask, hasRelationshipTask, providerAgreement);

                return(getCohortsTask.Result.Cohorts, hasRelationshipTask.Result, providerAgreement.Result.Status);
            }

            var data = await GetData();

            return(new CohortsViewModel
            {
                ProviderId = source.ProviderId,
                ShowDrafts = (data.HasRelationship),
                CohortsInDraft = new CohortCardLinkViewModel(
                    data.Cohorts.Count(x => x.GetStatus() == CohortStatus.Draft),
                    "drafts",
                    _urlHelper.Action("Draft", "Cohort", new { source.ProviderId }),
                    CohortStatus.Draft.ToString()),
                CohortsInReview = new CohortCardLinkViewModel(
                    data.Cohorts.Count(x => x.GetStatus() == CohortStatus.Review),
                    "ready to review",
                    _urlHelper.Action("Review", "Cohort", new { source.ProviderId }),
                    CohortStatus.Review.ToString()),
                CohortsWithEmployer = new CohortCardLinkViewModel(
                    data.Cohorts.Count(x => x.GetStatus() == CohortStatus.WithEmployer),
                    "with employers",
                    _urlHelper.Action("WithEmployer", "Cohort", new { source.ProviderId }),
                    CohortStatus.WithEmployer.ToString()),
                CohortsWithTransferSender = new CohortCardLinkViewModel(
                    data.Cohorts.Count(x => x.GetStatus() == CohortStatus.WithTransferSender),
                    "with transfer sending employers",
                    _urlHelper.Action("WithTransferSender", "Cohort", new { source.ProviderId }),
                    CohortStatus.WithTransferSender.ToString()),
                IsAgreementSigned = data.providerAgreementStatus == ProviderAgreementStatus.Agreed
            });
        }
        public async Task <WithTransferSenderViewModel> Map(CohortsByProviderRequest source)
        {
            async Task <(CohortSummary[] Cohorts, bool HasRelationship, ProviderAgreementStatus providerAgreementStatus)>
            GetData()
            {
                var getCohortsTask = _commitmentsApiClient.GetCohorts(new GetCohortsRequest {
                    ProviderId = source.ProviderId
                });
                var hasRelationshipTask = _providerRelationshipsApiClient.HasRelationshipWithPermission(new HasRelationshipWithPermissionRequest {
                    Ukprn = source.ProviderId, Operation = Operation.CreateCohort
                });
                var providerAgreement = _pasAccountApiClient.GetAgreement(source.ProviderId);

                await Task.WhenAll(getCohortsTask, hasRelationshipTask);

                return(getCohortsTask.Result.Cohorts, hasRelationshipTask.Result, providerAgreement.Result.Status);
            }

            var(cohorts, hasRelationship, providerAgreementStatus) = await GetData();

            var reviewViewModel = new WithTransferSenderViewModel
            {
                ProviderId  = source.ProviderId,
                SortField   = source.SortField,
                ReverseSort = source.ReverseSort,
                ApprenticeshipRequestsHeaderViewModel = cohorts.GetCohortCardLinkViewModel(_urlHelper, source.ProviderId, CohortStatus.WithTransferSender, hasRelationship, providerAgreementStatus),
                Cohorts = cohorts
                          .Where(x => x.GetStatus() == CohortStatus.WithTransferSender)
                          .Select(y => new WithTransferSenderCohortSummaryViewModel
                {
                    CohortReference     = _encodingService.Encode(y.CohortId, EncodingType.CohortReference),
                    EmployerName        = y.LegalEntityName,
                    NumberOfApprentices = y.NumberOfDraftApprentices,
                    DateSentToEmployer  = GetOrderByDate(y)
                })
                          .ApplyOrder(source.SortField, source.ReverseSort)
                          .ToList()
            };

            return(reviewViewModel);
        }