Exemplo n.º 1
0
        public PagedList <Cargo> GetCargos(CargoQueryFilter filters)
        {
            var cargoes = _unitOfWork.CargoRepository.GetAll();

            //if (filters.Name != null)
            //{
            //    cargoes = cargoes.Where(x => x.Name.ToLower().Contains(filters.Name.ToLower()));
            //}

            //if (filters.Weight != null)
            //{
            //    cargoes = cargoes.Where(x => x.Weight == filters.Weight);
            //}

            //if (filters.Description != null)
            //{
            //    cargoes = cargoes.Where(x => x.Description.ToLower().Contains(filters.Description.ToLower()));
            //}

            var pagedCargoes = PagedList <Cargo> .Create(cargoes, filters.PageNumber, filters.PageSize);

            return(pagedCargoes);
        }
Exemplo n.º 2
0
        public IActionResult GetAll([FromQuery] CargoQueryFilter filters)
        {
            var cargoes    = _cargoService.GetCargos(filters);
            var cargoesDTO = _mapper.Map <IEnumerable <CargoDTO> >(cargoes);

            var metadata = new Metadata
            {
                TotalCount      = cargoes.TotalCount,
                PageSize        = cargoes.PageSize,
                CurrentPage     = cargoes.CurrentPage,
                TotalPages      = cargoes.TotalPages,
                HasNextPage     = cargoes.HasNextPage,
                HasPreviousPage = cargoes.HasPreviousPage,
            };

            var response = new Response <IEnumerable <CargoDTO> >(cargoesDTO)
            {
                meta = metadata
            };

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

            return(Ok(response));
        }