public IActionResult Get(UserParameters parameters) { if (!_entityHelperService.EntityHasProperties <User>(parameters.Fields)) { return(BadRequest()); } var users = _repository.Pagination <UserDto>(parameters); string previousPage = users.HasPrevious ? CreateResourceUri(parameters, ResourceUriType.PreviousPage) : null; string nextPage = users.HasNext ? CreateResourceUri(parameters, ResourceUriType.NextPage) : null; var result = Mapper.Map <List <UserDto> >(users); var paginationMetadata = new { totalCount = users.TotalCount, pageSize = users.PageSize, currentPage = users.CurrentPage, totalPages = users.TotalPages, previousPageLink = previousPage, nextPageLink = nextPage }; Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(paginationMetadata)); return(Ok(result.ShapeData(parameters.Fields))); }
public IActionResult Get(PostParameters parameters) { if (!_entityHelperServices.EntityHasProperties <Post>(parameters.Fields)) { return(BadRequest()); } var posts = _repository.Pagination <PostDto>(parameters); if (posts == null) { return(NotFound()); } string previousPage = posts.HasPrevious ? CreateResourceUri(parameters, ResourceUriType.PreviousPage) : null; string nextPage = posts.HasNext ? CreateResourceUri(parameters, ResourceUriType.NextPage) : null; var paginationMetadata = new { totalCount = posts.TotalCount, pageSize = posts.PageSize, currentPage = posts.CurrentPage, totalPages = posts.TotalPages, previousPageLink = previousPage, nextPageLink = nextPage }; Response.Headers.Add("X-PaginationResources", JsonConvert.SerializeObject(paginationMetadata)); var vm = Mapper.Map <List <PostDto> >(posts); return(Ok(vm.ShapeData(parameters.Fields))); }