示例#1
0
        private async Task <ViewModel> CreateViewModel(int rowNumber)
        {
            var providerId = _providerContextProvider.GetProviderId();

            var rootRow = await _fileUploadProcessor.GetCourseUploadRowDetailForProvider(providerId, rowNumber);

            if (rootRow == null)
            {
                throw new ResourceDoesNotExistException(ResourceType.CourseUploadRow, rowNumber);
            }

            var rowGroup = await _fileUploadProcessor.GetCourseUploadRowGroupForProvider(providerId, rootRow.CourseId);

            var deliveryModes = DeduceDeliveryModes();

            var groupErrors = rowGroup.First().Errors
                              .Where(e => Core.DataManagement.Errors.GetCourseErrorComponent(e) == CourseErrorComponent.Course)
                              .ToArray();

            var learnAimRef      = rowGroup.Select(r => r.LearnAimRef).Distinct().Single();
            var learningDelivery = (await _sqlQueryDispatcher.ExecuteQuery(new GetLearningDeliveries()
            {
                LearnAimRefs = new[] { learnAimRef }
            }))[learnAimRef];

            return(new ViewModel()
            {
                DeliveryModes = deliveryModes,
                LearnAimRef = learnAimRef,
                LearnAimRefTitle = learningDelivery.LearnAimRefTitle,
                RowNumber = rowNumber,
                GroupErrorFields = groupErrors.Select(e => Core.DataManagement.Errors.MapCourseErrorToFieldGroup(e)).Distinct().ToArray()
            });

            IReadOnlyCollection <CourseDeliveryMode> DeduceDeliveryModes()
            {
                var deliveryModes = new HashSet <CourseDeliveryMode>();

                var allRowsHaveValidDeliveryMode = true;

                foreach (var row in rowGroup)
                {
                    var rowDeliveryMode = ParsedCsvCourseRow.ResolveDeliveryMode(row.DeliveryMode);

                    if (rowDeliveryMode != null)
                    {
                        deliveryModes.Add(rowDeliveryMode.Value);
                    }
                    else
                    {
                        allRowsHaveValidDeliveryMode = false;
                        break;
                    }
                }

                return((allRowsHaveValidDeliveryMode ? deliveryModes : (IEnumerable <CourseDeliveryMode>)_allDeliveryModes)
                       .OrderBy(dm => (int)dm)
                       .ToArray());
            }
        }
示例#2
0
            private UpsertCourseUploadRowsRecord CreateRecord(
                Guid courseId,
                Guid courseRunId,
                string learnAimRef,
                string whoThisCourseIsFor,
                string entryRequirements,
                string whatYouWillLearn,
                string howYouWillLearn,
                string whatYouWillNeedToBring,
                string howYouWillBeAssessed,
                string whereNext,
                string courseName,
                string providerCourseRef,
                string deliveryMode,
                string startDate,
                string flexibleStartDate,
                string venueName,
                string providerVenueRef,
                string nationalDelivery,
                string subRegions,
                string courseWebpage,
                string cost,
                string costDescription,
                string duration,
                string durationUnit,
                string studyMode,
                string attendancePattern,
                Guid?venueId,
                IEnumerable <string> errors = null)
            {
                var errorsArray = errors?.ToArray() ?? Array.Empty <string>();
                var isValid     = !errorsArray.Any();

                return(new UpsertCourseUploadRowsRecord()
                {
                    RowNumber = _records.Count + 2,
                    IsValid = isValid,
                    Errors = errorsArray,
                    CourseId = courseId,
                    CourseRunId = courseRunId,
                    LearnAimRef = learnAimRef,
                    WhoThisCourseIsFor = whoThisCourseIsFor,
                    EntryRequirements = entryRequirements,
                    WhatYouWillLearn = whatYouWillLearn,
                    HowYouWillLearn = howYouWillLearn,
                    WhatYouWillNeedToBring = whatYouWillNeedToBring,
                    HowYouWillBeAssessed = howYouWillBeAssessed,
                    WhereNext = whereNext,
                    CourseName = courseName,
                    ProviderCourseRef = providerCourseRef,
                    DeliveryMode = deliveryMode,
                    StartDate = startDate,
                    FlexibleStartDate = flexibleStartDate,
                    VenueName = venueName,
                    ProviderVenueRef = providerVenueRef,
                    NationalDelivery = nationalDelivery,
                    SubRegions = subRegions,
                    CourseWebpage = courseWebpage,
                    Cost = cost,
                    CostDescription = costDescription,
                    Duration = duration,
                    DurationUnit = durationUnit,
                    StudyMode = studyMode,
                    AttendancePattern = attendancePattern,
                    VenueId = venueId,
                    ResolvedDeliveryMode = ParsedCsvCourseRow.ResolveDeliveryMode(deliveryMode),
                    ResolvedStartDate = ParsedCsvCourseRow.ResolveStartDate(startDate),
                    ResolvedFlexibleStartDate = ParsedCsvCourseRow.ResolveFlexibleStartDate(flexibleStartDate),
                    ResolvedNationalDelivery = ParsedCsvCourseRow.ResolveNationalDelivery(nationalDelivery, subRegions),
                    ResolvedCost = ParsedCsvCourseRow.ResolveCost(cost),
                    ResolvedDuration = ParsedCsvCourseRow.ResolveDuration(duration),
                    ResolvedDurationUnit = ParsedCsvCourseRow.ResolveDurationUnit(durationUnit),
                    ResolvedStudyMode = ParsedCsvCourseRow.ResolveStudyMode(studyMode),
                    ResolvedAttendancePattern = ParsedCsvCourseRow.ResolveAttendancePattern(attendancePattern),
                    ResolvedSubRegions = ParsedCsvCourseRow.ResolveSubRegions(subRegions, _allRegions)?.Select(r => r.Id)
                });
            }