public IActionResult Courses(CoursesSortOrder?order, int page = 1) { int PageSize = 20; var courses = coursesService.GetUserCourses(userManager.GetUserId(User)); if (order.HasValue) { coursesService.SortCourses(ref courses, order.Value); } var viewModel = new UserCoursesViewData { Announcements = announcementsService.GetUserAnnouncements(userManager.GetUserId(User)), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = courses.Count } }; viewModel.Courses = courses.Skip((page - 1) * PageSize).Take(PageSize).ToList(); return(View(viewModel)); }