Skip to content

Instantly share code, notes, and snippets.

@pedrovasconcellos
Last active April 28, 2023 20:01
Show Gist options
  • Save pedrovasconcellos/590d069f03a916e51340c97b996053fb to your computer and use it in GitHub Desktop.
Save pedrovasconcellos/590d069f03a916e51340c97b996053fb to your computer and use it in GitHub Desktop.
Pagination
public async Task<IActionResult> Example(int? page, int? rows)
{
IList<object> entities = await _service.Get();
if (page != null && page > 0 && rows != null && rows > 0)
{
entities = query.Skip((int)(rows * (page - 1))).Take((int)rows).ToList();
}
else
entities = query.ToList();
Request.HttpContext.Response.Headers.Add("Access-Control-Expose-Headers", "X-Total-Count");
Request.HttpContext.Response.Headers.Add("X-Total-Count", entities.Count().ToString());
return this.Ok(_mapper.Map<List<object>>(entities));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment