public void SetUp() { var dataLockWithCourseMismatch = new List <DataLockViewModel>(); var dataLockWithOnlyPriceMismatch = new List <DataLockViewModel>(); _model = new DataLockSummaryViewModel { DataLockWithCourseMismatch = dataLockWithCourseMismatch, DataLockWithOnlyPriceMismatch = dataLockWithOnlyPriceMismatch, ShowCourseDataLockTriageLink = true, ShowPriceDataLockTriageLink = true }; }
public async Task <DataLockSummaryViewModel> MapDataLockSummary(DataLockSummary source, bool hasHadDataLockSuccess) { var result = new DataLockSummaryViewModel { DataLockWithCourseMismatch = new List <DataLockViewModel>(), DataLockWithOnlyPriceMismatch = new List <DataLockViewModel>() }; var trainingProgrammes = await GetTrainingProgrammes(); foreach (var dataLock in source.DataLockWithCourseMismatch) { var training = trainingProgrammes.SingleOrDefault(x => x.CourseCode == dataLock.IlrTrainingCourseCode); if (training == null) { throw new InvalidOperationException( $"Datalock {dataLock.DataLockEventId} IlrTrainingCourseCode {dataLock.IlrTrainingCourseCode} not found; possible expiry"); } result.DataLockWithCourseMismatch.Add(MapDataLockStatus(dataLock, training)); } foreach (var dataLock in source.DataLockWithOnlyPriceMismatch) { var training = trainingProgrammes.SingleOrDefault(x => x.CourseCode == dataLock.IlrTrainingCourseCode); if (training == null) { throw new InvalidOperationException( $"Datalock {dataLock.DataLockEventId} IlrTrainingCourseCode {dataLock.IlrTrainingCourseCode} not found; possible expiry"); } result.DataLockWithOnlyPriceMismatch.Add(MapDataLockStatus(dataLock, training)); } result.ShowChangesRequested = result.DataLockWithCourseMismatch.Any( x => x.TriageStatusViewModel == TriageStatusViewModel.RestartApprenticeship); result.ShowChangesPending = result.DataLockWithOnlyPriceMismatch.Any( x => x.TriageStatusViewModel == TriageStatusViewModel.ChangeApprenticeship) || result.DataLockWithCourseMismatch.Any( x => x.TriageStatusViewModel == TriageStatusViewModel.ChangeApprenticeship); //Can triage a course datalock if there is one that has not been triaged, and if there isn't one that //has been triaged but is pending approval by employer (dealt with one at a time) result.ShowCourseDataLockTriageLink = result.DataLockWithCourseMismatch.Any(x => x.TriageStatusViewModel == TriageStatusViewModel.Unknown) && result.DataLockWithCourseMismatch.All(x => x.TriageStatusViewModel != TriageStatusViewModel.RestartApprenticeship); // Show ChangeLink if any not triaged PriceOnly AND NO Course+Price DL result.ShowPriceDataLockTriageLink = result.DataLockWithOnlyPriceMismatch.Any(x => x.TriageStatusViewModel == TriageStatusViewModel.Unknown); if (result.DataLockWithCourseMismatch.Any(m => m.DataLockErrorCode.HasFlag(DataLockErrorCode.Dlock07))) { result.ShowPriceDataLockTriageLink = false; } result.ShowPriceDataLockTriageLink = result.ShowPriceDataLockTriageLink || result.ShowCourseDataLockTriageLink && !hasHadDataLockSuccess; return(result); }