public ActionResult Search() { ViewBag.Title = ""; using (var context = ApplicationDbContext.Create()) { var newModel = new UnionModels { SearchModel = new SearchModels(), AdsList = context.Advertisements.Where(m => String.IsNullOrEmpty(m.RenterId)).ToList() }; return(View(newModel)); } }
public ActionResult Search(UnionModels model) { using (var context = ApplicationDbContext.Create()) { var m = model.SearchModel; if (String.IsNullOrEmpty(m.SizeFrom)) { m.SizeFrom = "0"; } if (String.IsNullOrEmpty(m.SizeTo)) { m.SizeTo = "100000000"; } if (String.IsNullOrEmpty(m.PriceFrom)) { m.PriceFrom = "0"; } if (String.IsNullOrEmpty(m.PriceTo)) { m.PriceTo = "100000000"; } if (String.IsNullOrEmpty(m.SearchLine)) { m.SearchLine = ""; } int sizeFrom = Convert.ToInt32(m.SizeFrom); int sizeTo = Convert.ToInt32(m.SizeTo); int priceFrom = Convert.ToInt32(m.PriceFrom); int priceTo = Convert.ToInt32(m.PriceTo); var ads = context.Advertisements.Where(a => (a.Header.Contains(m.SearchLine)) && a.Size >= sizeFrom && a.Size <= sizeTo && a.Price >= priceFrom && a.Price <= priceTo && String.IsNullOrEmpty(a.RenterId)).ToList(); ads = ads.OrderBy(a => a.Price).ToList(); var newModel = new UnionModels() { SearchModel = m, AdsList = ads }; return(View(newModel)); } return(View()); }