Exemplo n.º 1
0
 public List <BeerDto> GetBeerByFilter(FilterOptionsDto filterOptions)
 {
     if (filterOptions.Id == Guid.Empty && !string.IsNullOrWhiteSpace(filterOptions.StringFilter))
     {
         //****Just with name option
         //return Context.Beer.Where(w => w.Name == filterOptions.StringFilter).Include(i=> i.BeerType).Include(i=> i.Country).Include(i=> i.City).ToBeerDtoList();
         return(WhereWithInclude <Beer>(w => w.Name == filterOptions.StringFilter, GetIncludes()).ToBeerDtoList());
     }
     else if (filterOptions.Id != Guid.Empty && string.IsNullOrWhiteSpace(filterOptions.StringFilter))
     {
         //****Just with type option
         //return Context.Beer.Where(w => w.BeerType.Id == filterOptions.Id).Include(i => i.BeerType).Include(i => i.Country).Include(i => i.City).ToBeerDtoList();
         return(WhereWithInclude <Beer>(w => w.BeerType.Id == filterOptions.Id, GetIncludes()).ToBeerDtoList());
     }
     else if (filterOptions.Id != Guid.Empty && !string.IsNullOrWhiteSpace(filterOptions.StringFilter))
     {
         //****Both Filters
         //return Context.Beer.Where(w => w.BeerType.Id == filterOptions.Id && w.Name == filterOptions.StringFilter).Include(i => i.BeerType).Include(i => i.Country).Include(i => i.City).ToBeerDtoList();
         return(WhereWithInclude <Beer>(w => w.BeerType.Id == filterOptions.Id && w.Name == filterOptions.StringFilter, GetIncludes()).ToBeerDtoList());
     }
     else
     {
         //Without Filters
         return(GetAllBeers());
     }
 }
Exemplo n.º 2
0
        public ActionResult Filter(BeerViewModelFilter filter)
        {
            var FilterOptions = new FilterOptionsDto();

            FilterOptions.StringFilter = filter.StringFilter;
            FilterOptions.Id           = filter.BeerTypeId;

            var model = new BeerViewModelIndex(filter);

            model.Filter.BeerTypeDtoList = new List <SelectListItem>
            {
                new SelectListItem
                {
                    Text  = "Select",
                    Value = "0"
                }
            }.Union(_beerTypeService.GetAll().ToSelectListItemList());
            model.BeerViewModelList = _beerService.GetBeerByFilter(FilterOptions).ToBeerViewModelList();

            return(View("Index", model));
        }