public IViewComponentResult Invoke() { CourseSummaryViewModel vm = new CourseSummaryViewModel(); List <CourseOffering> offeringList = database.CourseOfferings.ToList <CourseOffering>(); vm.NumberOfCoursesOffered = offeringList.Count; vm.NumberOfCoursesOfferedInTheMorning = offeringList.Where(co => co.StartTime.Hour <= 12).Count(); vm.NumberOfCoursesAtCapacity = offeringList.Where(co => co.Enrollment >= (0.9 * co.Capacity)).Count(); vm.NumberOfCoursesWithSpaceLeft = offeringList.Where(co => co.Enrollment <= (0.5 * co.Capacity)).Count(); return(View(vm)); }
public void Date_fields_should_display_in_day_month_year_order() { // Given var testDateTime = new DateTime(2012, 12, 21, 22, 22, 22); var courseDetails = CourseDetailsTestHelper.GetDefaultCourseDetails( createdDate: testDateTime, lastAccessed: testDateTime ); // When var viewModel = new CourseSummaryViewModel(courseDetails); // Then using (new AssertionScope()) { viewModel.CreatedDate.Should().Be("21/12/2012"); viewModel.LastAccessed.Should().Be("21/12/2012"); } }
public IActionResult Index(Guid?courseId, Guid?courseRunId) { Course course = null; CourseRun courseRun = null; if (courseId.HasValue) { course = _courseService.GetCourseByIdAsync(new GetCourseByIdCriteria(courseId.Value)).Result.Value; courseRun = course.CourseRuns.Where(x => x.id == courseRunId.Value).FirstOrDefault(); } CourseSummaryViewModel vm = new CourseSummaryViewModel { ProviderUKPRN = course.ProviderUKPRN, CourseId = course.id, QualificationCourseTitle = course.QualificationCourseTitle, LearnAimRef = course.LearnAimRef, NotionalNVQLevelv2 = course.NotionalNVQLevelv2, AwardOrgCode = course.AwardOrgCode, CourseDescription = course.CourseDescription, EntryRequirements = course.EntryRequirements, WhatYoullLearn = course.WhatYoullLearn, HowYoullLearn = course.HowYoullLearn, WhatYoullNeed = course.WhatYoullNeed, HowYoullBeAssessed = course.HowYoullBeAssessed, WhereNext = course.WhereNext, IsValid = course.IsValid, QualificationType = course.QualificationType, //Course run deets CourseInstanceId = courseRunId, CourseName = courseRun.CourseName, VenueId = courseRun.VenueId, Cost = courseRun.Cost, CostDescription = courseRun.CostDescription, DurationUnit = courseRun.DurationUnit, DurationValue = courseRun.DurationValue, ProviderCourseID = courseRun.ProviderCourseID, DeliveryMode = courseRun.DeliveryMode, National = courseRun.DeliveryMode == DeliveryMode.WorkBased & !courseRun.National.HasValue || courseRun.National.GetValueOrDefault(), FlexibleStartDate = courseRun.FlexibleStartDate, StartDate = courseRun.StartDate, StudyMode = courseRun.StudyMode, AttendancePattern = courseRun.AttendancePattern, CreatedBy = courseRun.CreatedBy, CreatedDate = courseRun.CreatedDate, }; //Determine newer edited date if (course.UpdatedDate > courseRun.UpdatedDate) { vm.UpdatedDate = course.UpdatedDate; vm.UpdatedBy = course.UpdatedBy; } else { vm.UpdatedDate = courseRun.UpdatedDate; vm.UpdatedBy = courseRun.UpdatedBy; } if (vm.VenueId != null) { if (vm.VenueId != Guid.Empty) { vm.VenueName = _venueService .GetVenueByIdAsync(new GetVenueByIdCriteria(courseRun.VenueId.Value.ToString())).Result.Value .VenueName; } } if (!string.IsNullOrEmpty(courseRun.CourseURL)) { if (courseRun.CourseURL.Contains("http") || courseRun.CourseURL.Contains("https")) { vm.CourseURL = courseRun.CourseURL; } else { vm.CourseURL = "http://" + courseRun.CourseURL; } } if (courseRun.Regions != null) { var allRegions = _courseService.GetRegions().RegionItems; var regions = GetRegions().RegionItems.Select(x => x.Id); vm.Regions = FormattedRegionsByIds(allRegions, courseRun.Regions); } return(View(vm)); }
public async Task <IActionResult> Index(Guid?courseId, Guid?courseRunId) { Course course = null; CourseRun courseRun = null; if (courseId.HasValue) { course = await _sqlQueryDispatcher.ExecuteQuery(new GetCourse() { CourseId = courseId.Value }); courseRun = course.CourseRuns.Where(x => x.CourseRunId == courseRunId.Value).FirstOrDefault(); } CourseSummaryViewModel vm = new CourseSummaryViewModel { ProviderUKPRN = course.ProviderUkprn, CourseId = course.CourseId, QualificationCourseTitle = course.LearnAimRefTitle, LearnAimRef = course.LearnAimRef, NotionalNVQLevelv2 = course.NotionalNVQLevelv2, AwardOrgCode = course.AwardOrgCode, CourseDescription = course.CourseDescription, EntryRequirements = course.EntryRequirements, WhatYoullLearn = course.WhatYoullLearn, HowYoullLearn = course.HowYoullLearn, WhatYoullNeed = course.WhatYoullNeed, HowYoullBeAssessed = course.HowYoullBeAssessed, WhereNext = course.WhereNext, IsValid = true, QualificationType = course.LearnAimRefTypeDesc, //Course run deets CourseInstanceId = courseRunId, CourseName = courseRun.CourseName, VenueId = courseRun.VenueId, Cost = courseRun.Cost, CostDescription = courseRun.CostDescription, DurationUnit = courseRun.DurationUnit, DurationValue = courseRun.DurationValue, ProviderCourseID = courseRun.ProviderCourseId, DeliveryMode = courseRun.DeliveryMode, National = courseRun.DeliveryMode == CourseDeliveryMode.WorkBased & !courseRun.National.HasValue || courseRun.National.GetValueOrDefault(), FlexibleStartDate = courseRun.FlexibleStartDate, StartDate = courseRun.StartDate, StudyMode = courseRun.StudyMode, AttendancePattern = courseRun.AttendancePattern, CreatedDate = courseRun.CreatedOn, }; //Determine newer edited date if (course.UpdatedOn > courseRun.UpdatedOn) { vm.UpdatedDate = course.UpdatedOn; } else { vm.UpdatedDate = courseRun.UpdatedOn; } if (vm.VenueId != null) { if (vm.VenueId != Guid.Empty) { var venue = await _sqlQueryDispatcher.ExecuteQuery(new GetVenue() { VenueId = courseRun.VenueId.Value }); vm.VenueName = venue?.VenueName; } } if (!string.IsNullOrEmpty(courseRun.CourseWebsite)) { if (courseRun.CourseWebsite.Contains("http") || courseRun.CourseWebsite.Contains("https")) { vm.CourseURL = courseRun.CourseWebsite; } else { vm.CourseURL = "http://" + courseRun.CourseWebsite; } } if (courseRun.SubRegionIds?.Count > 0) { var allRegions = _courseService.GetRegions().RegionItems; var regions = GetRegions().RegionItems.Select(x => x.Id); vm.Regions = FormattedRegionsByIds(allRegions, courseRun.SubRegionIds); } return(View(vm)); }