예제 #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();
 }