public async Task <IActionResult> Filter(FindContractorsViewModel model) { List <int> serviceIds = model.FilterServiceIds; if (serviceIds == null) { return(RedirectToAction("Index")); } var user = await GetCurrentUserAsync(); var allContractors = await _context.Contractor.Include(i => i.User).Include(f => f.Services).Where(u => u.User.StreetAddress == user.StreetAddress).ToListAsync(); var allContractorServices = await _context.ContractorServices.ToListAsync(); var contractorServices = (from c in allContractorServices from s in serviceIds where c.ServiceId == s select c).ToList(); var filteredContractors = (from c in allContractors from s in contractorServices where c.ContractorId == s.ContractorId select c).ToList(); FindContractorsViewModel newModel = new FindContractorsViewModel(_context); newModel.Contractors = filteredContractors; newModel.CurrentUser = user; return(View(newModel)); }
public async Task <IActionResult> Index() { var user = await GetCurrentUserAsync(); var contractors = await _context.Contractor.Include(i => i.User).Include(c => c.Services).Where(u => u.User.StreetAddress == user.StreetAddress).ToListAsync(); var model = new FindContractorsViewModel(_context); model.CurrentUser = user; model.Contractors = contractors; return(View(model)); }