示例#1
0
        public async Task <List <RestaurantDto> > GetByFilter(RestaurantFilterDto filter)
        {
            var restaurantList = await _dataProvider.GetRestaurantList();

            if (!string.IsNullOrEmpty(filter.Location))
            {
                filter.Location = filter.Location.ToLower();
                restaurantList  = restaurantList.Where(x => x.Suburb.ToLower().Contains(filter.Location) || x.City.ToLower().Contains(filter.Location)).ToList();
            }

            if (!string.IsNullOrEmpty(filter.Keyword))
            {
                filter.Keyword = filter.Keyword.ToLower();
                restaurantList = restaurantList.Where(r => r.Categories.Any(c => c.Name.ToLower().Contains(filter.Keyword)) || r.Categories.Any(c => c.MenuItems.Any(m => m.Name.ToLower().Contains(filter.Keyword)))).ToList();

                foreach (var restaurant in restaurantList)
                {
                    restaurant.Categories = restaurant.Categories.Where(x => x.Name.ToLower().Contains(filter.Keyword) || x.MenuItems.Any(m => m.Name.ToLower().Contains(filter.Keyword))).ToList();

                    foreach (var category in restaurant.Categories)
                    {
                        if (!category.Name.ToLower().Contains(filter.Keyword))
                        {
                            category.MenuItems = category.MenuItems.Where(x => x.Name.ToLower().Contains(filter.Keyword)).ToList();
                        }
                    }
                }
            }

            restaurantList = restaurantList.OrderByDescending(x => x.Categories.SelectMany(x => x.MenuItems).Count()).ThenByDescending(x => x.Rank).ToList();

            return(_mapper.Map <List <RestaurantDto> >(restaurantList));
        }
示例#2
0
        public async Task <IList <RestaurantEntity> > GetAll(RestaurantFilterDto queryParameters)
        {
            var allItems =
                _TestDbContext.RestaurantEntities
                .Include(r => r.Cuisine)
                .ThenInclude(cuisine => cuisine.CuisineEntity)
                .Where(r => queryParameters.FamilyFriendly.HasValue
                        ? r.FamilyFriendly == queryParameters.FamilyFriendly.Value
                        : !queryParameters.FamilyFriendly.HasValue
                       )
                .Where(r => queryParameters.VeganOptions.HasValue
                        ? r.VeganOptions == queryParameters.VeganOptions.Value
                        : !queryParameters.VeganOptions.HasValue
                       )
                .Where(r => !string.IsNullOrWhiteSpace(queryParameters.Name)
                        ? r.Name.ToLower().Contains(queryParameters.Name.ToLower())
                        : string.IsNullOrWhiteSpace(queryParameters.Name)
                       );

            if (!string.IsNullOrWhiteSpace(queryParameters.CuisineTagIds))
            {
                var ids = StringToIntList(queryParameters.CuisineTagIds).ToList();
                allItems = allItems.Where(r => r.Cuisine.Any(c =>
                                                             ids.IndexOf(c.CuisineId) > -1));
            }

            return(await allItems.ToListAsync());;
        }
示例#3
0
        public async Task <IList <RestaurantDto> > GetAll(RestaurantFilterDto q)
        {
            await Task.Delay(500);

            if (!string.IsNullOrWhiteSpace(q.Name))
            {
                _restaurants = _restaurants.Where(r => r.Name.Contains(q.Name)).ToList();
            }
            if (q.FamilyFriendly.HasValue)
            {
                _restaurants = _restaurants.Where(r => r.FamilyFriendly == q.FamilyFriendly.Value).ToList();
            }
            if (!string.IsNullOrWhiteSpace(q.CuisineTagIds))
            {
                var tagIds = StringToIntList(q.CuisineTagIds).ToList();
                _restaurants = _restaurants.Where(r =>
                                                  r.CuisineTagIds.Any(t => tagIds.IndexOf(t) > -1))
                               .ToList();
            }
            return(_restaurants);
        }
        public async Task <ActionResult> GetByFilter([FromBody] RestaurantFilterDto filter)
        {
            var result = await _restaurantService.GetByFilter(filter);

            return(Ok(result));
        }
示例#5
0
        public ActionResult GetAllItems(ApiVersion version, [FromQuery] RestaurantFilterDto queryParameters)
        {
            var restaurants = _restaurantService.GetAll(queryParameters);

            return(Ok(restaurants));
        }
示例#6
0
 public async Task <IList <RestaurantDto> > GetAll(RestaurantFilterDto queryParameters)
 {
     return(_mapper.Map <IList <RestaurantDto> >((await _restaurantRepository.GetAll(queryParameters))));
 }