public IActionResult Index() { CarIndexViewmodel indexViewmodel = new CarIndexViewmodel(); indexViewmodel.CarList = _carService.All(); return(View(indexViewmodel)); }
public IActionResult Delete(int id) { if (_carService.Remove(id)) { ViewBag.msg = "Car was removed."; } else { ViewBag.msg = "Unable to remove car with id: " + id; } CarIndexViewmodel indexViewmodel = new CarIndexViewmodel(); indexViewmodel.CarList = _carService.All(); return(View("Index", indexViewmodel)); }
public IActionResult Index(CarIndexViewmodel indexViewmodel) { if (ModelState.IsValid) { if (indexViewmodel.BeforeYear < indexViewmodel.AfterYear) { return(View(indexViewmodel)); } else { foreach (var item in _carService.All()) { if (item.Year <= indexViewmodel.BeforeYear && item.Year >= indexViewmodel.AfterYear) { indexViewmodel.CarList.Add(item); } } } } return(View(indexViewmodel)); }