Beispiel #1
0
        public async Task <IDraftApprenticeshipViewModel> Map(EditDraftApprenticeshipRequest source)
        {
            var cohort = source.Cohort;

            var draftApprenticeship = await _commitmentsApiClient.GetDraftApprenticeship(source.Request.CohortId, source.Request.DraftApprenticeshipId);

            return(new EditDraftApprenticeshipViewModel(draftApprenticeship.DateOfBirth, draftApprenticeship.StartDate, draftApprenticeship.EndDate)
            {
                DraftApprenticeshipId = draftApprenticeship.Id,
                DraftApprenticeshipHashedId = _encodingService.Encode(draftApprenticeship.Id, EncodingType.ApprenticeshipId),
                CohortId = source.Request.CohortId,
                CohortReference = _encodingService.Encode(source.Request.CohortId, EncodingType.CohortReference),
                ReservationId = draftApprenticeship.ReservationId,
                FirstName = draftApprenticeship.FirstName,
                LastName = draftApprenticeship.LastName,
                Uln = draftApprenticeship.Uln,
                CourseCode = draftApprenticeship.CourseCode,
                Cost = draftApprenticeship.Cost,
                Reference = draftApprenticeship.Reference,
                AccountHashedId = source.Request.AccountHashedId,
                ProviderName = cohort.ProviderName,
                LegalEntityName = source.Cohort.LegalEntityName,
                IsContinuation = draftApprenticeship.IsContinuation,
                Courses = (cohort.IsFundedByTransfer || cohort.LevyStatus == ApprenticeshipEmployerType.NonLevy) && !draftApprenticeship.IsContinuation
                    ? (await _commitmentsApiClient.GetAllTrainingProgrammeStandards()).TrainingProgrammes
                    : (await _commitmentsApiClient.GetAllTrainingProgrammes()).TrainingProgrammes
            });
        }
        public async Task Handle(TransferRequestRejectedEvent message, IMessageHandlerContext context)
        {
            var cohortSummary = await _mediator.Send(new GetCohortSummaryQuery(message.CohortId));

            var cohortReference = _encodingService.Encode(cohortSummary.CohortId, EncodingType.CohortReference);

            var sendEmailToEmployerCommand = new SendEmailToEmployerCommand(cohortSummary.AccountId,
                                                                            "SenderRejectedCommitmentEmployerNotification", new Dictionary <string, string>
            {
                { "employer_name", cohortSummary.LegalEntityName },
                { "cohort_reference", cohortReference },
                { "sender_name", cohortSummary.TransferSenderName },
                { "employer_hashed_account", _encodingService.Encode(cohortSummary.AccountId, EncodingType.AccountId) },
            },
                                                                            cohortSummary.LastUpdatedByEmployerEmail);

            var sendEmailToProviderCommand = new SendEmailToProviderCommand(cohortSummary.ProviderId.Value,
                                                                            "SenderRejectedCommitmentProviderNotification",
                                                                            new Dictionary <string, string>
            {
                { "cohort_reference", cohortReference },
                { "ukprn", cohortSummary.ProviderId.Value.ToString() },
            },
                                                                            cohortSummary.LastUpdatedByProviderEmail);

            await Task.WhenAll(
                context.Send(sendEmailToProviderCommand, new SendOptions()),
                context.Send(sendEmailToEmployerCommand, new SendOptions())
                );
        }
        public async Task <IActionResult> EmployerManage(ReservationsRouteModel routeModel)
        {
            var reservations = new List <ReservationViewModel>();

            var decodedAccountId   = _encodingService.Decode(routeModel.EmployerAccountId, EncodingType.AccountId);
            var reservationsResult = await _mediator.Send(new GetReservationsQuery { AccountId = decodedAccountId });

            foreach (var reservation in reservationsResult.Reservations)
            {
                var accountLegalEntityPublicHashedId = _encodingService.Encode(reservation.AccountLegalEntityId,
                                                                               EncodingType.PublicAccountLegalEntityId);

                var apprenticeUrl = reservation.Status == ReservationStatus.Pending && !reservation.IsExpired
                    ? _urlHelper.GenerateAddApprenticeUrl(
                    reservation.Id,
                    accountLegalEntityPublicHashedId,
                    reservation.Course.Id,
                    routeModel.UkPrn,
                    reservation.StartDate,
                    routeModel.CohortReference,
                    routeModel.EmployerAccountId)
                    : string.Empty;

                var viewModel = new ReservationViewModel(reservation, apprenticeUrl, routeModel.UkPrn);
                reservations.Add(viewModel);
            }

            return(View(ViewNames.EmployerManage, new ManageViewModel
            {
                Reservations = reservations,
                BackLink = _urlHelper.GenerateDashboardUrl(routeModel.EmployerAccountId)
            }));
        }
        public async Task <IActionResult> ChooseEmployer(ReservationsRouteModel routeModel)
        {
            if (!routeModel.UkPrn.HasValue)
            {
                throw new ArgumentException("UkPrn must be set", nameof(ReservationsRouteModel.UkPrn));
            }

            var getTrustedEmployersResponse = await _mediator.Send(new GetTrustedEmployersQuery { UkPrn = routeModel.UkPrn.Value });


            var eoiEmployers = new List <AccountLegalEntity>();

            foreach (var employer in getTrustedEmployersResponse.Employers)
            {
                employer.AccountLegalEntityPublicHashedId = _encodingService.Encode(employer.AccountLegalEntityId,
                                                                                    EncodingType.PublicAccountLegalEntityId);
                eoiEmployers.Add(employer);
            }

            var viewModel = new ChooseEmployerViewModel
            {
                Employers = eoiEmployers
            };

            return(View(viewModel));
        }
Beispiel #5
0
        public async Task Handle(CohortTransferApprovalRequestedEvent message, IMessageHandlerContext context)
        {
            await _mediator.Send(new AddTransferRequestCommand { CohortId = message.CohortId, LastApprovedByParty = message.LastApprovedByParty });

            var cohortSummary = await _mediator.Send(new GetCohortSummaryQuery(message.CohortId));

            if (message.LastApprovedByParty == Party.Employer)
            {
                //send "TransferPendingFinalApproval" to the Provider to go here
            }
            else if (message.LastApprovedByParty == Party.Provider)
            {
                var tokens = new Dictionary <string, string>
                {
                    { "provider_name", cohortSummary.ProviderName },
                    { "sender_name", cohortSummary.TransferSenderName },
                    { "employer_hashed_account", _encodingService.Encode(cohortSummary.AccountId, EncodingType.AccountId) },
                    { "cohort_reference", _encodingService.Encode(cohortSummary.CohortId, EncodingType.CohortReference) }
                };

                await context.Send(new SendEmailToEmployerCommand(cohortSummary.AccountId,
                                                                  "EmployerTransferPendingFinalApproval", tokens,
                                                                  cohortSummary.LastUpdatedByEmployerEmail));
            }
        }
        public async Task Handle(CohortAssignedToEmployerEvent message, IMessageHandlerContext context)
        {
            if (message.AssignedBy != Party.Provider)
            {
                return;
            }

            var cohortSummary = await _mediator.Send(new GetCohortSummaryQuery(message.CohortId));

            if (cohortSummary.ChangeOfPartyRequestId.HasValue)
            {
                return;
            }

            var tokens = new Dictionary <string, string>
            {
                { "provider_name", cohortSummary.ProviderName },
                { "employer_hashed_account", _encodingService.Encode(cohortSummary.AccountId, EncodingType.AccountId) },
                { "cohort_reference", _encodingService.Encode(cohortSummary.CohortId, EncodingType.CohortReference) }
            };

            await context.Send(new SendEmailToEmployerCommand(cohortSummary.AccountId,
                                                              "EmployerCohortNotification",
                                                              tokens, cohortSummary.LastUpdatedByEmployerEmail));
        }
        public async Task <DetailsViewModel> Map(DetailsRequest source)
        {
            GetCohortResponse cohort;

            Task <bool> IsAgreementSigned(long accountLegalEntityId)
            {
                var request = new AgreementSignedRequest
                {
                    AccountLegalEntityId = accountLegalEntityId
                };

                if (cohort.IsFundedByTransfer)
                {
                    request.AgreementFeatures = new AgreementFeature[] { AgreementFeature.Transfers };
                }

                return(_commitmentsApiClient.IsAgreementSigned(request));
            }

            var cohortTask = _commitmentsApiClient.GetCohort(source.CohortId);
            var draftApprenticeshipsTask = _commitmentsApiClient.GetDraftApprenticeships(source.CohortId);
            var emailOverlapsTask        = _commitmentsApiClient.GetEmailOverlapChecks(source.CohortId);

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

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

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

            var viewOrApprove     = cohort.WithParty == CommitmentsV2.Types.Party.Employer ? "Approve" : "View";
            var isAgreementSigned = await IsAgreementSigned(cohort.AccountLegalEntityId);

            return(new DetailsViewModel
            {
                AccountHashedId = source.AccountHashedId,
                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.LatestMessageCreatedByProvider,
                Courses = courses,
                PageTitle = draftApprenticeships.Count == 1
                    ? $"{viewOrApprove} apprentice details"
                    : $"{viewOrApprove} {draftApprenticeships.Count} apprentices' details",
                IsApprovedByProvider = cohort.IsApprovedByProvider,
                IsAgreementSigned = isAgreementSigned,
                IsCompleteForEmployer = cohort.IsCompleteForEmployer,
                HasEmailOverlaps = emailOverlaps.Any(),
                ShowAddAnotherApprenticeOption = !cohort.IsLinkedToChangeOfPartyRequest
            });
        }
        public Task ProviderAmendedCohort(Commitment commitment)
        {
            var tokens = CreateDictionaryWithCommonTokens(commitment);

            tokens["provider_name"]           = commitment.ProviderName;
            tokens["employer_hashed_account"] = _encodingService.Encode(commitment.EmployerAccountId, EncodingType.AccountId);

            var command = new SendEmailToEmployerCommand(commitment.EmployerAccountId, AmendedTemplate, tokens, commitment.LastUpdatedByEmployerEmail);

            return(SendCommandAndLog(command, $"Provider: {commitment.ProviderId} CohortId: {commitment.Id} LastAction: {commitment.LastAction}"));
        }
Beispiel #9
0
        public async Task <IChangeEmployerViewModel> Map(ChangeEmployerRequest source)
        {
            var changeOfPartyRequest = (await _commitmentsApiClient.GetChangeOfPartyRequests(source.ApprenticeshipId))
                                       .ChangeOfPartyRequests.FirstOrDefault(x => x.OriginatingParty == Party.Provider &&
                                                                             x.ChangeOfPartyType == ChangeOfPartyRequestType.ChangeEmployer &&
                                                                             (x.Status == ChangeOfPartyRequestStatus.Pending || x.Status == ChangeOfPartyRequestStatus.Approved));

            var apprenticeDetails = await _commitmentsApiClient.GetApprenticeship(source.ApprenticeshipId);

            if (changeOfPartyRequest != null)
            {
                var priceEpisodes = await _commitmentsApiClient.GetPriceEpisodes(source.ApprenticeshipId);

                var cohortReference = changeOfPartyRequest.CohortId.HasValue
                    ? _encodingService.Encode(changeOfPartyRequest.CohortId.Value, EncodingType.CohortReference)
                    : string.Empty;

                return(new ChangeEmployerRequestDetailsViewModel
                {
                    ApprenticeshipHashedId = source.ApprenticeshipHashedId,
                    ProviderId = source.ProviderId,
                    ApprenticeshipId = source.ApprenticeshipId,
                    Price = changeOfPartyRequest.Price.GetValueOrDefault(),
                    StartDate = changeOfPartyRequest.StartDate.GetValueOrDefault(),
                    EndDate = changeOfPartyRequest.EndDate.GetValueOrDefault(),
                    EmployerName = changeOfPartyRequest.EmployerName,
                    CurrentEmployerName = apprenticeDetails.EmployerName,
                    CurrentStartDate = apprenticeDetails.StartDate,
                    CurrentEndDate = apprenticeDetails.EndDate,
                    CurrentPrice = priceEpisodes.PriceEpisodes.GetPrice(),
                    CohortId = changeOfPartyRequest.CohortId,
                    CohortReference = cohortReference,
                    WithParty = changeOfPartyRequest.WithParty,
                    Status = changeOfPartyRequest.Status,
                    EncodedNewApprenticeshipId = changeOfPartyRequest.NewApprenticeshipId.HasValue
                        ? _encodingService.Encode(changeOfPartyRequest.NewApprenticeshipId.Value,
                                                  EncodingType.ApprenticeshipId)
                        : string.Empty
                });
            }
            else
            {
                return(new InformViewModel
                {
                    ApprenticeshipHashedId = source.ApprenticeshipHashedId,
                    ProviderId = source.ProviderId,
                    ApprenticeshipId = source.ApprenticeshipId,
                    LegalEntityName = apprenticeDetails.EmployerName
                });
            }
        }
Beispiel #10
0
        public Task <ICollection <TransferConnectionViewModel> > GetTransferConnections(string accountHashedId)
        {
            const int fundingEmployerAccountId = 456;
            ICollection <TransferConnectionViewModel> transferConnections = new List <TransferConnectionViewModel>();

            transferConnections.Add(new TransferConnectionViewModel
            {
                FundingEmployerAccountId             = fundingEmployerAccountId,
                FundingEmployerAccountName           = "Stubs Funding",
                FundingEmployerHashedAccountId       = _encodingService.Encode(fundingEmployerAccountId, EncodingType.AccountId),
                FundingEmployerPublicHashedAccountId = _encodingService.Encode(fundingEmployerAccountId, EncodingType.PublicAccountId)
            });

            return(Task.FromResult(transferConnections));
        }
        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)
            });
        }
        public async Task <AddCohortResult> Handle(AddCohortCommand command, CancellationToken cancellationToken)
        {
            var db = _dbContext.Value;

            var draftApprenticeshipDetails = await _draftApprenticeshipDetailsMapper.Map(command);

            var cohort = await _cohortDomainService.CreateCohort(command.ProviderId,
                                                                 command.AccountId,
                                                                 command.AccountLegalEntityId,
                                                                 command.TransferSenderId,
                                                                 draftApprenticeshipDetails,
                                                                 command.UserInfo,
                                                                 cancellationToken);

            db.Cohorts.Add(cohort);
            await db.SaveChangesAsync(cancellationToken);

            //this encoding and re-save could be removed and put elsewhere
            cohort.Reference = _encodingService.Encode(cohort.Id, EncodingType.CohortReference);
            await db.SaveChangesAsync(cancellationToken);

            _logger.LogInformation($"Saved cohort. Provider: {command.ProviderId} Account-Legal-Entity:{command.AccountLegalEntityId} Reservation-Id:{command.ReservationId} Commitment-Id:{cohort.Id} Apprenticeship:{cohort.Apprenticeships?.FirstOrDefault()?.Id}");

            var response = new AddCohortResult
            {
                Id        = cohort.Id,
                Reference = cohort.Reference
            };

            return(response);
        }
Beispiel #13
0
        public async Task <IActionResult> Index(Guid uniqueCode)
        {
            var idClaim = HttpContext.User.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier);    //System.Security.Claims.ClaimTypes.NameIdentifier

            var employerEmailDetail = await _employerEmailDetailsRepository.GetEmployerInviteForUniqueCode(uniqueCode);

            if (employerEmailDetail == null)
            {
                _logger.LogWarning($"Attempt to use invalid unique code: {uniqueCode}");
                return(NotFound());
            }

            var providerAttributes = await _employerEmailDetailsRepository.GetAllAttributes();

            if (providerAttributes == null)
            {
                _logger.LogError($"Unable to load Provider Attributes from the database.");
                return(RedirectToAction("Error", "Error"));
            }

            var providerAttributesModel = providerAttributes.Select(s => new ProviderAttributeModel {
                Name = s.AttributeName
            });
            var newSurveyModel = MapToNewSurveyModel(employerEmailDetail, providerAttributesModel);

            newSurveyModel.UniqueCode = uniqueCode;
            await _sessionService.Set(idClaim.Value, newSurveyModel);

            var encodedAccountId = _encodingService.Encode(employerEmailDetail.AccountId, EncodingType.AccountId);

            return(RedirectToRoute(RouteNames.Landing_Get_New, new { encodedAccountId = encodedAccountId }));
        }
Beispiel #14
0
        public async Task <ViewChangesViewModel> Map(ViewChangesRequest source)
        {
            var apprenticeshipTask           = _client.GetApprenticeship(source.ApprenticeshipId);
            var changeOfProviderRequestsTask = _client.GetChangeOfPartyRequests(source.ApprenticeshipId);
            var priceHistoryTask             = _client.GetPriceEpisodes(source.ApprenticeshipId);

            await Task.WhenAll(apprenticeshipTask, changeOfProviderRequestsTask, priceHistoryTask);

            var apprenticeship           = apprenticeshipTask.Result;
            var changeOfProviderRequests = changeOfProviderRequestsTask.Result;
            var priceHistory             = priceHistoryTask.Result;

            var pendingChangeRequest = changeOfProviderRequests.ChangeOfPartyRequests.FirstOrDefault(r => r.Status == ChangeOfPartyRequestStatus.Pending && r.ChangeOfPartyType == ChangeOfPartyRequestType.ChangeProvider);

            var newProvider = await _client.GetProvider(pendingChangeRequest.ProviderId.Value);

            var result = new ViewChangesViewModel
            {
                AccountHashedId        = source.AccountHashedId,
                ApprenticeshipHashedId = source.ApprenticeshipHashedId,
                ApprenticeName         = $"{apprenticeship.FirstName} {apprenticeship.LastName}",
                CurrentProviderName    = apprenticeship.ProviderName,
                CurrentStartDate       = apprenticeship.StartDate,
                CurrentEndDate         = apprenticeship.EndDate,
                CurrentPrice           = priceHistory.PriceEpisodes.GetPrice(),
                NewProviderName        = newProvider.Name,
                NewStartDate           = pendingChangeRequest.StartDate,
                NewEndDate             = pendingChangeRequest.EndDate,
                NewPrice        = pendingChangeRequest.Price,
                CurrentParty    = pendingChangeRequest.WithParty.Value,
                CohortReference = _encodingService.Encode(pendingChangeRequest.CohortId.Value, EncodingType.CohortReference)
            };

            return(result);
        }
Beispiel #15
0
        public async Task <WithTransferSenderViewModel> Map(CohortsByAccountRequest source)
        {
            var cohortsResponse = await _commitmentsApiClient.GetCohorts(new GetCohortsRequest { AccountId = source.AccountId });

            var reviewViewModel = new WithTransferSenderViewModel
            {
                Title           = Title,
                AccountHashedId = source.AccountHashedId,
                ApprenticeshipRequestsHeaderViewModel = cohortsResponse.Cohorts.GetCohortCardLinkViewModel(_urlHelper, source.AccountHashedId, CohortStatus.WithTransferSender),
                Cohorts = cohortsResponse.Cohorts
                          .Where(x => x.GetStatus() == CohortStatus.WithTransferSender)
                          .OrderBy(GetOrderByDate)
                          .Select(y => new WithTransferSenderCohortSummaryViewModel
                {
                    TransferSenderId    = y.TransferSenderId.Value,
                    TransferSenderName  = y.TransferSenderName,
                    CohortReference     = _encodingService.Encode(y.CohortId, EncodingType.CohortReference),
                    ProviderName        = y.ProviderName,
                    NumberOfApprentices = y.NumberOfDraftApprentices,
                }).ToList()
            };

            if (reviewViewModel.Cohorts?.GroupBy(x => x.TransferSenderId).Count() > 1)
            {
                reviewViewModel.Title += "s";
            }

            return(reviewViewModel);
        }
Beispiel #16
0
        public async Task Trigger(short periodMonth, int periodYear, string periodEnd, long accountId)
        {
            try
            {
                var triggerMessage = new PaymentDataCompleteTrigger
                {
                    EmployerAccountIds = new List <string> {
                        _encodingService.Encode(accountId, EncodingType.AccountId)
                    },
                    PeriodYear  = periodYear,
                    PeriodMonth = periodMonth,
                    PeriodId    = periodEnd
                };

                var response = await _httpFunctionClient.PostAsync(_configuration.PaymentPreLoadHttpFunctionBaseUrl, triggerMessage);

                if (!response.IsSuccessStatusCode)
                {
                    _logger.LogError($"Failed to trigger Payment PreLoad HttpTriggerFunction for AccountId: { accountId}, PeriodEnd: { periodEnd}. Status Code: {response.StatusCode}");
                    throw new Exception($"Status Code: {response.StatusCode}, reason: {response.ReasonPhrase}");
                }

                _logger.LogInformation($"Successfully triggered Payment PreLoad HttpTriggerFunction for AccountId: { accountId}, PeriodEnd: { periodEnd}, Status Code: {response.StatusCode}");
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Failed to trigger Payment PreLoad HttpTriggerFunction for AccountId: {accountId}, PeriodEnd: {periodEnd}");
                throw;
            }
        }
Beispiel #17
0
        private async Task <LegalEntityViewModel> GetLegalEntity(long accountId, long maLegalEntityId)
        {
            var hashedAccountId = _encodingService.Encode(accountId, EncodingType.AccountId);
            var legalEntity     = await _accountApiClient.GetLegalEntity(hashedAccountId, maLegalEntityId);

            return(legalEntity);
        }
Beispiel #18
0
        public async Task <WithTrainingProviderViewModel> Map(CohortsByAccountRequest source)
        {
            var cohortsResponse = await _commitmentsApiClient.GetCohorts(new GetCohortsRequest { AccountId = source.AccountId });

            var reviewViewModel = new WithTrainingProviderViewModel
            {
                Title           = Title,
                AccountHashedId = source.AccountHashedId,
                ApprenticeshipRequestsHeaderViewModel = cohortsResponse.Cohorts.GetCohortCardLinkViewModel(_urlHelper, source.AccountHashedId, CohortStatus.WithProvider),
                Cohorts = cohortsResponse.Cohorts
                          .Where(x => x.GetStatus() == CohortStatus.WithProvider)
                          .OrderBy(z => z.LatestMessageFromEmployer != null ? z.LatestMessageFromEmployer.SentOn : z.CreatedOn)
                          .Select(y => new WithTrainingProviderCohortSummaryViewModel
                {
                    ProviderId          = y.ProviderId,
                    CohortReference     = _encodingService.Encode(y.CohortId, EncodingType.CohortReference),
                    ProviderName        = y.ProviderName,
                    NumberOfApprentices = y.NumberOfDraftApprentices,
                    LastMessage         = GetMessage(y.LatestMessageFromEmployer)
                }).ToList()
            };

            if (reviewViewModel.Cohorts?.GroupBy(x => x.ProviderId).Count() > 1)
            {
                reviewViewModel.Title += "s";
            }

            return(reviewViewModel);
        }
Beispiel #19
0
 public string Encode(
     [Service] IEncodingService encodingService,
     string value,
     EncodingType type)
 {
     return(encodingService.Encode(value, type));
 }
Beispiel #20
0
        public async Task <AddCohortResult> Handle(AddCohortWithOtherPartyCommand command, CancellationToken cancellationToken)
        {
            var db = _dbContext.Value;

            var cohort = await _cohortDomainService.CreateCohortWithOtherParty(command.ProviderId,
                                                                               command.AccountId,
                                                                               command.AccountLegalEntityId,
                                                                               command.TransferSenderId,
                                                                               command.Message,
                                                                               command.UserInfo,
                                                                               cancellationToken);

            db.Cohorts.Add(cohort);
            await db.SaveChangesAsync(cancellationToken);

            //this encoding and re-save could be removed and put elsewhere
            cohort.Reference = _encodingService.Encode(cohort.Id, EncodingType.CohortReference);
            await db.SaveChangesAsync(cancellationToken);

            _logger.LogInformation($"Saved cohort with other party. Provider: {command.ProviderId} Account-Legal-Entity:{command.AccountLegalEntityId} Commitment-Id:{cohort.Id}");

            var response = new AddCohortResult
            {
                Id        = cohort.Id,
                Reference = cohort.Reference
            };

            return(response);
        }
Beispiel #21
0
        public async Task <AddDraftApprenticeshipViewModel> Map(AddDraftApprenticeshipRequest source)
        {
            var cohort = await _commitmentsApiClient.GetCohort(source.CohortId);

            if (cohort.WithParty != Party.Employer)
            {
                throw new CohortEmployerUpdateDeniedException($"Cohort {cohort} is not with the Employer");
            }

            var result = new AddDraftApprenticeshipViewModel
            {
                AccountHashedId            = source.AccountHashedId,
                CohortReference            = source.CohortReference,
                CohortId                   = source.CohortId,
                AccountLegalEntityHashedId = source.AccountLegalEntityHashedId,
                AccountLegalEntityId       = source.AccountLegalEntityId,
                LegalEntityName            = cohort.LegalEntityName,
                ReservationId              = source.ReservationId,
                StartDate                  = new MonthYearModel(source.StartMonthYear),
                CourseCode                 = source.CourseCode,
                ProviderName               = cohort.ProviderName,
                Courses = cohort.IsFundedByTransfer || cohort.LevyStatus == ApprenticeshipEmployerType.NonLevy
                    ? (await _commitmentsApiClient.GetAllTrainingProgrammeStandards()).TrainingProgrammes
                    : (await _commitmentsApiClient.GetAllTrainingProgrammes()).TrainingProgrammes,
                TransferSenderHashedId = cohort.IsFundedByTransfer ? _encodingService.Encode(cohort.TransferSenderId.Value, EncodingType.PublicAccountId) : string.Empty,
                AutoCreatedReservation = source.AutoCreated
            };

            return(result);
        }
        public async Task <DraftViewModel> Map(CohortsByAccountRequest source)
        {
            var request = new GetCohortsRequest {
                AccountId = source.AccountId
            };
            var apiResponse = await _commitmentsApiClient.GetCohorts(request);

            var cohorts = apiResponse.Cohorts
                          .Where(x => x.GetStatus() == CohortStatus.Draft)
                          .OrderByDescending(x => x.CreatedOn)
                          .Select(x => new DraftCohortSummaryViewModel
            {
                ProviderName        = x.ProviderName,
                CohortReference     = _encodingService.Encode(x.CohortId, EncodingType.CohortReference),
                NumberOfApprentices = x.NumberOfDraftApprentices,
            }).ToList();

            return(new DraftViewModel
            {
                AccountHashedId = source.AccountHashedId,
                ApprenticeshipRequestsHeaderViewModel = apiResponse.Cohorts.GetCohortCardLinkViewModel(_urlHelper, source.AccountHashedId, CohortStatus.Draft),
                AccountId = source.AccountId,
                Cohorts = cohorts
            });
        }
Beispiel #23
0
        public async Task <ChooseCohortViewModel> Map(ChooseCohortByProviderRequest source)
        {
            var cohortsResponse = await _commitmentsApiClient.GetCohorts(new GetCohortsRequest { ProviderId = source.ProviderId }) ??
                                  new GetCohortsResponse(new List <CohortSummary>());

            var filterModel = new ChooseCohortFilterModel
            {
                ReverseSort = source.ReverseSort,
                SortField   = source.SortField
            };

            var cohorts = cohortsResponse.Cohorts
                          .Where(x => (x.GetStatus() == CohortStatus.Draft || x.GetStatus() == CohortStatus.Review) && !x.IsLinkedToChangeOfPartyRequest)
                          .Select(y => new ChooseCohortSummaryViewModel
            {
                EmployerName        = y.LegalEntityName,
                CohortReference     = _encodingService.Encode(y.CohortId, EncodingType.CohortReference),
                Status              = y.GetStatus() == CohortStatus.Review ? "Ready to review" : "Draft",
                NumberOfApprentices = y.NumberOfDraftApprentices,
                AccountLegalEntityPublicHashedId = y.AccountLegalEntityPublicHashedId,
                CreatedOn = y.CreatedOn
            }).ToList();

            var sortedCohorts = GetSortedCohorts(filterModel, cohorts);

            var chooseCohortViewModel = new ChooseCohortViewModel
            {
                ProviderId  = source.ProviderId,
                Cohorts     = sortedCohorts,
                FilterModel = filterModel
            };

            return(chooseCohortViewModel);
        }
Beispiel #24
0
        public async Task <IActionResult> Manage(ReservationsRouteModel routeModel)
        {
            var    employerAccountIds = new List <long>();
            var    reservations       = new List <ReservationViewModel>();
            string viewName;

            if (routeModel.UkPrn.HasValue)
            {
                var trustedEmployersResponse = await _mediator.Send(new GetTrustedEmployersQuery { UkPrn = routeModel.UkPrn.Value });

                if (!trustedEmployersResponse.Employers.Any())
                {
                    return(View("NoPermissions"));
                }

                employerAccountIds.AddRange(trustedEmployersResponse.Employers.Select(employer => employer.AccountId));
                viewName = ViewNames.ProviderManage;
            }
            else
            {
                var decodedAccountId = _encodingService.Decode(routeModel.EmployerAccountId, EncodingType.AccountId);
                employerAccountIds.Add(decodedAccountId);
                viewName = ViewNames.EmployerManage;
            }

            foreach (var employerAccountId in employerAccountIds)
            {
                var reservationsResult = await _mediator.Send(new GetReservationsQuery { AccountId = employerAccountId });

                foreach (var reservation in reservationsResult.Reservations)
                {
                    var accountLegalEntityPublicHashedId = _encodingService.Encode(reservation.AccountLegalEntityId,
                                                                                   EncodingType.PublicAccountLegalEntityId);

                    var apprenticeUrl = reservation.Status == ReservationStatus.Pending && !reservation.IsExpired
                        ? _urlHelper.GenerateAddApprenticeUrl(
                        reservation.Id,
                        accountLegalEntityPublicHashedId,
                        reservation.Course.Id,
                        routeModel.UkPrn,
                        reservation.StartDate,
                        routeModel.CohortReference,
                        routeModel.EmployerAccountId)
                        : string.Empty;

                    var viewModel = new ReservationViewModel(reservation, apprenticeUrl, routeModel.UkPrn);

                    reservations.Add(viewModel);
                }
            }

            return(View(viewName, new ManageViewModel
            {
                Reservations = reservations,
                BackLink = _urlHelper.GenerateDashboardUrl(routeModel.EmployerAccountId)
            }));
        }
Beispiel #25
0
        private async Task <LegalEntity> GetAssociatedLegalEntity(UpdatedPermissionsEvent message)
        {
            var employerAccountId = _encoder.Encode(message.AccountId, EncodingType.AccountId);
            var legalEntities     = await _employerAccountProvider.GetLegalEntitiesConnectedToAccountAsync(employerAccountId);

            var legalEntity = legalEntities.FirstOrDefault(le => le.AccountLegalEntityId == message.AccountLegalEntityId);

            return(legalEntity == null ? null : LegalEntityMapper.MapFromAccountApiLegalEntity(legalEntity));
        }
Beispiel #26
0
        private async Task SendEmployerEmail(IMessageHandlerContext context, GetCohortSummaryQueryResult cohortSummary)
        {
            var tokens = new Dictionary <string, string>
            {
                { "provider_name", cohortSummary.ProviderName },
                { "employer_hashed_account", _encodingService.Encode(cohortSummary.AccountId, EncodingType.AccountId) },
                { "cohort_reference", _encodingService.Encode(cohortSummary.CohortId, EncodingType.CohortReference) }
            };

            var templateName = cohortSummary.LevyStatus == Types.ApprenticeshipEmployerType.Levy
                ? TemplateApproveNewEmployerDetailsLevy
                : TemplateApproveNewEmployerDetailsNonLevy;

            await context.Send(new SendEmailToEmployerCommand(cohortSummary.AccountId,
                                                              templateName,
                                                              tokens));

            _logger.LogInformation($"Sent SendEmailToEmployerCommand with template: {templateName}");
        }
        public async Task <IActionResult> AddDraftApprenticeship(AddDraftApprenticeshipViewModel model)
        {
            var addDraftApprenticeshipRequest = await _modelMapper.Map <CommitmentsV2.Api.Types.Requests.AddDraftApprenticeshipRequest>(model);

            var response = await _commitmentsApiClient.AddDraftApprenticeship(model.CohortId.Value, addDraftApprenticeshipRequest);

            var draftApprenticeshipHashedId = _encodingService.Encode(response.DraftApprenticeshipId, EncodingType.ApprenticeshipId);

            return(RedirectToAction("SelectOption", "DraftApprenticeship", new { model.AccountHashedId, model.CohortReference, draftApprenticeshipHashedId }));
        }
        private async Task ValidateTransferSenderIdIsAFundingConnection(long accountId, long transferSenderId)
        {
            var hashedAccountId    = _encodingService.Encode(accountId, EncodingType.AccountId);
            var fundingConnections = await _accountApiClient.GetTransferConnections(hashedAccountId);

            if (fundingConnections.Any(x => x.FundingEmployerAccountId == transferSenderId))
            {
                return;
            }
            throw new BadRequestException($"TransferSenderId {transferSenderId} is not a FundingEmployer for Account {accountId}");
        }
Beispiel #29
0
        private void PrintAttribute()
        {
            IHashingProvider hashingProvider = ObjectLocator.GetInstance <IHashingProvider>();
            IEncodingService encodingService = ObjectLocator.GetInstance <IEncodingService>();

            string dllCheckHash = encodingService.Encode(hashingProvider.HashFile(Directory.GetCurrentDirectory() + "\\lib\\WaveTech.Scutex.Licensing.dll"));
            string publicKey    = encodingService.Encode(UIContext.License.KeyPair.PublicKey);

            if (rdoCodeTypeCSharp.IsChecked.HasValue && rdoCodeTypeCSharp.IsChecked.Value)
            {
                txtAttribute.Text = string.Format("[assembly: License(\"{0}\",\"{1}\")]", publicKey, dllCheckHash);
            }
            else
            {
                txtAttribute.Text = string.Format("<Assembly: License(\"{0}\",\"{1}\")>", publicKey, dllCheckHash);
            }

            txtParam1.Text = publicKey;
            txtParam2.Text = dllCheckHash;
        }
 public static string EncodeSafe(this IEncodingService encodingService, long value, EncodingType encodingType)
 {
     try
     {
         return(encodingService.Encode(value, encodingType));
     }
     catch (Exception)
     {
         return("#Error");
     }
 }