public ActionResult <IEnumerable <TodoItemResponseDTO> > GetTodoItems([FromQuery] QueryParameters queryParameters) { try { List <TodoEntity> items = _todoRepository.GetAll(queryParameters).ToList(); var allItemCount = _todoRepository.Count(); var totalPageCount = Math.Ceiling(allItemCount / (double)queryParameters.PageCount); var paginationMetadata = new { totalCount = allItemCount, pageSize = queryParameters.PageCount, currentPage = queryParameters.Page, totalPages = totalPageCount }; Response.Headers.Add("X-Pagination", Newtonsoft.Json.JsonConvert.SerializeObject(paginationMetadata)); return(Ok(new { value = items })); } catch (Exception ex) { _logger.LogError(String.Concat("An unhanded error occured when getting items: ", ex.Message)); return(StatusCode(500)); } }
public ActionResult <IEnumerable <TodoDto> > Get([FromQuery] QueryParameters queryParameters) { var items = _todoRepository.GetAll(queryParameters); var allItemCount = _todoRepository.Count(); var paginationMetadata = new { totalCount = allItemCount, pageSize = queryParameters.PageCount, currentPage = queryParameters.Page, totalPages = queryParameters.GetTotalPages(allItemCount) }; Response.Headers.Add("X-Pagination", JsonSerializer.Serialize(paginationMetadata)); return(Ok(items.Select(x => _mapper.Map <TodoDto>(x)))); }