public ActionResult Edit(Car car) { if (ModelState.IsValid) { db.Entry(car).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.BrandId = new SelectList(db.Brands, "BrandId", "Name", car.BrandId); return View(car); }
public ActionResult Create(Car car) { if (ModelState.IsValid) { db.Cars.Add(car); db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.BrandId = new SelectList(db.Brands, "BrandId", "Name", car.BrandId); return View(car); }
public void TestStoreCar() { using (TransactionScope ts = new TransactionScope()) using (CarsContext context = new CarsContext()) { Brand volvo = new Brand { Name = "Volvo" }; Car myVolvo = new Car { Brand = volvo, RegistrationNumber = "ABC123" }; context.Cars.Add(myVolvo); context.SaveChanges(); } }