private ApprenticeshipUploadModel MapTo(CsvRecord record, CommitmentView commitment) { var dateOfBirth = GetValidDate(record.DateOfBirth, "yyyy-MM-dd"); var learnerStartDate = GetValidDate(record.StartDate, "yyyy-MM"); var learnerEndDate = GetValidDate(record.EndDate, "yyyy-MM"); var courseCode = record.ProgType == "25" ? record.StdCode : $"{record.FworkCode}-{record.ProgType}-{record.PwayCode}"; var apprenticeshipViewModel = new ApprenticeshipViewModel { AgreementStatus = AgreementStatus.NotAgreed, PaymentStatus = PaymentStatus.Active, ULN = record.ULN, FirstName = record.GivenNames, LastName = record.FamilyName, DateOfBirth = new DateTimeViewModel(dateOfBirth), Cost = record.TotalPrice, ProviderRef = record.ProviderRef, StartDate = new DateTimeViewModel(learnerStartDate), EndDate = new DateTimeViewModel(learnerEndDate), ProgType = record.ProgType.TryParse(), CourseCode = courseCode, IsPaidForByTransfer = commitment.IsTransfer() }; return(new ApprenticeshipUploadModel { ApprenticeshipViewModel = apprenticeshipViewModel, CsvRecord = record }); }
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 }); }