Ejemplo n.º 1
0
        public async Task <ActionResult> GetCars([FromQuery] CarsParameters carsParameters)
        {
            var result = await _carService.GetAllCars(carsParameters);

            var resultMetadata = new
            {
                result.TotalCount,
                result.PageSize,
                result.CurrentPage,
                result.HasPrevious,
                result.HasNext
            };

            _logger.LogInformation($"list Car length is {result.Count}");

            var carResponses = new List <CarResponse>();

            result.ForEach(c => carResponses.Add(
                               _customMapper.CarToCarResponse(c)));

            var responsesArray = carResponses.ToArray();

            Response.Headers.Add(
                "X-Pagination",
                JsonConvert.SerializeObject(resultMetadata));

            Response.Headers.Add("Access-Control-Expose-Headers", "X-Pagination");

            _logger.LogInformation($"responsesArray length is {responsesArray.Length}");

            return(Ok(new Response <CarResponse[]>(responsesArray)));
        }
Ejemplo n.º 2
0
        public async Task <PagedList <Car> > GetAllCars(CarsParameters carsParameters)
        {
            var iQueryableCars = _repository.GetIQueryableCars().OrderBy(c => c.Brand);

            return(await PagedList <Car>
                   .ToPagedList(
                       iQueryableCars,
                       carsParameters.PageNum,
                       carsParameters.PageSize));
        }