// GET: Image public async Task <IActionResult> Index() { var allImages = await _context.Image.Include(i => i.Room).Include(i => i.Style).Take(33).ToListAsync(); var model = new FilterResultsModel(_context); model.Images = allImages; return(View(model)); }
public async Task <IActionResult> Filter(FilterResultsModel model) { List <int> roomIds = model.FilterRoomIds; List <int> styleIds = model.FilterStyleIds; var allImages = await _context.Image.ToListAsync(); FilterResultsModel newModel = new FilterResultsModel(_context); if (roomIds == null && styleIds == null) { newModel.Images = allImages; } if (styleIds != null) { var match = (from i in allImages from s in styleIds where i.StyleId == s select i).ToList(); newModel.Images = match; } if (roomIds != null) { var match = (from i in allImages from r in roomIds where i.RoomId == r select i).ToList(); newModel.Images = match; } if (styleIds != null && roomIds != null) { var match = (from i in allImages from r in roomIds from s in styleIds where i.StyleId == s where i.RoomId == r select i).ToList(); newModel.Images = match; } return(View(newModel)); }