public ActionResult CreateEditCar(Car car) { if (ModelState.IsValid) { if (car.ID == 0) { CarRepository.Insert(car); } else { var editModel = CarRepository.GetById(car.ID); editModel.Make = car.Make; editModel.Model = car.Model; CarRepository.Update(editModel); } if (car.ID > 0) { return RedirectToAction("Index"); } } return View(car); }
public ActionResult CreateEditCar(int? id) { Car model = new Car(); if (id.HasValue) { model = CarRepository.GetById(id.Value); } return View(model); }