public async Task <PagedList <Vehiculo> > GetVehiculos(VehiculoQueryFilter filters, ResourceLocation resourceLocation) { var vehiculos = await _unitOfWork.VehiculoRepository.GetAll(); vehiculos = filters.Matricula != null?vehiculos.Where(x => x.Matricula == filters.Matricula) : vehiculos; vehiculos = filters.Placa != null?vehiculos.Where(x => x.Placa == filters.Placa) : vehiculos; vehiculos = filters.Lanzamiento != null?vehiculos.Where(x => x.Lanzamiento == filters.Lanzamiento.ToString()) : vehiculos; return(_pagedGenerator.GeneratePagedList(GetItemsOrdered(vehiculos, resourceLocation), filters)); }
public async Task <ActionResult <IEnumerable <VehiculoDTO> > > Get([FromQuery] VehiculoQueryFilter filters) { var location = new ResourceLocation() { Scheme = Request.Scheme, Host = Request.Host.Value, PathBase = Request.PathBase }; var vehiculos = await _vehiculoService.GetVehiculos(filters, location); var vehiculoDTO = _mapper.Map <IEnumerable <VehiculoDTO> >(vehiculos); var metadata = new MetaData().BuildMeta <Vehiculo>(vehiculos, filters, Request.Path.Value, _uriService); var response = new ApiResponse <IEnumerable <VehiculoDTO> >(vehiculoDTO) { Meta = metadata }; Request.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata)); return(Ok(response)); }