Exemple #1
0
        public async Task <IActionResult> Index(int?id)
        {
            PagedAnimesViewModel viewModel = new PagedAnimesViewModel();

            if (id.HasValue && id > 0)
            {
                await this.LoadViewModelProperties(viewModel, id.Value);
            }
            else
            {
                await this.LoadViewModelProperties(viewModel, 1);
            }

            return(this.View(viewModel));
        }
Exemple #2
0
        private async Task LoadViewModelProperties(PagedAnimesViewModel viewModel, int page)
        {
            int pagesToLoad = (int)Math.Ceiling((double)await this.AnimeService.GetAllAnimesCountAsync() / NumericConstants.Number_Of_Animes_Per_Page);

            if (page > pagesToLoad)
            {
                page = pagesToLoad;
            }

            viewModel.Animes = await this.AnimeService.GetAnimesForPage(page);

            viewModel.Pagination.Pages       = this.AnimeService.LoadPages(page, pagesToLoad);
            viewModel.Pagination.PageUrl     = UrlConstants.Index_Pagination;
            viewModel.Pagination.CurrentPage = page;
        }