示例#1
0
 public ActionResult Create(Car car)
 {
     if (ModelState.IsValid)
     {
         car.UserId = WebSecurity.CurrentUserId;
         CarDAL.AddCar(car);
         return RedirectToAction("Index");
     }
     return View(car);
 }
示例#2
0
 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);
 }
示例#3
0
 public static void UpdateCar(Car Car)
 {
     db.Entry(Car).State = EntityState.Modified;
     db.SaveChanges();
 }
示例#4
0
 public static void AddCar(Car Car)
 {
     db.Cars.Add(Car);
     db.SaveChanges();
 }