public IActionResult Find(FindGoodView model) { List <Good> goods = new List <Good>(); if (ModelState.IsValid) { var allGoods = unitOfWork.Goods.GetAll().ToList(); foreach (var good in allGoods) { bool addToResult = true; if (model.Name == null && model.ProducerName == null && model.EndPrice - model.StartPrice == 0 && model.YearOfManufacture == 0 && model.Type == null) { addToResult = false; } if (model.Name != null && good.Name != model.Name) { addToResult = false; } if (model.YearOfManufacture != null && good.YearOfManufacture != model.YearOfManufacture) { addToResult = false; } if (model.ProducerName != null && good.Producer.Name != model.ProducerName) { addToResult = false; } if (model.EndPrice - model.StartPrice != 0 && good.Price < model.StartPrice || good.Price > model.EndPrice) { addToResult = false; } if (model.Type != null && good.Type != model.Type) { addToResult = false; } if (addToResult) { goods.Add(good); } } HttpContext.Session.Set("list", goods); return(RedirectToAction("FindResult", "Good")); } return(View(model)); }
private bool AddToResult(FindGoodView model, Good good) { bool addToResult = true; if (model.Name == null && model.ProducerName == null && model.EndPrice - model.StartPrice == 0 && model.YearOfManufacture == 0 && model.Type == null) { addToResult = false; } if (model.Name != null && good.Name != model.Name) { addToResult = false; } if (model.YearOfManufacture != null && good.YearOfManufacture != model.YearOfManufacture) { addToResult = false; } if (model.ProducerName != null && good.Producer.Name != model.ProducerName) { addToResult = false; } if (model.EndPrice - model.StartPrice != 0 && good.Price < model.StartPrice || good.Price > model.EndPrice) { addToResult = false; } if (model.Type != null && good.Type != model.Type) { addToResult = false; } return(addToResult); }
public IActionResult Find(FindGoodView model) { List <Good> goods = new List <Good>(); if (ModelState.IsValid) { var allGoods = unitOfWork.Goods.GetAll().ToList(); foreach (var good in allGoods) { if (this.AddToResult(model, good)) { goods.Add(good); } } HttpContext.Session.Set("list", goods); return(RedirectToAction("FindResult", "Good")); } return(View(model)); }