Пример #1
0
 public static CarModelViewModel CreateCarModelViewModel(CarModel carModel)
 {
     ApplicationDbContext db = new ApplicationDbContext();
     CarModelViewModel cmvm = new CarModelViewModel();
     cmvm.CarModelData = carModel;
     cmvm.Brands = new SelectList(db.CarBrands, "CarBrandId", "BrandName", cmvm.CarModelData.CarBrandId);
     return cmvm;
 }
Пример #2
0
 public ActionResult Create(CarModelViewModel cmvm)
 {
     if (ModelState.IsValid)
     {
         db.CarModels.Add(cmvm.CarModelData);
         db.SaveChanges();
         TempData["Added"] = cmvm.CarModelData.Description + " Added";
         return RedirectToAction("Index");
     }
     cmvm = ViewModelFactory.CreateCarModelViewModel(cmvm.CarModelData);
     return View(cmvm);
 }
Пример #3
0
 public ActionResult Edit(CarModelViewModel cmvm)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cmvm.CarModelData).State = EntityState.Modified;
         db.SaveChanges();
         TempData["Added"] = cmvm.CarModelData.Description + " Edited";
         return RedirectToAction("Index");
     }
     cmvm = ViewModelFactory.CreateCarModelViewModel(cmvm.CarModelData);
     return View(cmvm);
 }