Last active
April 28, 2023 20:01
-
-
Save pedrovasconcellos/590d069f03a916e51340c97b996053fb to your computer and use it in GitHub Desktop.
Pagination
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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