Exemplo n.º 1
0
 public static CarTypeViewModel CreateCarTypeViewModel(CarType carType)
 {
     ApplicationDbContext db = new ApplicationDbContext();
     CarTypeViewModel ectvm = new CarTypeViewModel();
     ectvm.CarTypeData = carType;
     ectvm.CarEdited = new Car();//Just to prevent it being null
     //ectvm.CarModels = new SelectList(db.CarModels, "CarModelId", "Description", ectvm.CarTypeData.CarModelId);
     return ectvm;
 }
Exemplo n.º 2
0
 public ActionResult Create(CarTypeViewModel ctvm)
 {
     if (ModelState.IsValid)
     {
         db.CarTypes.Add(ctvm.CarTypeData);
         db.SaveChanges();
         TempData["Added"] = ctvm.CarTypeData.Description + " Added";
         return RedirectToAction("Index");
     }
     ctvm = ViewModelFactory.CreateCarTypeViewModel();
     return View(ctvm);
 }
Exemplo n.º 3
0
 //public ActionResult Edit([Bind(Include = "CarTypeId,CarCode,CarModelId,DailyPrice,DailyLatePrice,Gear")] CarType carType)
 public ActionResult Edit(CarTypeViewModel ctvm)
 {
     if (ModelState.IsValid)
     {
         db.Entry(ctvm.CarTypeData).State = EntityState.Modified;
         db.SaveChanges();
         TempData["Added"] = ctvm.CarTypeData.Description + " Edited";
         return RedirectToAction("Index");
     }
     ctvm = ViewModelFactory.CreateCarTypeViewModel(ctvm.CarTypeData);
     return View(ctvm);
 }