private void ValidateChangeDateForStop(DateTime dateOfChange, Apprenticeship apprenticeship) { if (apprenticeship == null) { throw new ArgumentException(nameof(apprenticeship)); } if (apprenticeship.IsWaitingToStart(_currentDate)) { if (dateOfChange.Date != apprenticeship.StartDate.Value.Date) { throw new ValidationException("Invalid Date of Change. Date should be value of start date if training has not started."); } } else { if (dateOfChange.Date > _currentDate.Now.Date) { throw new ValidationException("Invalid Date of Change. Date cannot be in the future."); } if (dateOfChange.Date < apprenticeship.StartDate.Value.Date) { throw new ValidationException("Invalid Date of Change. Date cannot be before the training start date."); } if (apprenticeship.PaymentStatus != PaymentStatus.PendingApproval && _academicYearValidator.Validate(dateOfChange.Date) == AcademicYearValidationResult.NotWithinFundingPeriod) { throw new ValidationException("Invalid Date of Change. Date cannot be before the academic year start date."); } } }
public Dictionary <string, string> ValidateAcademicYear(ApprenticeshipViewModel model) { var dict = new Dictionary <string, string>(); if (model.StartDate?.DateTime != null && _academicYearValidator.Validate(model.StartDate.DateTime.Value) == AcademicYearValidationResult.NotWithinFundingPeriod) { dict.Add($"{nameof(model.StartDate)}", ValidationText.AcademicYearStartDate01.Text); } return(dict); }
public void ThenAcademicYearValidationShouldReturnExpectedResult(DateTime currentDate, DateTime startDate, AcademicYearValidationResult expectedResult) { //Arrange var yearStartDate = new DateTime(2016, 8, 1); var fundingPeriodDate = new DateTime(2017, 10, 19); _mockCurrentDateTime.Setup(x => x.Now).Returns(currentDate); _academicYear = new Infrastructure.Services.AcademicYearDateProvider(_mockCurrentDateTime.Object); _academicYearValidator = new AcademicYearValidator(_mockCurrentDateTime.Object, _academicYear); //Act var result = _academicYearValidator.Validate(startDate); //Assert Assert.AreEqual(expectedResult, result); }
private void ValidateChangeDate(Apprenticeship apprenticeship, DateTime dateOfChange) { if (apprenticeship.IsWaitingToStart(_currentDate)) { return; } if (_academicYearValidator.Validate(apprenticeship.PauseDate.Value.Date) == AcademicYearValidationResult.NotWithinFundingPeriod) { if (dateOfChange.Date != _academicYearDateProvider.CurrentAcademicYearStartDate.Date) { throw new ValidationException("Invalid Date of Change. Date should be the academic year start date."); } } else { if (dateOfChange.Date != apprenticeship.PauseDate.Value.Date) { throw new ValidationException("Invalid Date of Change. Date should be the pause date."); } } }
public ApprenticeshipViewModel MapApprenticeship(Apprenticeship apprenticeship, CommitmentView commitment) { var isStartDateInFuture = apprenticeship.StartDate.HasValue && apprenticeship.StartDate.Value > new DateTime(_currentDateTime.Now.Year, _currentDateTime.Now.Month, 1); var isUpdateLockedForStartDateAndCourse = false; var isEndDateLockedForUpdate = false; var isLockedForUpdate = false; //locking fields concerns post-approval apprenticeships only //this method should be split into pre- and post-approval versions //ideally dealing with different api types and view models if (apprenticeship.PaymentStatus != PaymentStatus.PendingApproval) { isLockedForUpdate = (!isStartDateInFuture && (apprenticeship.HasHadDataLockSuccess || _academicYearValidator.IsAfterLastAcademicYearFundingPeriod && apprenticeship.StartDate.HasValue && _academicYearValidator.Validate(apprenticeship.StartDate.Value) == AcademicYearValidationResult.NotWithinFundingPeriod)) || (commitment.TransferSender?.TransferApprovalStatus == TransferApprovalStatus.Approved && apprenticeship.HasHadDataLockSuccess && isStartDateInFuture); isUpdateLockedForStartDateAndCourse = commitment.TransferSender?.TransferApprovalStatus == TransferApprovalStatus.Approved && !apprenticeship.HasHadDataLockSuccess; // if editing post-approval, we also lock down end date if... // start date is in the future and has had data lock success // (as the validation rule that disallows setting end date to > current month // means any date entered would be before the start date (which is also disallowed)) // and open it up if... // data lock success and start date in past isEndDateLockedForUpdate = isLockedForUpdate; if (commitment.AgreementStatus == AgreementStatus.BothAgreed && apprenticeship.HasHadDataLockSuccess) { isEndDateLockedForUpdate = isStartDateInFuture; } } var dateOfBirth = apprenticeship.DateOfBirth; return(new ApprenticeshipViewModel { HashedApprenticeshipId = _hashingService.HashValue(apprenticeship.Id), HashedCommitmentId = _hashingService.HashValue(apprenticeship.CommitmentId), FirstName = apprenticeship.FirstName, LastName = apprenticeship.LastName, DateOfBirth = new DateTimeViewModel(dateOfBirth?.Day, dateOfBirth?.Month, dateOfBirth?.Year), NINumber = apprenticeship.NINumber, ULN = apprenticeship.ULN, CourseType = apprenticeship.TrainingType, CourseName = apprenticeship.TrainingName, CourseCode = apprenticeship.TrainingCode, Cost = NullableDecimalToString(apprenticeship.Cost), StartDate = new DateTimeViewModel(apprenticeship.StartDate), StopDate = new DateTimeViewModel(apprenticeship.StopDate), EndDate = new DateTimeViewModel(apprenticeship.EndDate), PaymentStatus = apprenticeship.PaymentStatus, AgreementStatus = apprenticeship.AgreementStatus, ProviderRef = apprenticeship.ProviderRef, EmployerRef = apprenticeship.EmployerRef, HasStarted = !isStartDateInFuture, IsLockedForUpdate = isLockedForUpdate, IsPaidForByTransfer = commitment.IsTransfer(), IsUpdateLockedForStartDateAndCourse = isUpdateLockedForStartDateAndCourse, IsEndDateLockedForUpdate = isEndDateLockedForUpdate, ReservationId = apprenticeship.ReservationId, IsContinuation = apprenticeship.ContinuationOfId.HasValue }); }
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)); }