[HttpGet] //działa public async Task <JsonResult> GetAllCourses([FromQuery] int page, [FromQuery] int threadsPerPage = 10) { var model = await _courseService.GetCourses(page, threadsPerPage); var result = new CourseListingViewModel(model); return(Json(result)); }
public async Task <JsonResult> GetCoursesFromStudent([FromQuery] string studentId) { var student = await _userService.GetUserByIdAsync(studentId); var model = _courseService.GetCoursesFromStudent(student); var result = new CourseListingViewModel(model); return(Json(result)); }
public async Task <JsonResult> GetCoursesFromTeacher([FromQuery] string teacherId, [FromQuery] int page, [FromQuery] int threadsPerPage = 10) { var teacher = await _userService.GetUserByIdAsync(teacherId); var model = await _courseService.GetCoursesFromTeacher(teacher, page, threadsPerPage); var result = new CourseListingViewModel(model); return(Json(result)); }
public CourseSearchResultLocationTests() { courseDetailsView = new _MVC_Views_CourseSearchResults_CourseDetail_cshtml(); courseListingViewModel = new CourseListingViewModel { LocationLabel = "LocationLabel", ProviderLabel = "ProviderLabel", AdvancedLoanProviderLabel = "AdvancedLoanProviderLabel", StartDateLabel = "StartDateLabel", Course = new Course() }; }
// GET: Course public async Task <IActionResult> Index(string courseName, string searchString) { var courses = from m in _context.Courses select m; if (!String.IsNullOrEmpty(searchString)) { courses = courses.Where(s => s.Name.Contains(searchString)); } var courseListingVM = new CourseListingViewModel(); courseListingVM.Courses = await courses.ToListAsync(); return(View(courseListingVM)); }
public void Dfc7055CourseDetailsViewTests( Course course, string providerLabel, string advancedLoanProviderLabel, string locationLabel, string startDateLabel) { // Assign var courseDetailsView = new _MVC_Views_CourseSearchResults_CourseDetail_cshtml(); var viewModel = new CourseListingViewModel { Course = course, ProviderLabel = providerLabel, AdvancedLoanProviderLabel = advancedLoanProviderLabel, LocationLabel = locationLabel, StartDateLabel = startDateLabel }; // Act var htmlDom = courseDetailsView.RenderAsHtml(viewModel); // Assert AssertTagInnerTextValue(htmlDom, viewModel.AdvancedLoanProviderLabel, "span"); AssertTagInnerTextValue(htmlDom, viewModel.ProviderLabel, "span"); if (!string.IsNullOrWhiteSpace(viewModel.Course.Location)) { AssertTagInnerTextValue(htmlDom, viewModel.LocationLabel, "span"); } else { AssertTagInnerTextValueDoesNotExist(htmlDom, viewModel.LocationLabel, "span"); } if (viewModel.Course.QualificationLevel.ToLowerInvariant().Contains("unknown")) { AssertTagInnerTextValueDoesNotExist(htmlDom, viewModel.Course.QualificationLevel, "li"); } else { AssertTagInnerTextValue(htmlDom, viewModel.Course.QualificationLevel, "li"); } }
public void Dfc7055CourseDetailsViewTests( Course course, string providerLabel, string advancedLoanProviderLabel, string locationLabel, string startDateLabel) { // Assign var courseDetailsView = new _MVC_Views_CourseSearchResults_CourseDetail_cshtml(); var viewModel = new CourseListingViewModel { Course = course, ProviderLabel = providerLabel, AdvancedLoanProviderLabel = advancedLoanProviderLabel, LocationLabel = locationLabel, StartDateLabel = startDateLabel }; // Act var htmlDom = courseDetailsView.RenderAsHtml(viewModel); // Assert // AssertTagInnerTextValue(htmlDom, viewModel.AdvancedLoanProviderLabel, "span"); AssertTagInnerTextValue(htmlDom, viewModel.ProviderLabel, "span"); if (viewModel.Course.LocationDetails != null) { AssertTagInnerTextValue(htmlDom, viewModel.LocationLabel, "span"); if (!viewModel.Course.LocationDetails.Distance.Equals(default(float))) { AssertTagInnerTextValue(htmlDom, "miles)", "li"); } } else { AssertTagInnerTextValueDoesNotExist(htmlDom, viewModel.LocationLabel, "span"); } }
public void CourseListingVMTest() { // arrange Course course1 = new Course(); course1.ID = 77; course1.Name = "Advanced Anger Management"; course1.Teacher = "Bob Saget"; course1.CourseTerm = CourseTerm.Fall2018; Course course2 = new Course(); course2.ID = 88; course2.Name = "Making Unit Tests"; course2.Teacher = "Ron Testmaster"; course2.CourseTerm = CourseTerm.Winter2018; CourseListingViewModel courseLVM = new CourseListingViewModel(); List <Course> demCourses = new List <Course> { course1, course2 }; courseLVM.Courses = demCourses; courseLVM.Course = course2; var result1 = courseLVM.Courses.FirstOrDefault(c => c.ID == 77); var result2 = courseLVM.Courses.FirstOrDefault(c => c.ID == 88); Assert.Equal(course1, result1); Assert.Equal(course2, result2); Assert.Equal(2, courseLVM.Courses.Count()); Assert.Equal(course2, courseLVM.Course); }