public async Task <IActionResult> SearchClothes([Bind("SearchText")] SearchClothesViewModel model) { var clothes = await cr.GetAllIncludedAsync(); var search = model.SearchText.ToLower(); if (string.IsNullOrEmpty(search)) { model.ClothesList = clothes; } else { var clothesList = await db.Clothes.Include(x => x.Services).Include(x => x.Reviews).OrderBy(x => x.Name) .Where(p => p.Name.ToLower().Contains(search) || p.Price.ToString("c").ToLower().Contains(search) || p.Services.Name.ToLower().Contains(search)).ToListAsync(); if (clothesList.Any()) { model.ClothesList = clothesList; } else { model.ClothesList = new List <Clothes>(); } } return(View(model)); }
public async Task <IActionResult> ListAll() { var model = new SearchClothesViewModel() { ClothesList = await cr.GetAllIncludedAsync(), SearchText = null }; return(View(model)); }