예제 #1
0
        public PaginationLessonsViewModel GetAll(int page)
        {
            if (page < 1)
            {
                page = 1;
            }

            int pageMultiplier = page - 1;

            IEnumerable <GetAllLessonsViewModel> lessons = this.dbContext.Lessons
                                                           .Select(lesson => new GetAllLessonsViewModel
            {
                Id   = lesson.Id,
                Name = lesson.Name,
            })
                                                           .Skip(pageMultiplier * LESSONS_PER_PAGE)
                                                           .Take(LESSONS_PER_PAGE)
                                                           .ToList();

            int totalPages = (int)Math.Ceiling(this.dbContext.Lessons.Count() / (double)LESSONS_PER_PAGE);
            PaginationLessonsViewModel paginationLessons = new PaginationLessonsViewModel()
            {
                Lessons     = lessons,
                CurrentPage = page,
                TotalPages  = totalPages,
            };

            return(paginationLessons);
        }
예제 #2
0
        public async Task <IActionResult> Index(int page = 1)
        {
            PaginationLessonsViewModel paginationLessons = this.lessonsService.GetAll(page);

            ApplicationUser currentUser = await this.userManager.GetUserAsync(this.User);

            if (this.User.Identity.IsAuthenticated)
            {
                this.lessonsUsersService.PopulateLessonsWithInformationAboutUsers(paginationLessons.Lessons, currentUser.Id);
            }

            return(this.View(paginationLessons));
        }