public async Task <IEnumerable <Models.Ecommerce.Product> > GetAllAsync(Models.Filter.ProductFilter filter) { var query = DbSet .Where(p => string.IsNullOrWhiteSpace(filter.Name) || p.Name.ToLower().Contains(filter.Name.ToLower())) .Include(p => p.Category) .Where(p => string.IsNullOrWhiteSpace(filter.Category) || p.Category.Name.ToLower().Contains(filter.Category.ToLower())) .Include(p => p.Supplier) .Where(p => string.IsNullOrWhiteSpace(filter.Supplier) || p.Supplier.Name.ToLower().Contains(filter.Supplier.ToLower())); return(await query.ToListAsync()); }
// Probably this coud be refactor to the generic controller // But for example I'll keep here public async System.Threading.Tasks.Task <Microsoft.AspNetCore.Mvc.IActionResult> Filter(Models.Filter.ProductFilter filter) { filter.AddViewData(ViewData); var list = await _service.GetAllAsync(filter); return(View(nameof(Index), list)); }