public ActionResult Create(Car car) { if (ModelState.IsValid) { db.Cars.Add(car); db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.BrandID = new SelectList(db.Brands, "BrandID", "CarBrand", car.BrandID); return View(car); }
public void AddToCart(Car car) { var cartItem = storeDB.Carts.SingleOrDefault(c => c.CartId == ShoppingCartId && c.CarID == car.CarID); if (cartItem == null) { cartItem = new Cart { CarID = car.CarID, CartId = ShoppingCartId, Count = 1, DateCreated = DateTime.Now }; storeDB.Carts.Add(cartItem); } else { cartItem.Count ++; } storeDB.SaveChanges(); }
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", "CarBrand", car.BrandID); return View(car); }