L
L
lucky42021-03-22 23:29:57
ASP.NET
lucky4, 2021-03-22 23:29:57

How to make offset restrictions for pagination?

The repository has a method that accepts an offset and a limit:

public async Task<IList<TEntity>> GetAllPaged(int offset, int limit)
        {
            return await _context.Set<TEntity>()
                .OrderBy(property => property.Id)
                .Skip(offset)
                .Take(limit)
                .ToListAsync();
        }


And then, the service calls this method:
public async Task<IList<ProductDto>> GetPageAllAsync(PaginationFilterDto paginationFilter)
        {
            int skip = (paginationFilter.PageNumber - 1) * paginationFilter.PageSize;
            int total = await _unitOfWork.ProductRepository.GetQuantity();

            IList<Product> productsPaged = await _unitOfWork.ProductRepository.GetAllPaged(skip, paginationFilter.PageSize);

            return _mapper.Map<IList<ProductDto>>(productsPaged);
        }


Now the question is: where and how can I write a condition so that with a negative pageNumber, I would display the relevant page?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question