예제 #1
0
        public IActionResult Index()
        {
            CarIndexViewmodel indexViewmodel = new CarIndexViewmodel();

            indexViewmodel.CarList = _carService.All();

            return(View(indexViewmodel));
        }
예제 #2
0
        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));
        }
예제 #3
0
        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));
        }