public async Task <ActionResult> StatusChangeConfirmation(string hashedAccountId, string hashedApprenticeshipId, ChangeStatusType changeType, WhenToMakeChangeOptions whenToMakeChange, DateTime?dateOfChange, bool?madeRedundant)
        {
            if (!await IsUserRoleAuthorized(hashedAccountId, Role.Owner, Role.Transactor))
            {
                return(View("AccessDenied"));
            }

            var response = await _orchestrator.GetChangeStatusConfirmationViewModel(hashedAccountId, hashedApprenticeshipId, changeType, whenToMakeChange, dateOfChange, madeRedundant, OwinWrapper.GetClaimValue(@"sub"));

            return(View(response));
        }
Exemplo n.º 2
0
        private DateTimeViewModel DetermineChangeDate(ChangeStatusType changeType, Apprenticeship apprenticeship, WhenToMakeChangeOptions whenToMakeChange, DateTime?dateOfChange)
        {
            if (changeType == ChangeStatusType.Pause || changeType == ChangeStatusType.Resume)
            {
                return(new DateTimeViewModel(_currentDateTime.Now.Date));
            }

            if (apprenticeship.IsWaitingToStart(_currentDateTime))
            {
                return(new DateTimeViewModel(apprenticeship.StartDate));
            }

            if (whenToMakeChange == WhenToMakeChangeOptions.Immediately)
            {
                return(new DateTimeViewModel(_currentDateTime.Now.Date));
            }

            return(new DateTimeViewModel(dateOfChange));
        }
        public async Task <OrchestratorResponse <ConfirmationStateChangeViewModel> > GetChangeStatusConfirmationViewModel(string hashedAccountId, string hashedApprenticeshipId, ChangeStatusType changeType, WhenToMakeChangeOptions whenToMakeChange, DateTime?dateOfChange, bool?madeRedundant, string externalUserId)
        {
            var accountId        = HashingService.DecodeValue(hashedAccountId);
            var apprenticeshipId = HashingService.DecodeValue(hashedApprenticeshipId);

            Logger.Info(
                $"Getting Change Status Confirmation ViewModel. AccountId: {accountId}, ApprenticeshipId: {apprenticeshipId}, ChangeType: {changeType}");

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

                CheckApprenticeshipStateValidForChange(data.Apprenticeship);

                var result = new OrchestratorResponse <ConfirmationStateChangeViewModel>
                {
                    Data = new ConfirmationStateChangeViewModel
                    {
                        ApprenticeName = data.Apprenticeship.ApprenticeshipName,
                        ApprenticeULN = data.Apprenticeship.ULN,
                        DateOfBirth = data.Apprenticeship.DateOfBirth.Value,
                        ApprenticeCourse = data.Apprenticeship.TrainingName,
                        ViewTransactionsLink = _linkGenerator.FinanceLink($"accounts/{hashedAccountId}/finance/{_currentDateTime.Now.Year}/{_currentDateTime.Now.Month}"),

                        ChangeStatusViewModel = new ChangeStatusViewModel
                        {
                            DateOfChange = DetermineChangeDate(changeType, data.Apprenticeship, whenToMakeChange, dateOfChange),
                            ChangeType = changeType,
                            WhenToMakeChange = whenToMakeChange,
                            ChangeConfirmed = false,
                            StartDate = data.Apprenticeship.StartDate,
                            MadeRedundant = madeRedundant
                        }
                    }
                };

                var notResuming = changeType != ChangeStatusType.Resume;

                if (notResuming)
                {
                    return result;
                }

                result.Data.ChangeStatusViewModel.PauseDate = new DateTimeViewModel(data.Apprenticeship.PauseDate, 90);


                if (data.Apprenticeship.IsWaitingToStart(_currentDateTime))
                {
                    result.Data.ChangeStatusViewModel.DateOfChange = new DateTimeViewModel(_currentDateTime.Now.Date, 90);
                    return result;
                }

                result.Data.ChangeStatusViewModel.DateOfChange = new DateTimeViewModel(data.Apprenticeship.PauseDate.Value, 90);

                var mustInvokeAcademicYearFundingRule = _academicYearValidator.Validate(data.Apprenticeship.PauseDate.Value) == AcademicYearValidationResult.NotWithinFundingPeriod;

                if (!mustInvokeAcademicYearFundingRule)
                {
                    return result;
                }

                result.Data.ChangeStatusViewModel.AcademicYearBreakInTraining = true;

                result.Data.ChangeStatusViewModel.DateOfChange = new DateTimeViewModel(_academicYearDateProvider.CurrentAcademicYearStartDate, 90);


                return result;
            }, hashedAccountId, externalUserId));
        }
Exemplo n.º 4
0
        public async Task <OrchestratorResponse <ConfirmationStateChangeViewModel> > GetChangeStatusConfirmationViewModel(string hashedAccountId, string hashedApprenticeshipId, ChangeStatusType changeType, WhenToMakeChangeOptions whenToMakeChange, DateTime?dateOfChange, string externalUserId)
        {
            var accountId        = _hashingService.DecodeValue(hashedAccountId);
            var apprenticeshipId = _hashingService.DecodeValue(hashedApprenticeshipId);

            _logger.Info(
                $"Getting Change Status Confirmation ViewModel. AccountId: {accountId}, ApprenticeshipId: {apprenticeshipId}, ChangeType: {changeType}");

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

                CheckApprenticeshipStateValidForChange(data.Apprenticeship);

                return new OrchestratorResponse <ConfirmationStateChangeViewModel>
                {
                    Data = new ConfirmationStateChangeViewModel
                    {
                        ApprenticeName = data.Apprenticeship.ApprenticeshipName,
                        DateOfBirth = data.Apprenticeship.DateOfBirth.Value,
                        ChangeStatusViewModel = new ChangeStatusViewModel
                        {
                            DateOfChange = DetermineChangeDate(changeType, data.Apprenticeship, whenToMakeChange, dateOfChange),
                            ChangeType = changeType,
                            WhenToMakeChange = whenToMakeChange,
                            ChangeConfirmed = false
                        }
                    }
                };
            }, 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));
        }