Example #1
0
        public ActionResult GetAllShips(ApiVersion version, [FromQuery] QueryParameters queryParameters)
        {
            List <ShipEntity> shipItems = _shipRepository.GetAll(queryParameters).ToList();

            var allItemCount = _shipRepository.Count();

            var paginationMetadata = new
            {
                totalCount  = allItemCount,
                pageSize    = queryParameters.PageCount,
                currentPage = queryParameters.Page,
                totalPages  = queryParameters.GetTotalPages(allItemCount)
            };

            Response.Headers.Add("X-Pagination",
                                 Newtonsoft.Json.JsonConvert.SerializeObject(paginationMetadata));

            var links = CreateLinksForCollection(queryParameters, allItemCount, version);

            var toReturn = shipItems.Select(x => ExpandSingleShipItem(x, version));

            return(Ok(new
            {
                value = toReturn,
                links = links
            }));
        }