public async Task <IActionResult> GetPetsPerPage(int pageNumber) { try { var totalCount = await _repo.CountPets(); var totalPages = Math.Ceiling((double)totalCount / 10); return(Ok(new { totalCount, totalPages, pets = await _repo.GetPetPerPage(pageNumber, 10) })); } catch (Exception ex) { _log.LogException(ex); return(BadRequest(new { status = "failed", message = "An error has occured. Kindly check back again" })); } }
public List <Pet> GetAllPetsPaged(int page, int itemsPrPage) { if (page <= 0 || itemsPrPage <= 0) { throw new InvalidDataException("CurrentPage and ItemsPage Must zero or more"); } if (page - 1 * itemsPrPage > _PetRepo.CountPets()) { throw new InvalidDataException("Index out bounds, CurrentPage is to high"); } return(_PetRepo.GetPets() .Skip((page - 1) * itemsPrPage) .Take(itemsPrPage) .ToList()); }