internal IEnumerable <CsvApprenticeship> ApprenticeshipsToCsvApprenticeships(IEnumerable <Apprenticeship> apprenticeships) { List <CsvApprenticeship> csvApprenticeships = new List <CsvApprenticeship>(); foreach (var apprenticeship in apprenticeships) { foreach (var apprenticeshipLocation in apprenticeship.ApprenticeshipLocations) { //Sanitise regions if (apprenticeshipLocation.Regions != null) { if (apprenticeshipLocation.Regions.Any()) { apprenticeshipLocation.Regions = _CSVHelper.SanitiseRegionTextForCSVOutput(apprenticeshipLocation.Regions); } } var csvApprenticeshipLocation = MapCsvApprenticeship(apprenticeship, apprenticeshipLocation); csvApprenticeships.Add(csvApprenticeshipLocation); } } return(csvApprenticeships); }
private IEnumerable <CsvCourse> CoursesToCsvCourses(IEnumerable <Course> courses) { List <CsvCourse> csvCourses = new List <CsvCourse>(); foreach (var course in courses) { //First course run is on same line as course line in CSV var courseRuns = course.CourseRuns.Where(r => r.RecordStatus == RecordStatus.Live).ToArray(); if (!courseRuns.Any()) { continue; } var firstCourseRun = courseRuns.First(); if (firstCourseRun.Regions != null) { firstCourseRun.Regions = _CSVHelper.SanitiseRegionTextForCSVOutput(firstCourseRun.Regions); } SelectRegionModel selectRegionModel = new SelectRegionModel(); CsvCourse csvCourse = new CsvCourse { LearnAimRef = course.LearnAimRef != null?_CSVHelper.SanitiseTextForCSVOutput(course.LearnAimRef) : string.Empty, CourseDescription = !string.IsNullOrWhiteSpace(course.CourseDescription) ? _CSVHelper.SanitiseTextForCSVOutput(course.CourseDescription) : string.Empty, EntryRequirements = !string.IsNullOrWhiteSpace(course.EntryRequirements) ? _CSVHelper.SanitiseTextForCSVOutput(course.EntryRequirements) : string.Empty, WhatYoullLearn = !string.IsNullOrWhiteSpace(course.WhatYoullLearn) ? _CSVHelper.SanitiseTextForCSVOutput(course.WhatYoullLearn) : string.Empty, HowYoullLearn = !string.IsNullOrWhiteSpace(course.HowYoullLearn) ? _CSVHelper.SanitiseTextForCSVOutput(course.HowYoullLearn) : string.Empty, WhatYoullNeed = !string.IsNullOrWhiteSpace(course.WhatYoullNeed) ? _CSVHelper.SanitiseTextForCSVOutput(course.WhatYoullNeed) : string.Empty, HowYoullBeAssessed = !string.IsNullOrWhiteSpace(course.HowYoullBeAssessed) ? _CSVHelper.SanitiseTextForCSVOutput(course.HowYoullBeAssessed) : string.Empty, WhereNext = !string.IsNullOrWhiteSpace(course.WhereNext) ? _CSVHelper.SanitiseTextForCSVOutput(course.WhereNext) : string.Empty, AdvancedLearnerLoan = course.AdvancedLearnerLoan ? "Yes" : "No", AdultEducationBudget = course.AdultEducationBudget ? "Yes" : "No", CourseName = firstCourseRun.CourseName != null?_CSVHelper.SanitiseTextForCSVOutput(firstCourseRun.CourseName) : string.Empty, ProviderCourseID = firstCourseRun.ProviderCourseID != null?_CSVHelper.SanitiseTextForCSVOutput(firstCourseRun.ProviderCourseID) : string.Empty, DeliveryMode = firstCourseRun.DeliveryMode.ToDescription(), StartDate = firstCourseRun.StartDate.HasValue ? firstCourseRun.StartDate.Value.ToString("dd/MM/yyyy") : string.Empty, FlexibleStartDate = firstCourseRun.FlexibleStartDate ? "Yes" : string.Empty, National = firstCourseRun.National.HasValue ? (firstCourseRun.National.Value ? "Yes" : "No") : string.Empty, Regions = firstCourseRun.Regions != null?_CSVHelper.SemiColonSplit( selectRegionModel.RegionItems .Where(x => firstCourseRun.Regions.Contains(x.Id)) .Select(y => _CSVHelper.SanitiseTextForCSVOutput(y.RegionName).Replace(",", "")).ToList()) : string.Empty, SubRegions = firstCourseRun.Regions != null?_CSVHelper.SemiColonSplit( selectRegionModel.RegionItems.SelectMany( x => x.SubRegion.Where( y => firstCourseRun.Regions.Contains(y.Id)).Select( z => _CSVHelper.SanitiseTextForCSVOutput(z.SubRegionName).Replace(",", "")).ToList())) : string.Empty, CourseURL = firstCourseRun.CourseURL != null?_CSVHelper.SanitiseTextForCSVOutput(firstCourseRun.CourseURL) : string.Empty, Cost = firstCourseRun.Cost.HasValue ? firstCourseRun.Cost.Value.ToString() : string.Empty, CostDescription = firstCourseRun.CostDescription != null?_CSVHelper.SanitiseTextForCSVOutput(firstCourseRun.CostDescription) : string.Empty, DurationValue = firstCourseRun.DurationValue.HasValue ? firstCourseRun.DurationValue.Value.ToString() : string.Empty, DurationUnit = firstCourseRun.DurationUnit.ToDescription(), StudyMode = firstCourseRun.StudyMode.ToDescription(), AttendancePattern = firstCourseRun.AttendancePattern.ToDescription() }; if (firstCourseRun.VenueId.HasValue) { var result = _cosmosDbQueryDispatcher.ExecuteQuery( new GetVenueById() { VenueId = firstCourseRun.VenueId.Value }).Result; if (!string.IsNullOrWhiteSpace(result?.VenueName)) { csvCourse.VenueName = result.VenueName; } } csvCourses.Add(csvCourse); foreach (var courseRun in courseRuns) { //Ignore the first course run as we've already captured it if (courseRun.id == firstCourseRun.id) { continue; } //Sanitise regions if (courseRun.Regions != null) { courseRun.Regions = _CSVHelper.SanitiseRegionTextForCSVOutput(courseRun.Regions); } CsvCourse csvCourseRun = new CsvCourse { LearnAimRef = course.LearnAimRef != null?_CSVHelper.SanitiseTextForCSVOutput(course.LearnAimRef) : string.Empty, CourseName = courseRun.CourseName != null?_CSVHelper.SanitiseTextForCSVOutput(courseRun.CourseName) : string.Empty, ProviderCourseID = courseRun.ProviderCourseID != null?_CSVHelper.SanitiseTextForCSVOutput(courseRun.ProviderCourseID) : string.Empty, DeliveryMode = courseRun.DeliveryMode.ToDescription(), StartDate = courseRun.StartDate.HasValue ? courseRun.StartDate.Value.ToString("dd/MM/yyyy") : string.Empty, FlexibleStartDate = courseRun.FlexibleStartDate ? "Yes" : string.Empty, National = courseRun.National.HasValue ? (courseRun.National.Value ? "Yes" : "No") : string.Empty, Regions = courseRun.Regions != null?_CSVHelper.SemiColonSplit( selectRegionModel.RegionItems .Where(x => courseRun.Regions.Contains(x.Id)) .Select(y => _CSVHelper.SanitiseTextForCSVOutput(y.RegionName).Replace(",", "")).ToList()) : string.Empty, SubRegions = courseRun.Regions != null?_CSVHelper.SemiColonSplit( selectRegionModel.RegionItems.SelectMany( x => x.SubRegion.Where( y => courseRun.Regions.Contains(y.Id)).Select( z => _CSVHelper.SanitiseTextForCSVOutput(z.SubRegionName).Replace(",", "")).ToList())) : string.Empty, CourseURL = courseRun.CourseURL != null?_CSVHelper.SanitiseTextForCSVOutput(courseRun.CourseURL) : string.Empty, Cost = courseRun.Cost.HasValue ? courseRun.Cost.Value.ToString() : string.Empty, CostDescription = courseRun.CostDescription != null?_CSVHelper.SanitiseTextForCSVOutput(courseRun.CostDescription) : string.Empty, DurationValue = courseRun.DurationValue.HasValue ? courseRun.DurationValue.Value.ToString() : string.Empty, DurationUnit = courseRun.DurationUnit.ToDescription(), StudyMode = courseRun.StudyMode.ToDescription(), AttendancePattern = courseRun.AttendancePattern.ToDescription() }; if (courseRun.VenueId.HasValue) { var result = _cosmosDbQueryDispatcher.ExecuteQuery(new GetVenueById() { VenueId = courseRun.VenueId.Value }).Result; if (!string.IsNullOrWhiteSpace(result?.VenueName)) { csvCourseRun.VenueName = result.VenueName; } } csvCourses.Add(csvCourseRun); } } return(csvCourses); }