public async Task <OrchestratorResponse <UpdateApprenticeshipViewModel> > GetConfirmChangesModel(
            string hashedAccountId, string hashedApprenticeshipId, string externalUserId,
            ApprenticeshipViewModel apprenticeship)
        {
            //todo: could pick up first 2 params from apprenticeship
            var accountId        = HashingService.DecodeValue(hashedAccountId);
            var apprenticeshipId = HashingService.DecodeValue(hashedApprenticeshipId);

            Logger.Debug($"Getting confirm change model: {accountId}, ApprenticeshipId: {apprenticeshipId}");

            return(await CheckUserAuthorization(async() =>
            {
                await AssertApprenticeshipStatus(accountId, apprenticeshipId);

                var data = await Mediator.SendAsync(new GetApprenticeshipQueryRequest
                {
                    AccountId = accountId,
                    ApprenticeshipId = apprenticeshipId
                });

                var apprenticeships = _apprenticeshipMapper.CompareAndMapToApprenticeshipViewModel(data.Apprenticeship,
                                                                                                   apprenticeship);

                return new OrchestratorResponse <UpdateApprenticeshipViewModel>
                {
                    Data = await apprenticeships
                };
            }, hashedAccountId, externalUserId));
        }
        GetOrchestratorResponseUpdateApprenticeshipViewModelFromCookie(string hashedAccountId,
                                                                       string hashedApprenticeshipId)
        {
            var mappedModel = _apprenticeshipsViewModelCookieStorageService.Get(CookieName);

            var apprenticeshipId = HashingService.DecodeValue(hashedApprenticeshipId);
            var accountId        = HashingService.DecodeValue(hashedAccountId);

            var apprenticeshipResult = await Mediator.SendAsync(
                new GetApprenticeshipQueryRequest
            {
                AccountId        = accountId,
                ApprenticeshipId = apprenticeshipId
            });

            var apprenticeship = _apprenticeshipMapper.MapToApprenticeshipDetailsViewModel(apprenticeshipResult.Apprenticeship);

            mappedModel.OriginalApprenticeship = apprenticeship;
            mappedModel.HashedAccountId        = hashedAccountId;
            mappedModel.HashedApprenticeshipId = hashedApprenticeshipId;

            return(new OrchestratorResponse <UpdateApprenticeshipViewModel> {
                Data = mappedModel
            });
        }
        public async Task <OrchestratorResponse <ApprenticeshipDetailsViewModel> > GetApprenticeship(string hashedAccountId, string hashedApprenticeshipId, string externalUserId)
        {
            var accountId        = HashingService.DecodeValue(hashedAccountId);
            var apprenticeshipId = HashingService.DecodeValue(hashedApprenticeshipId);

            Logger.Info(
                $"Getting On-programme apprenticeships Provider: {accountId}, ApprenticeshipId: {apprenticeshipId}");

            return(await CheckUserAuthorization(async() =>
            {
                var data = await Mediator.SendAsync(
                    new GetApprenticeshipQueryRequest {
                    AccountId = accountId, ApprenticeshipId = apprenticeshipId
                });

                var detailsViewModel =
                    _apprenticeshipMapper.MapToApprenticeshipDetailsViewModel(data.Apprenticeship);

                detailsViewModel.PendingDataLockRestart = data.Apprenticeship.DataLockCourseTriaged;
                detailsViewModel.PendingDataLockChange = data.Apprenticeship.DataLockPriceTriaged || data.Apprenticeship.DataLockCourseChangeTriaged;

                return new OrchestratorResponse <ApprenticeshipDetailsViewModel> {
                    Data = detailsViewModel
                };
            }, hashedAccountId, externalUserId));
        }
        public async Task UpdateStopDate(string hashedAccountId, string hashedApprenticeshipId, EditApprenticeshipStopDateViewModel model, string externalUserId, string userName, string userEmail)
        {
            var accountId        = HashingService.DecodeValue(hashedAccountId);
            var apprenticeshipId = HashingService.DecodeValue(hashedApprenticeshipId);

            Logger.Info($"Updating Apprenticeship stop date. AccountId: {accountId}, ApprenticeshipId: {apprenticeshipId}");

            await CheckUserAuthorization(async() =>
            {
                var data =
                    await
                    Mediator.SendAsync(new GetApprenticeshipQueryRequest
                {
                    AccountId        = accountId,
                    ApprenticeshipId = apprenticeshipId
                });

                await Mediator.SendAsync(new UpdateApprenticeshipStopDateCommand
                {
                    UserId            = externalUserId,
                    ApprenticeshipId  = apprenticeshipId,
                    EmployerAccountId = accountId,
                    NewStopDate       = model.NewStopDate.DateTime.Value,
                    UserEmailAddress  = userEmail,
                    UserDisplayName   = userName,
                    CommitmentId      = data.Apprenticeship.CommitmentId
                });
            }, hashedAccountId, externalUserId);
        }
Exemple #5
0
        public async Task <FinishEditingViewModel> GetFinishEditing(long providerId, string hashedCommitmentId)
        {
            var commitmentId = HashingService.DecodeValue(hashedCommitmentId);

            Logger.Info($"Get info for finish editing options for provider:{providerId} commitment:{commitmentId}", providerId: providerId, commitmentId: commitmentId);

            var commitment = await GetCommitment(providerId, commitmentId);

            AssertCommitmentStatus(commitment, EditStatus.ProviderOnly);
            AssertCommitmentStatus(commitment, AgreementStatus.EmployerAgreed, AgreementStatus.ProviderAgreed, AgreementStatus.NotAgreed);

            var overlaps = await Mediator.Send(
                new GetOverlappingApprenticeshipsQueryRequest
            {
                Apprenticeship = commitment.Apprenticeships
            });

            return(new FinishEditingViewModel
            {
                HashedCommitmentId = hashedCommitmentId,
                ProviderId = providerId,
                ReadyForApproval = commitment.CanBeApproved,
                ApprovalState = GetApprovalState(commitment),
                HasApprenticeships = commitment.Apprenticeships.Any(),
                InvalidApprenticeshipCount = commitment.Apprenticeships.Count(x => !x.CanBeApproved),
                HasSignedTheAgreement = await IsSignedAgreement(providerId) == ProviderAgreementStatus.Agreed,
                SignAgreementUrl = _configuration.ContractAgreementsUrl,
                HasOverlappingErrors = overlaps.Overlaps.Any()
            });
        }
        public async Task UpdateStatus(string hashedAccountId, string hashedApprenticeshipId, ChangeStatusViewModel model, string externalUserId, string userName, string userEmail)
        {
            var accountId        = HashingService.DecodeValue(hashedAccountId);
            var apprenticeshipId = HashingService.DecodeValue(hashedApprenticeshipId);

            Logger.Info(
                $"Updating Apprenticeship status to {model.ChangeType}. AccountId: {accountId}, ApprenticeshipId: {apprenticeshipId}");

            await CheckUserAuthorization(async() =>
            {
                var data =
                    await
                    Mediator.SendAsync(new GetApprenticeshipQueryRequest
                {
                    AccountId        = accountId,
                    ApprenticeshipId = apprenticeshipId
                });

                CheckApprenticeshipStateValidForChange(data.Apprenticeship);

                await Mediator.SendAsync(new UpdateApprenticeshipStatusCommand
                {
                    UserId            = externalUserId,
                    ApprenticeshipId  = apprenticeshipId,
                    EmployerAccountId = accountId,
                    ChangeType        = (Domain.Models.Apprenticeship.ChangeStatusType)model.ChangeType,
                    DateOfChange      = model.DateOfChange.DateTime.Value,
                    UserEmailAddress  = userEmail,
                    UserDisplayName   = userName,
                    MadeRedundant     = model.MadeRedundant
                });
            }, hashedAccountId, externalUserId);
        }
        public async Task <OrchestratorResponse <ChangeStatusChoiceViewModel> > GetChangeStatusChoiceNavigation(string hashedAccountId, string hashedApprenticeshipId, string externalUserId)
        {
            var accountId        = HashingService.DecodeValue(hashedAccountId);
            var apprenticeshipId = HashingService.DecodeValue(hashedApprenticeshipId);

            Logger.Info(
                $"Determining navigation for type of change status selection. AccountId: {accountId}, ApprenticeshipId: {apprenticeshipId}");

            return(await CheckUserAuthorization(async() =>
            {
                var data =
                    await
                    Mediator.SendAsync(new GetApprenticeshipQueryRequest
                {
                    AccountId = accountId,
                    ApprenticeshipId = apprenticeshipId
                });

                CheckApprenticeshipStateValidForChange(data.Apprenticeship);

                var isPaused = data.Apprenticeship.PaymentStatus == PaymentStatus.Paused;
                var apprenticeDetailsV2Link = _linkGenerator.CommitmentsV2Link($"{hashedAccountId}/apprentices/{hashedApprenticeshipId}/details");

                return new OrchestratorResponse <ChangeStatusChoiceViewModel> {
                    Data = new ChangeStatusChoiceViewModel {
                        IsCurrentlyPaused = isPaused, ApprenticeDetailsV2Link = apprenticeDetailsV2Link
                    }
                };
            }, hashedAccountId, externalUserId));
        }
        private async Task AddReservationValidationErrors(ConcurrentDictionary <string, string> errors, ApprenticeshipViewModel model)
        {
            void AddToErrors(ReservationValidationResult data)
            {
                foreach (var error in data.ValidationErrors)
                {
                    errors.TryAdd(error.PropertyName, error.Reason);
                }
            }

            if (model.ReservationId == null)
            {
                Logger.Info($"Apprenticeship: {HashingService.DecodeValue(model.HashedApprenticeshipId)} Reservation-id:null - no reservation validation required");
                return;
            }

            if (model.StartDate?.DateTime == null)
            {
                Logger.Info($"Apprenticeship: {HashingService.DecodeValue(model.HashedApprenticeshipId)} Reservation-id:{model.ReservationId} start date required for reservation validation");
                return;
            }

            var response = await Mediator.SendAsync(
                new GetReservationValidationRequest
            {
                StartDate     = model.StartDate.DateTime.Value,
                TrainingCode  = model.TrainingCode,
                ReservationId = model.ReservationId.Value
            }
                );

            AddToErrors(response.Data);
        }
Exemple #9
0
        public async Task SubmitCommitment(string currentUserId, long providerId, string hashedCommitmentId, SaveStatus saveStatus, string message, SignInUserModel currentUser)
        {
            var commitmentId = HashingService.DecodeValue(hashedCommitmentId);

            await AssertCommitmentStatus(commitmentId, providerId);

            Logger.Info($"Submitting ({saveStatus}) Commitment for provider:{providerId} commitment:{commitmentId}", providerId: providerId, commitmentId: commitmentId);

            if (saveStatus == SaveStatus.Approve || saveStatus == SaveStatus.ApproveAndSend)
            {
                var isSigned = await IsSignedAgreement(providerId) == ProviderAgreementStatus.Agreed;

                if (!isSigned)
                {
                    throw new InvalidStateException("Cannot approve commitment when no agreement signed");
                }
            }

            LastAction lastAction;

            switch (saveStatus)
            {
            case SaveStatus.AmendAndSend:
                lastAction = LastAction.Amend;
                break;

            case SaveStatus.Approve:
                lastAction = LastAction.Approve;
                break;

            case SaveStatus.ApproveAndSend:
                lastAction = LastAction.Approve;
                break;

            case SaveStatus.Save:
                lastAction = LastAction.None;
                break;

            default:
                lastAction = LastAction.None;
                break;
            }

            await
            Mediator.Send(
                new SubmitCommitmentCommand
            {
                ProviderId         = providerId,
                HashedCommitmentId = hashedCommitmentId,
                CommitmentId       = commitmentId,
                Message            = message,
                LastAction         = lastAction,
                CreateTask         = (saveStatus == SaveStatus.ApproveAndSend || saveStatus == SaveStatus.AmendAndSend),
                UserDisplayName    = currentUser.DisplayName,
                UserEmailAddress   = currentUser.Email,
                UserId             = currentUserId
            });
        }
        public void When_Decode_HashId_IsNullOrEmpty_Should_ThrowException(string valueToDecode)
        {
            // Arrange
            var _sut = new HashingService(AllowedCharacters, Hashstring);

            //Act
            Action testDelegate = () => _sut.DecodeValue(valueToDecode);

            //Assert
            testDelegate.ShouldThrow <ArgumentException>();
        }
        public void Then_Invalid_Decode_HashId_Should_ThrowException(string hashId)
        {
            // Arrange
            var _sut = new HashingService(AllowedCharacters, Hashstring);

            //Act
            Action testDelegate = () => _sut.DecodeValue(hashId);

            //Assert
            testDelegate.ShouldThrow <IndexOutOfRangeException>();
        }
 public async Task CreateApprenticeshipUpdate(UpdateApprenticeshipViewModel apprenticeship, string hashedAccountId, string userId, string userName, string userEmail)
 {
     var employerId = HashingService.DecodeValue(hashedAccountId);
     await Mediator.SendAsync(new CreateApprenticeshipUpdateCommand
     {
         EmployerId           = employerId,
         ApprenticeshipUpdate = _apprenticeshipMapper.MapFrom(apprenticeship),
         UserId           = userId,
         UserEmailAddress = userEmail,
         UserDisplayName  = userName
     });
 }
        public void Then_Numeric_HashValue_Should_Equal_DecodeValue(long expectTedValue)
        {
            // Arrange
            var _sut = new HashingService(AllowedCharacters, Hashstring);

            //Act
            var hash        = _sut.HashValue(expectTedValue);
            var actualValue = _sut.DecodeValue(hash);

            //Assert
            expectTedValue.Should().Be(actualValue);
        }
Exemple #14
0
        public async Task <OrchestratorResponse <DataLockStatusViewModel> > GetDataLockStatusForRestartRequest(string hashedAccountId, string hashedApprenticeshipId, string userId)
        {
            var accountId        = HashingService.DecodeValue(hashedAccountId);
            var apprenticeshipId = HashingService.DecodeValue(hashedApprenticeshipId);

            return(await CheckUserAuthorization(
                       async() =>
            {
                var dataLockSummary = await Mediator.SendAsync(
                    new GetDataLockSummaryQueryRequest {
                    AccountId = accountId, ApprenticeshipId = apprenticeshipId
                });

                //var dataLock = dataLocks.DataLockStatus
                //    .First(m => m.TriageStatus == TriageStatus.Restart);
                var dataLock = dataLockSummary.DataLockSummary
                               .DataLockWithCourseMismatch.FirstOrDefault(m => m.TriageStatus == TriageStatus.Restart);

                if (dataLock == null)
                {
                    throw new InvalidStateException($"No data locks exist that can be restarted for apprenticeship: {apprenticeshipId}");
                }

                var apprenticeship = await Mediator.SendAsync(
                    new GetApprenticeshipQueryRequest {
                    AccountId = accountId, ApprenticeshipId = apprenticeshipId
                });

                var programms = await GetTrainingProgrammes(true);
                var currentProgram = programms.Single(m => m.CourseCode == apprenticeship.Apprenticeship.TrainingCode);
                var newProgram = programms.Single(m => m.CourseCode == dataLock.IlrTrainingCourseCode);

                return new OrchestratorResponse <DataLockStatusViewModel>
                {
                    Data = new DataLockStatusViewModel
                    {
                        HashedAccountId = hashedAccountId,
                        HashedApprenticeshipId = hashedApprenticeshipId,
                        CurrentProgram = currentProgram,
                        IlrProgram = newProgram,
                        PeriodStartData = dataLock.IlrEffectiveFromDate,
                        PeriodEndData = dataLock.IlrEffectiveToDate,
                        ProviderName = apprenticeship.Apprenticeship.ProviderName,
                        LearnerName = apprenticeship.Apprenticeship.ApprenticeshipName,
                        DateOfBirth = apprenticeship.Apprenticeship.DateOfBirth,
                        ApprenticeDetailsV2Link = _linkGenerator.CommitmentsV2Link($"{hashedAccountId}/apprentices/{hashedApprenticeshipId}/details")
                    }
                };
            }, hashedAccountId, userId));
        }
Exemple #15
0
        public async Task DeleteCommitment(string userId, long providerId, string hashedCommitmentId, SignInUserModel signinUser)
        {
            var commitmentId = HashingService.DecodeValue(hashedCommitmentId);

            Logger.Info($"Deleting commitment {hashedCommitmentId}", providerId, commitmentId);

            await Mediator.Send(new DeleteCommitmentCommand
            {
                UserId           = userId,
                ProviderId       = providerId,
                CommitmentId     = commitmentId,
                UserDisplayName  = signinUser.DisplayName,
                UserEmailAddress = signinUser.Email
            });
        }
Exemple #16
0
        public async Task <OrchestratorResponse <DataLockStatusViewModel> > GetDataLockChangeStatus(string hashedAccountId, string hashedApprenticeshipId, string userId)
        {
            var accountId        = HashingService.DecodeValue(hashedAccountId);
            var apprenticeshipId = HashingService.DecodeValue(hashedApprenticeshipId);

            return(await CheckUserAuthorization(
                       async() =>
            {
                var dataLockSummary = await Mediator.SendAsync(
                    new GetDataLockSummaryQueryRequest {
                    AccountId = accountId, ApprenticeshipId = apprenticeshipId
                });

                var priceHistory = await Mediator.SendAsync(new GetPriceHistoryQueryRequest
                {
                    AccountId = accountId,
                    ApprenticeshipId = apprenticeshipId
                });

                var apprenticeship = await Mediator.SendAsync(
                    new GetApprenticeshipQueryRequest {
                    AccountId = accountId, ApprenticeshipId = apprenticeshipId
                });

                var dataLockPrice =
                    dataLockSummary.DataLockSummary.DataLockWithCourseMismatch
                    .Concat(dataLockSummary.DataLockSummary.DataLockWithOnlyPriceMismatch)
                    .Where(m => m.ErrorCode.HasFlag(DataLockErrorCode.Dlock07));

                return new OrchestratorResponse <DataLockStatusViewModel>
                {
                    Data = new DataLockStatusViewModel
                    {
                        HashedAccountId = hashedAccountId,
                        HashedApprenticeshipId = hashedApprenticeshipId,
                        PeriodStartData = new DateTime(2017, 08, 08),
                        ProviderName = apprenticeship.Apprenticeship.ProviderName,
                        LearnerName = apprenticeship.Apprenticeship.ApprenticeshipName,
                        DateOfBirth = apprenticeship.Apprenticeship.DateOfBirth,
                        CourseChanges = await _apprenticeshipMapper.MapCourseChanges(dataLockSummary.DataLockSummary.DataLockWithCourseMismatch, apprenticeship.Apprenticeship, priceHistory.History),
                        PriceChanges = _apprenticeshipMapper.MapPriceChanges(dataLockPrice, priceHistory.History),
                        ULN = apprenticeship.Apprenticeship.ULN,
                        TrainingName = apprenticeship.Apprenticeship.TrainingName,
                        ApprenticeDetailsV2Link = _linkGenerator.CommitmentsV2Link($"{hashedAccountId}/apprentices/{hashedApprenticeshipId}/details")
                    }
                };
            }, hashedAccountId, userId));
        }
        public async Task <OrchestratorResponse <UpdateApprenticeshipViewModel> > GetViewChangesViewModel(
            string hashedAccountId, string hashedApprenticeshipId, string externalUserId)
        {
            var accountId        = HashingService.DecodeValue(hashedAccountId);
            var apprenticeshipId = HashingService.DecodeValue(hashedApprenticeshipId);

            Logger.Debug($"Getting confirm change model: {accountId}, ApprenticeshipId: {apprenticeshipId}");

            return(await CheckUserAuthorization(
                       async() =>
            {
                var data = await Mediator.SendAsync(
                    new GetApprenticeshipUpdateRequest
                {
                    AccountId = accountId,
                    ApprenticeshipId = apprenticeshipId
                });

                var apprenticeshipResult = await Mediator.SendAsync(
                    new GetApprenticeshipQueryRequest
                {
                    AccountId = accountId,
                    ApprenticeshipId = apprenticeshipId
                });

                var viewModel = _apprenticeshipMapper.MapFrom(data.ApprenticeshipUpdate);

                if (viewModel == null)
                {
                    throw new InvalidStateException("Attempting to update an already updated Apprenticeship");
                }

                var apprenticeship = _apprenticeshipMapper.MapToApprenticeshipDetailsViewModel(apprenticeshipResult.Apprenticeship);
                viewModel.OriginalApprenticeship = apprenticeship;
                viewModel.HashedAccountId = hashedAccountId;
                viewModel.HashedApprenticeshipId = hashedApprenticeshipId;
                viewModel.ProviderName = apprenticeship.ProviderName;

                return new OrchestratorResponse <UpdateApprenticeshipViewModel>
                {
                    Data = viewModel
                };
            }, hashedAccountId, externalUserId));
        }
Exemple #18
0
        public async Task <DeleteConfirmationViewModel> GetDeleteConfirmationModel(long providerId, string hashedCommitmentId, string hashedApprenticeshipId)
        {
            var apprenticeshipId = HashingService.DecodeValue(hashedApprenticeshipId);

            var apprenticeship = await Mediator.Send(new GetApprenticeshipQueryRequest
            {
                ProviderId       = providerId,
                ApprenticeshipId = apprenticeshipId
            });

            return(new DeleteConfirmationViewModel
            {
                ProviderId = providerId,
                HashedCommitmentId = hashedCommitmentId,
                HashedApprenticeshipId = hashedApprenticeshipId,
                ApprenticeshipName = apprenticeship.Apprenticeship.ApprenticeshipName,
                DateOfBirth = apprenticeship.Apprenticeship.DateOfBirth.HasValue ? apprenticeship.Apprenticeship.DateOfBirth.Value.ToGdsFormat() : string.Empty
            });
        }
        public async Task SubmitReviewApprenticeshipUpdate(string hashedAccountId, string hashedApprenticeshipId, string userId, bool isApproved, string userName, string userEmail)
        {
            var accountId        = HashingService.DecodeValue(hashedAccountId);
            var apprenticeshipId = HashingService.DecodeValue(hashedApprenticeshipId);

            await CheckUserAuthorization(async() =>
            {
                await Mediator.SendAsync(new ReviewApprenticeshipUpdateCommand
                {
                    AccountId        = accountId,
                    ApprenticeshipId = apprenticeshipId,
                    UserId           = userId,
                    IsApproved       = isApproved,
                    UserDisplayName  = userName,
                    UserEmailAddress = userEmail
                });
            }
                                         , hashedAccountId, userId);
        }
        public async Task <OrchestratorResponse <ExtendedApprenticeshipViewModel> > GetApprenticeshipForEdit(
            string hashedAccountId, string hashedApprenticeshipId, string externalUserId)
        {
            var accountId        = HashingService.DecodeValue(hashedAccountId);
            var apprenticeshipId = HashingService.DecodeValue(hashedApprenticeshipId);

            Logger.Info($"Getting Approved Apprenticeship for Editing, Account: {accountId}, ApprenticeshipId: {apprenticeshipId}");

            return(await CheckUserAuthorization(async() =>
            {
                await AssertApprenticeshipStatus(accountId, apprenticeshipId);

                //todo: whenall
                var apprenticeshipData = await Mediator.SendAsync(new GetApprenticeshipQueryRequest
                {
                    AccountId = accountId,
                    ApprenticeshipId = apprenticeshipId
                });

                var commitmentData = await Mediator.SendAsync(new GetCommitmentQueryRequest
                {
                    AccountId = accountId,
                    CommitmentId = apprenticeshipData.Apprenticeship.CommitmentId
                });

                AssertApprenticeshipIsEditable(apprenticeshipData.Apprenticeship);
                var apprenticeship = _apprenticeshipMapper.MapToApprenticeshipViewModel(apprenticeshipData.Apprenticeship, commitmentData.Commitment);

                apprenticeship.HashedAccountId = hashedAccountId;

                var includeFrameworks = commitmentData.Commitment.ApprenticeshipEmployerTypeOnApproval != ApprenticeshipEmployerType.NonLevy;

                return new OrchestratorResponse <ExtendedApprenticeshipViewModel>
                {
                    Data = new ExtendedApprenticeshipViewModel
                    {
                        Apprenticeship = apprenticeship,
                        ApprenticeshipProgrammes = await GetTrainingProgrammes(includeFrameworks)
                    }
                };
            }, hashedAccountId, externalUserId));
        }
        public async Task SubmitUndoApprenticeshipUpdate(string hashedAccountId, string hashedApprenticeshipId, string userId, string userName, string userEmail)
        {
            var accountId        = HashingService.DecodeValue(hashedAccountId);
            var apprenticeshipId = HashingService.DecodeValue(hashedApprenticeshipId);

            Logger.Debug($"Undoing pending update for : AccountId {accountId}, ApprenticeshipId: {apprenticeshipId}");

            await CheckUserAuthorization(async() =>
            {
                await Mediator.SendAsync(new UndoApprenticeshipUpdateCommand
                {
                    AccountId        = accountId,
                    ApprenticeshipId = apprenticeshipId,
                    UserId           = userId,
                    UserDisplayName  = userName,
                    UserEmailAddress = userEmail
                });
            }
                                         , hashedAccountId, userId);
        }
Exemple #22
0
        public async Task <ApprenticeshipViewModel> GetApprenticeshipViewModel(long providerId, string hashedCommitmentId, string hashedApprenticeshipId)
        {
            var apprenticeshipId = HashingService.DecodeValue(hashedApprenticeshipId);
            var commitmentId     = HashingService.DecodeValue(hashedCommitmentId);

            Logger.Info($"Getting apprenticeship:{apprenticeshipId} for provider:{providerId}", providerId: providerId, commitmentId: commitmentId, apprenticeshipId: apprenticeshipId);

            var data = await Mediator.Send(new GetApprenticeshipQueryRequest
            {
                ProviderId       = providerId,
                ApprenticeshipId = apprenticeshipId
            });

            var commitment = await GetCommitment(providerId, commitmentId);

            var apprenticeship = _apprenticeshipMapper.MapApprenticeship(data.Apprenticeship, commitment);

            apprenticeship.ProviderId = providerId;

            return(apprenticeship);
        }
Exemple #23
0
        public async Task ConfirmRequestChanges(string hashedAccountId, string hashedApprenticeshipId, string user, bool approved)
        {
            var accountId        = HashingService.DecodeValue(hashedAccountId);
            var apprenticeshipId = HashingService.DecodeValue(hashedApprenticeshipId);

            await CheckUserAuthorization(
                async() =>
            {
                await Mediator.SendAsync(
                    new ResolveRequestedChangesCommand
                {
                    AccountId        = accountId,
                    ApprenticeshipId = apprenticeshipId,
                    Approved         = approved,
                    TriageStatus     = TriageStatus.Change,
                    UserId           = user
                });
            },
                hashedAccountId,
                user);
        }
        public async Task <OrchestratorResponse <WhenToMakeChangeViewModel> > GetChangeStatusDateOfChangeViewModel(
            string hashedAccountId, string hashedApprenticeshipId,
            ChangeStatusType changeType, string externalUserId)
        {
            var accountId        = HashingService.DecodeValue(hashedAccountId);
            var apprenticeshipId = HashingService.DecodeValue(hashedApprenticeshipId);

            Logger.Info(
                $"Determining navigation for type of change status selection. AccountId: {accountId}, ApprenticeshipId: {apprenticeshipId}");

            return(await CheckUserAuthorization(async() =>
            {
                var data =
                    await
                    Mediator.SendAsync(new GetApprenticeshipQueryRequest
                {
                    AccountId = accountId,
                    ApprenticeshipId = apprenticeshipId
                });

                CheckApprenticeshipStateValidForChange(data.Apprenticeship);

                return new OrchestratorResponse <WhenToMakeChangeViewModel>
                {
                    Data = new WhenToMakeChangeViewModel
                    {
                        ApprenticeStartDate = data.Apprenticeship.StartDate.Value,
                        SkipToConfirmationPage = CanSkipToConfirmationPage(changeType, data),
                        SkipToMadeRedundantQuestion = CanSkipToAskRedundancyQuestion(changeType, data),
                        ChangeStatusViewModel = new ChangeStatusViewModel
                        {
                            ChangeType = changeType
                        },
                        ApprenticeshipULN = data.Apprenticeship.ULN,
                        ApprenticeshipName = data.Apprenticeship.ApprenticeshipName,
                        TrainingName = data.Apprenticeship.TrainingName
                    }
                };
            }, hashedAccountId, externalUserId));
        }
        public async Task <OrchestratorResponse <RedundantApprenticeViewModel> > GetRedundantViewModel(
            string hashedAccountId, string hashedApprenticeshipId, ChangeStatusType changeType, DateTime?dateOfChange, WhenToMakeChangeOptions whenToMakeChange, string externalUserId, bool?madeRedundant)
        {
            var accountId        = HashingService.DecodeValue(hashedAccountId);
            var apprenticeshipId = HashingService.DecodeValue(hashedApprenticeshipId);

            Logger.Info(
                $"Determining navigation for type of change status selection. AccountId: {accountId}, ApprenticeshipId: {apprenticeshipId}");

            return(await CheckUserAuthorization(async() =>
            {
                var data =
                    await
                    Mediator.SendAsync(new GetApprenticeshipQueryRequest
                {
                    AccountId = accountId,
                    ApprenticeshipId = apprenticeshipId
                });

                CheckApprenticeshipStateValidForChange(data.Apprenticeship);

                return new OrchestratorResponse <RedundantApprenticeViewModel>
                {
                    Data = new RedundantApprenticeViewModel
                    {
                        ApprenticeshipName = data.Apprenticeship.ApprenticeshipName,
                        ChangeStatusViewModel = new ChangeStatusViewModel()
                        {
                            DateOfChange = DetermineChangeDate(changeType, data.Apprenticeship, whenToMakeChange, dateOfChange),
                            ChangeType = changeType,
                            WhenToMakeChange = whenToMakeChange,
                            ChangeConfirmed = false,
                            StartDate = data.Apprenticeship.StartDate,
                            MadeRedundant = madeRedundant
                        }
                    }
                };
            }, hashedAccountId, externalUserId));
        }
Exemple #26
0
        public async Task <UploadApprenticeshipsViewModel> GetUnsuccessfulUpload(long providerId, string hashedCommitmentId, string bulkUploadReference)
        {
            var commitmentId = HashingService.DecodeValue(hashedCommitmentId);
            var bulkUploadId = HashingService.DecodeValue(bulkUploadReference);

            var commitment = await GetCommitment(providerId, commitmentId);

            AssertCommitmentStatus(commitment);
            await AssertAutoReservationEnabled(commitment);

            var fileContentResult = await Mediator.Send(new GetBulkUploadFileQueryRequest
            {
                ProviderId   = providerId,
                BulkUploadId = bulkUploadId
            });

            var uploadResult = _fileParser.CreateViewModels(providerId, commitment, fileContentResult.FileContent);

            var validationResult = await _bulkUploader.ValidateFileRows(uploadResult.Data, providerId, bulkUploadId);

            var overlaps = await GetOverlapErrors(uploadResult.Data.ToList());

            var errors = validationResult.Errors.ToList();

            errors.AddRange(overlaps);

            var result = _mapper.MapErrors(errors);

            return(new UploadApprenticeshipsViewModel
            {
                ProviderId = providerId,
                HashedCommitmentId = hashedCommitmentId,
                ErrorCount = errors.Count,
                RowCount = result.Count,
                Errors = result,
                FileErrors = new List <UploadError>()
            });
        }
        public async Task <ValidateWhenToApplyChangeResult> ValidateWhenToApplyChange(string hashedAccountId,
                                                                                      string hashedApprenticeshipId, ChangeStatusViewModel model)
        {
            var accountId        = HashingService.DecodeValue(hashedAccountId);
            var apprenticeshipId = HashingService.DecodeValue(hashedApprenticeshipId);

            Logger.Info(
                $"Validating Date for when to apply change. AccountId: {accountId}, ApprenticeshipId: {apprenticeshipId}, ChangeType: {model.ChangeType}, ChangeDate: {model.DateOfChange.DateTime}");

            var response = await Mediator.SendAsync(new ValidateStatusChangeDateQuery
            {
                AccountId        = accountId,
                ApprenticeshipId = apprenticeshipId,
                ChangeOption     = (ChangeOption)model.WhenToMakeChange,
                DateOfChange     = model.DateOfChange.DateTime
            });

            return(new ValidateWhenToApplyChangeResult
            {
                ValidationResult = response.ValidationResult,
                DateOfChange = response.ValidatedChangeOfDate
            });
        }
Exemple #28
0
        public async Task <string> DeleteApprenticeship(string userId, DeleteConfirmationViewModel viewModel, SignInUserModel signinUser)
        {
            var apprenticeshipId = HashingService.DecodeValue(viewModel.HashedApprenticeshipId);

            Logger.Info($"Deleting apprenticeship {apprenticeshipId}", providerId: viewModel.ProviderId, apprenticeshipId: apprenticeshipId);

            var apprenticeship = await Mediator.Send(new GetApprenticeshipQueryRequest
            {
                ProviderId       = viewModel.ProviderId,
                ApprenticeshipId = apprenticeshipId
            });

            await Mediator.Send(new DeleteApprenticeshipCommand
            {
                UserId           = userId,
                ProviderId       = viewModel.ProviderId,
                ApprenticeshipId = apprenticeshipId,
                UserDisplayName  = signinUser.DisplayName,
                UserEmailAddress = signinUser.Email
            });

            return(apprenticeship.Apprenticeship.ApprenticeshipName);
        }
        public async Task <OrchestratorResponse <EditApprenticeshipStopDateViewModel> > GetEditApprenticeshipStopDateViewModel(string hashedAccountId, string hashedApprenticeshipId, string externalUserId)
        {
            var accountId        = HashingService.DecodeValue(hashedAccountId);
            var apprenticeshipId = HashingService.DecodeValue(hashedApprenticeshipId);

            Logger.Info(
                $"Getting On-programme apprenticeships Provider: {accountId}, ApprenticeshipId: {apprenticeshipId}");

            return(await CheckUserAuthorization(async() =>
            {
                var data = await Mediator.SendAsync(
                    new GetApprenticeshipQueryRequest {
                    AccountId = accountId, ApprenticeshipId = apprenticeshipId
                });

                var stopDateEditModel =
                    _apprenticeshipMapper.MapToEditApprenticeshipStopDateViewModel(data.Apprenticeship);
                stopDateEditModel.ApprenticeDetailsV2Link = _linkGenerator.CommitmentsV2Link($"{hashedAccountId}/apprentices/{hashedApprenticeshipId}/details");

                return new OrchestratorResponse <EditApprenticeshipStopDateViewModel> {
                    Data = stopDateEditModel
                };
            }, hashedAccountId, externalUserId));
        }
Exemple #30
0
        public async Task <ExtendedApprenticeshipViewModel> GetApprenticeship(long providerId, string hashedCommitmentId, string hashedApprenticeshipId)
        {
            var apprenticeshipId = HashingService.DecodeValue(hashedApprenticeshipId);
            var commitmentId     = HashingService.DecodeValue(hashedCommitmentId);

            Logger.Info($"Getting apprenticeship:{apprenticeshipId} for provider:{providerId}", providerId: providerId, commitmentId: commitmentId, apprenticeshipId: apprenticeshipId);

            var data = await Mediator.Send(new GetApprenticeshipQueryRequest
            {
                ProviderId       = providerId,
                ApprenticeshipId = apprenticeshipId
            });

            var commitment = await GetCommitment(providerId, commitmentId);

            AssertCommitmentStatus(commitment);

            var overlappingErrors = await Mediator.Send(
                new GetOverlappingApprenticeshipsQueryRequest
            {
                Apprenticeship = new List <Apprenticeship> {
                    data.Apprenticeship
                }
            });

            var apprenticeship = _apprenticeshipMapper.MapApprenticeship(data.Apprenticeship, commitment);

            apprenticeship.ProviderId = providerId;

            return(new ExtendedApprenticeshipViewModel
            {
                Apprenticeship = apprenticeship,
                ApprenticeshipProgrammes = await GetTrainingProgrammes(!commitment.IsTransfer()),
                ValidationErrors = _apprenticeshipCoreValidator.MapOverlappingErrors(overlappingErrors)
            });
        }