public static PagedResponse <T> CreatePaginatedResponse <T>(IUriService uriService, PaginationFilter paginationFilter, List <T> response) { var nextPage = paginationFilter.PageNumber >= 1 ? uriService .GetAllPostsUri(new PaginationQuery(paginationFilter.PageNumber + 1, paginationFilter.PageSize)) .ToString() : null; var previousPage = paginationFilter.PageNumber - 1 >= 1 ? uriService .GetAllPostsUri(new PaginationQuery(paginationFilter.PageNumber - 1, paginationFilter.PageSize)) .ToString() : null; var paginationResponse = new PagedResponse <T> { Data = response, PageNumber = paginationFilter.PageNumber >= 1 ? paginationFilter.PageNumber : (int?)null, PageSize = paginationFilter.PageSize >= 1 ? paginationFilter.PageSize : (int?)null, NextPage = response.Any() ? nextPage : null, PreviousPage = previousPage }; return(paginationResponse); }
public async Task <IActionResult> GetAll([FromQuery] PaginationQuerry paginationQuerry) { var pagination = _mapper.Map <PaginationFilter>(paginationQuerry); var posts = await _postService.GetAll_Async(pagination); var postResponse = _mapper.Map <List <PostResponse> >(posts); if (paginationQuerry == null || paginationQuerry.PageNumber < 1 || paginationQuerry.PageSize < 1) { return(Ok(new PageResponse <PostResponse>(postResponse))); } var nextPage = pagination.PageNumber >= 1 ? _uriService.GetAllPostsUri(new PaginationQuerry { PageNumber = pagination.PageNumber + 1, PageSize = pagination.PageSize }).ToString():null; var previousPage = pagination.PageNumber - 1 >= 1 ? _uriService.GetAllPostsUri(new PaginationQuerry { PageNumber = pagination.PageNumber - 1, PageSize = pagination.PageSize }).ToString() : null; var paginationResponse = new PageResponse <PostResponse> { Data = postResponse, PageNumber = pagination.PageNumber, PageSize = pagination.PageSize, NextPage = postResponse.Any() ? nextPage : null, PreviousPage = previousPage }; return(Ok(paginationResponse)); }
internal static PagedResponse <T> CreatePaginatedResponse <T>(IUriService uriService, PaginationFilter paginationFilter, List <T> postResponse) { var nextPageUri = paginationFilter.PageNumber >= 1 ? uriService.GetAllPostsUri(new PaginationFilter { PageNumber = paginationFilter.PageNumber + 1, PageSize = paginationFilter.PageSize }).ToString() : null; var previousPageUri = paginationFilter.PageNumber - 1 >= 1 ? uriService.GetAllPostsUri(new PaginationFilter { PageNumber = paginationFilter.PageNumber - 1, PageSize = paginationFilter.PageSize }).ToString() : null; return(new PagedResponse <T> { Data = postResponse, PageNumber = paginationFilter.PageNumber >= 1 ? paginationFilter.PageNumber : (int?)null, PageSize = paginationFilter.PageSize >= 1 ? paginationFilter.PageSize : (int?)null, NextPage = postResponse.Any() ? nextPageUri : null, PreviousPage = previousPageUri }); }
public static PagedResponse <T> CreatePaginationResponse <T>(IUriService uriService, PaginationFilter pagination, List <T> response) { //lấy uri để query lấy post ở next page var nextPage = pagination.PageNumber >= 1 ? uriService .GetAllPostsUri(new PaginationQuery(pagination.PageNumber + 1, pagination.PageSize)).ToString() : null; //lấy uri để query lấy post ở previous page var previousPage = pagination.PageNumber - 1 >= 1 ? uriService .GetAllPostsUri(new PaginationQuery(pagination.PageNumber - 1, pagination.PageSize)).ToString() : null; return(new PagedResponse <T> { Data = response, NextPage = response.Any() ? nextPage : null, PreviousPage = previousPage, PageNumber = pagination.PageNumber >= 1 ? pagination.PageNumber : (int?)null, PageSize = pagination.PageSize >= 1 ? pagination.PageSize : (int?)null }); }
public static PagedPostResponse CreatePaginationResponse(IUriService uriService, PaginationFilter filter, List <PostDto> posts) { //lấy uri để query lấy post ở next page var nextPage = filter.PageNumber >= 1 ? uriService .GetAllPostsUri(new PaginationQuery(filter.PageNumber + 1, filter.PageSize)).ToString() : null; //lấy uri để query lấy post ở previous page var previousPage = filter.PageNumber - 1 >= 1 ? uriService .GetAllPostsUri(new PaginationQuery(filter.PageNumber - 1, filter.PageSize)).ToString() : null; return(new PagedPostResponse { postDtos = posts, NextPage = posts.Any() ? nextPage : null, PreviousPage = previousPage, PageNumber = filter.PageNumber >= 1 ? filter.PageNumber : (int?)null, PageSize = filter.PageSize >= 1 ? filter.PageSize : (int?)null }); }