private async Task <PaginatedList <DishOrMenuListItemDto> > LoadMenues(DishesOrMenuesSearchFilter filter, CancellationToken ct)
        {
            var query = BuildMenuesQuery(filter);

            return(await query
                   .Select(m => new DishOrMenuListItemDto
            {
                Id = m.Id,
                Name = m.Name,
                Description = m.Description,
                Picture = m.Picture ?? NoDataFallbacks.NO_DATA_IMAGE,
                Price = m.Price,
                IsMenu = true,

                ChefFullName = m.MenuSections
                               .Where(ms => !ms.MenuOwns)
                               .SelectMany(ms => ms.Section.CardsSection, (ds, cs) => cs)
                               .Select(cs => cs.Card.User.FirstName + " " + cs.Card.User.LastName)
                               .FirstOrDefault(),

                ChefCity = m.MenuSections
                           .Where(ms => !ms.MenuOwns)
                           .SelectMany(ms => ms.Section.CardsSection, (ds, cs) => cs)
                           .Select(cs => cs.Card.User.UserAddresses
                                   .OrderByDescending(ua => ua.LastTimeUsed)
                                   .FirstOrDefault()
                                   .Address
                                   .City
                                   .Name)
                           .FirstOrDefault()
            })
                   .ToPaginatedListAsync(filter.PageIndex, filter.ItemsPerPage, ct));
        }
        private IQueryable <DomainModel.Menu> BuildMenuesQuery(DishesOrMenuesSearchFilter filter)
        {
            var dbQuery = context.Menu.AsQueryable();

            dbQuery = ApplyFilter(dbQuery, filter);

            return(dbQuery.Where(m => m.MenuSections
                                 .Where(ms => !ms.MenuOwns)
                                 .SelectMany(ms => ms.Section.CardsSection, (ms, cs) => cs)
                                 .Any(cs => cs.Card.IsActive && DatabaseFunctions.IsNear(
                                          cs.Card.User.Id,
                                          filter.Latitude,
                                          filter.Longitude,
                                          distanceConfig.MinDistance))));

            IQueryable <DomainModel.Menu> ApplyFilter(IQueryable <DomainModel.Menu> source, DishesOrMenuesSearchFilter filter)
            {
                if (!string.IsNullOrWhiteSpace(filter.Search))
                {
                    var search = filter.Search.ToLowerInvariant();
                    source = source.Where(m => m.Name.ToLower().Contains(search) ||
                                          m.Description.ToLower().Contains(search) ||
                                          m.MenuSections.Where(m => m.MenuOwns).Any(ms => ms.Section.DishesSection
                                                                                    .Any(ds => ds.Dish.Name.ToLower().Contains(search) ||
                                                                                         ds.Dish.Description.ToLower().Contains(search) ||
                                                                                         ds.Dish.DishCategories.Any(dc => dc.Category.Label.ToLower().Contains(search)) ||
                                                                                         ds.Dish.DishOptions.Any(dop => dop.Option.Name.ToLower().Contains(search)) ||
                                                                                         ds.Dish.DishExtras.Any(de => de.Extra.Name.ToLower().Contains(search)))) ||
                                          m.MenuOptions.Any(mo => mo.Option.Name.ToLower().Contains(search)) ||
                                          m.MenuExtras.Any(me => me.Extra.Name.ToLower().Contains(search)));
                }

                return(source);
            }
        }
Ejemplo n.º 3
0
 public async Task <PaginatedList <DishOrMenuListItemDto> > GetDishesAndMenues(DishesOrMenuesSearchFilter filter)
 {
     return(await dishService.SearchForDishesAndMenues(filter));
 }
Ejemplo n.º 4
0
 public SearchForDishesOrMenuesQuery(DishesOrMenuesSearchFilter filter, SearchDishOrMenu dishOrMenu)
 {
     Filter     = filter;
     DishOrMenu = dishOrMenu;
 }
Ejemplo n.º 5
0
 public Task <PaginatedList <DishOrMenuListItemDto> > SearchForMenues(DishesOrMenuesSearchFilter filter)
 {
     return(dishService.SearchForMenues(filter));
 }