// Called when the user submits the apply filters form to the view listings page public ActionResult ApplyListingsFilters(ViewListingsViewModel model) { CoreysListEntities db = new CoreysListEntities(); // check filters if (model.HasImageFilter == true && model.PostedTodayFilter == true) { model.Listings = db.Listings.Where(l => l.CreatedDate == DateTime.Now && l.Images.Count() > 0 && l.CityID == model.CityId && l.SubCategoryID == model.SubCatId).ToList(); } else if (model.PostedTodayFilter == true) { model.Listings = db.Listings.Where(l => l.CreatedDate == DateTime.Now && l.CityID == model.CityId && l.SubCategoryID == model.SubCatId).ToList(); } else if (model.HasImageFilter == true) { model.Listings = db.Listings.Where(l => l.Images.Count() > 0 && l.CityID == model.CityId && l.SubCategoryID == model.SubCatId).ToList(); } else { model.Listings = db.Listings.Where(l => l.CityID == model.CityId && l.SubCategoryID == model.SubCatId).ToList(); } // return the filtered listings return View("ViewListings", model); }
// called when a user clicks a subcategory id to view listings public ActionResult Index(int subcategoryId) { // check to make sure city id cookie is populated if (Request.Cookies["cityId"] != null) { // return the view listings with the city and subcategory id int cityId = Convert.ToInt32(Request.Cookies["cityId"].Value); ViewListingsViewModel model = new ViewListingsViewModel(cityId, subcategoryId); return View("ViewListings", model); } else { // there is no selected city id so send user to locator to chose a city LocatorViewModel locatorModel = new LocatorViewModel(); Response.Redirect("/Home/Locator"); return View(); } }