using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; namespace Catalog26; public class PaginatedList : List { public int PageIndex { get; private set; } public int TotalPages { get; private set; } public PaginatedList(List items, int count, int pageIndex, int pageSize) { PageIndex = pageIndex; TotalPages = (int)Math.Ceiling(count / (double)pageSize); this.AddRange(items); } public bool HasPreviousPage => PageIndex > 1; public bool HasNextPage => PageIndex < TotalPages; public static async Task> CreateAsync( IQueryable source, int pageIndex, int pageSize) { var count = await source.CountAsync(); var items = await source.Skip( (pageIndex - 1) * pageSize) .Take(pageSize).ToListAsync(); return new PaginatedList(items, count, pageIndex, pageSize); } }