public ActionResult SearchEngine(int?page) { setUsername(); var priceRange = Request["priceRange"]; var locationSelect = Request["locationSelect"]; var txtSearch = Request["txtSearch"]; var optionList = context.locations.Where(o => o.id != null).ToList(); ViewData["optionList"] = optionList; if (priceRange == "Dưới 300.000VNĐ") { model = context.hotels.OrderByDescending(h => h.id).Where(h => (h.location.location_name == locationSelect && (h.sell_price < 300000) && h.hotel_name.Contains(txtSearch))).ToPagedList(page ?? 1, 9); } if (priceRange == "300.000- 500.000VNĐ") { model = context.hotels.OrderByDescending(h => h.id).Where(h => (h.location.location_name == locationSelect && (h.sell_price >= 300000 && h.sell_price < 500000) && h.hotel_name.Contains(txtSearch))).ToPagedList(page ?? 1, 9); } if (priceRange == "500.000- 1.000.000VNĐ") { model = context.hotels.OrderByDescending(h => h.id).Where(h => (h.location.location_name == locationSelect && (h.sell_price >= 500000 && h.sell_price < 1000000) && h.hotel_name.Contains(txtSearch))).ToPagedList(page ?? 1, 9); } var minPrice = model.Min(h => h.sell_price); var maxPrice = model.Max(h => h.sell_price); ViewData["minPrice"] = minPrice.ToString(); ViewData["maxPrice"] = maxPrice.ToString(); ViewData["count"] = model.Count.ToString(); ViewData["priceRange"] = priceRange.ToString(); ViewData["locationSelect"] = locationSelect.ToString(); ViewData["txtSearch"] = txtSearch.ToString(); return(View("List", model)); }
public ActionResult SearchEngine(int?page) { setUsername(); var priceRange = Request["priceRange"]; var locationSelect = Request["locationSelect"]; var txtSearch = Request["txtSearch"]; var optionList = JsonConvert.DeserializeObject <List <location> >(client.FEOpitionList()); //var optionList = context.locations.Where(o => o.id != null).ToList(); ViewData["optionList"] = optionList; if (priceRange == "Dưới 300.000VNĐ") { //model = context.homestays.OrderByDescending(h => h.id).Where(h => (h.location.location_name == locationSelect && (h.sell_price < 300000) && h.homestay_name.Contains(txtSearch))).ToPagedList(page ?? 1, 9); model = JsonConvert.DeserializeObject <List <homestay> >(client.FEFindHomestayByPriceLow(page, txtSearch, locationSelect)).ToPagedList(page ?? 1, 9); } if (priceRange == "300.000- 500.000VNĐ") { //model = context.homestays.OrderByDescending(h => h.id).Where(h => (h.location.location_name == locationSelect && (h.sell_price >= 300000 && h.sell_price < 500000) && h.homestay_name.Contains(txtSearch))).ToPagedList(page ?? 1, 9); model = JsonConvert.DeserializeObject <List <homestay> >(client.FEFindHomestayByPriceMedium(page, txtSearch, locationSelect)).ToPagedList(page ?? 1, 9); } if (priceRange == "500.000- 1.000.000VNĐ") { //model = context.homestays.OrderByDescending(h => h.id).Where(h => (h.location.location_name == locationSelect && (h.sell_price >= 500000 && h.sell_price < 1000000) && h.homestay_name.Contains(txtSearch))).ToPagedList(page ?? 1, 9); model = JsonConvert.DeserializeObject <List <homestay> >(client.FEFindHomestayByPriceHigh(page, txtSearch, locationSelect)).ToPagedList(page ?? 1, 9); } var minPrice = model.Min(h => h.sell_price); var maxPrice = model.Max(h => h.sell_price); ViewData["minPrice"] = minPrice.ToString(); ViewData["maxPrice"] = maxPrice.ToString(); ViewData["count"] = model.Count.ToString(); ViewData["priceRange"] = priceRange.ToString(); ViewData["locationSelect"] = locationSelect.ToString(); ViewData["txtSearch"] = txtSearch.ToString(); return(View("List", model)); }