Ejemplo n.º 1
0
        public string FinanceLink(string routeName, params string[] args)
        {
            var route = _routes.Finance[routeName];

            if (args != null && args.Length > 0)
            {
                route = string.Format(route, args);
            }

            return(_generator.FinanceLink(route));
        }
        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));
        }