public static IQueryable <Airport> Where(this IQueryable <Airport> query, AirportGetBinding binding, MainContext context, int?userId = null)
        {
            var airports = context.Airports.Include(x => x.City).AsQueryable();

            if (binding.Visited.HasValue)
            {
                var visitedAirports = context.Flights.WhereUser(userId.Value)
                                      .Select(x => new { Destination = x.DestinationAirportId, Origin = x.OriginAirportId })
                                      .ToList();

                var visitedAirportIds = visitedAirports.Select(x => x.Destination)
                                        .Concat(visitedAirports.Select(x => x.Origin))
                                        .ToList();

                airports = binding.Visited.Value ? airports.Where(x => visitedAirportIds.Contains(x.Id)) : airports.Where(x => !visitedAirportIds.Contains(x.Id));
            }

            int?cityId = context.Cities.GetId(binding.CityId);

            airports = cityId.HasValue ? airports.Where(x => x.CityId == cityId) : airports;

            int?countryId = context.Countries.GetId(binding.Countryid);

            airports = countryId.HasValue ? airports.Where(x => x.City.CountryId == countryId) : airports;

            return(airports);
        }
 public long Count(AirportGetBinding binding)
 {
     using (var context = GetMainContext())
     {
         return(context.Airports.Where(binding, context, UserId)
                .LongCount());
     }
 }
 public PagedView <View.Airport> Get(AirportGetBinding binding)
 {
     using (var context = GetMainContext())
     {
         return(context.Airports.Where(binding, context, UserId)
                .WhereIf(binding.Search, x =>  x.Iata == binding.Search.ToUpper() || x.Name.ToLower().Contains(binding.Search.ToLower()))
                .Include(x => x.Poi)
                .ThenInclude(x => x.PoiCategory)
                .OrderByDescending(x =>  x.Iata == binding.Search)
                .Select(x => new View.Airport(x))
                .ToPagedView(binding));
     }
 }
示例#4
0
 public long GetCount([FromQuery] AirportGetBinding binding) => _airportHandler.Count(binding);
示例#5
0
 public PagedView <View.Airport> Get([FromQuery] AirportGetBinding binding) => _airportHandler.Get(binding);