Exemplo n.º 1
0
        public async Task <IActionResult> Get([FromQuery] VehicleFilterDTO filter)
        {
            List <Vehicle> vehicles = await vehicleDAL.GetVehicles(filter);

            var vehicleDTO = mapper.Map <List <Vehicle>, List <VehicleDTO> >(vehicles);

            return(Ok(vehicleDTO));
        }
Exemplo n.º 2
0
        public async Task <IEnumerable <Vehicle> > FindVehiclesAsync(VehicleFilterDTO vehicleFilter)
        {
            using (var context = new ApplicationDBContext())
            {
                context.Database.EnsureCreated();
                var vehicles   = new List <Vehicle>();
                var statistics = context.VehicleStatistic.Include(x => x.Vehicle).AsNoTracking();

                if (!string.IsNullOrEmpty(vehicleFilter.TeamName))
                {
                    statistics = statistics.Where(x => x.Vehicle.TeamName == vehicleFilter.TeamName);
                }

                if (!string.IsNullOrEmpty(vehicleFilter.VehicleModel))
                {
                    statistics = statistics.Where(x => x.Vehicle.VehicleModel == vehicleFilter.VehicleModel);
                }

                if (vehicleFilter.ManufacturingDate.HasValue)
                {
                    statistics = statistics.Where(x => x.Vehicle.ManufacturingDate == vehicleFilter.ManufacturingDate.Value);
                }

                if (!string.IsNullOrEmpty(vehicleFilter.Status))
                {
                    statistics = statistics.Where(x => x.Status == vehicleFilter.Status);
                }

                foreach (var item in await statistics.ToListAsync())
                {
                    vehicles.Add(item.Vehicle);
                }

                if (vehicleFilter.SortOrder.HasValue && vehicleFilter.SortOrder == (int)SortOrder.ASC)
                {
                    vehicles = vehicles.OrderBy(x => x.Id).ToList();
                }
                else if (vehicleFilter.SortOrder.HasValue && vehicleFilter.SortOrder == (int)SortOrder.DESC)
                {
                    vehicles = vehicles.OrderByDescending(x => x.Id).ToList();
                }
                else
                {
                    vehicles = vehicles.OrderBy(x => x.Id).ToList();
                }

                return(vehicles);
            }
        }
        public async Task <List <Vehicle> > GetVehicles(VehicleFilterDTO filter)
        {
            var query = db.Vehicles
                        .Include(x => x.VehicleFeatures)
                        .ThenInclude(x => x.Feature)
                        .Include(x => x.Model)
                        .ThenInclude(x => x.Make)
                        .AsQueryable();

            if (filter.MakeId.HasValue && filter.MakeId > 0)
            {
                query = query.Where(x => x.Model.MakeId == filter.MakeId);
            }

            if (filter.ModelId.HasValue && filter.ModelId > 0)
            {
                query = query.Where(x => x.Model.Id == filter.ModelId);
            }

            return(await query.ToListAsync());
        }
        public async Task <IActionResult> FindVehicles(VehicleFilterDTO vehicleFilter)
        {
            var result = await this.vehicleRepository.FindVehiclesAsync(vehicleFilter);

            return(Ok(result));
        }