Exemple #1
0
        public static async Task <PaginatedList <T> > CreateAsync(IQueryable <T> source, int pageNumber, int pageSize, IUriService uriService)
        {
            var exists = source.Any();
            var count  = exists ? await source.CountAsync() : 0;

            var items = await source.Skip((pageNumber - 1) *pageSize).Take(pageSize).ToListAsync();

            var nextPage = pageNumber >= 1
                ? uriService.GetAll(pageNumber + 1, pageSize).ToString()
                : null;

            var previousPage = pageNumber - 1 >= 1
                ? uriService.GetAll(pageNumber - 1, pageSize).ToString()
                : null;

            return(new PaginatedList <T>(items, count, pageNumber, pageSize, nextPage, previousPage));
        }