public ActionResult Create(Car car) { if (ModelState.IsValid) { car.UserId = WebSecurity.CurrentUserId; CarDAL.AddCar(car); return RedirectToAction("Index"); } return View(car); }
public ActionResult Edit(Car car) { try { if (ModelState.IsValid) { CarDAL.UpdateCar(car); return RedirectToAction("Index"); } } catch { //Log the error (add a variable name after DataException) ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator."); } ViewBag.UserId = car.UserId; return View(car); }
public static void UpdateCar(Car Car) { db.Entry(Car).State = EntityState.Modified; db.SaveChanges(); }
public static void AddCar(Car Car) { db.Cars.Add(Car); db.SaveChanges(); }