コード例 #1
0
        public async Task <IActionResult> GetMap([FromQuery] MapRestaurantPaginationModel model)
        {
            GetAllRestaurantsResponseModel result = await _restaurantService.GetMapAsync(User.Identity.Name, model);

            return(Ok(result));
        }
コード例 #2
0
        public async Task <GetAllRestaurantsResponseModel> GetMapAsync(string userId, MapRestaurantPaginationModel filter)
        {
            IQueryable <RestaurantEntity> a = null;

            if (filter.Cuisines != null && filter.Cuisines.Length > 0)
            {
                a = _context.Restaurants
                    .AsNoTracking()
                    .Include(x => x.Reviews)
                    .Include(x => x.Cuisines)
                    .Where(x => !x.IsBlock && x.Cuisines
                           .Any(x => filter.Cuisines.Contains(x.CuisineId)));
            }
            else
            {
                a = _context.Restaurants
                    .AsNoTracking()
                    .Include(x => x.Reviews)
                    .Include(x => x.Cuisines)
                    .Where(x => !x.IsBlock);
            }

            if (filter.DeliveryTypes != null && filter.DeliveryTypes.Length > 0)
            {
                a = a.Where(x => x.Deliveries
                            .Any(x => filter.DeliveryTypes.Contains(x.DeliveryId)));
            }

            if (filter.Latitude > 0 && filter.Longitude > 0)
            {
                Point point = new Point(filter.Latitude, filter.Longitude)
                {
                    SRID = 4326
                };
                a = a.Where(c => c.Address.Location.Distance(point) < filter.Radius);
            }

            var restaurants = await a.Where(x => x.PriceFrom <= filter.PriceFrom && x.PriceTo >= filter.PriceTo).ToListAsync();

            return(new GetAllRestaurantsResponseModel {
                Restaurants = await GetRestaurantsAsync(restaurants, userId),
                Total = restaurants.Count
            });
        }