public void AddToCart(Car car) { // Get the matching cart and car instances /*var cartItem = catalogDB.Carts.SingleOrDefault( c => c.CartId == ShoppingCartId && c.CarId == car.CarId);*/ ShoppingCartDAL dal = new ShoppingCartDAL(); var cartItem = dal.MatchingCarAndCart(ShoppingCartId,car); if (cartItem == null) { // Create a new cart item if no cart item exists cartItem = new Cart { CarId = car.CarId, CartId = ShoppingCartId, Count = 1, DateCreated = DateTime.Now }; /*catalogDB.Carts.Add(cartItem);*/ dal.AddCartItem(cartItem); } else { // If the item does exist in the cart, then add one to the quantity cartItem.Count++; } // Save changes /*catalogDB.SaveChanges();*/ dal.SaveChangestoCart(); }
public Cart MatchingCarAndCart(string ShoppingCartId, Car car) { var cartItem = catalogDB.Carts.SingleOrDefault( c => c.CartId == ShoppingCartId && c.CarId == car.CarId); return (cartItem); }
public ActionResult Create(Car car) { if (ModelState.IsValid) { CatalogManagerDAL dal = new CatalogManagerDAL(); dal.createStore(car); return RedirectToAction("Index"); } /* ViewBag.BrandId = new SelectList(db.Brands, "BrandId", "Name", car.BrandId); ViewBag.AutoId = new SelectList(db.Autos, "AutoId", "Name", car.AutoId); return View(car);*/ CatalogManagerDAL dal2 = new CatalogManagerDAL(); List<SelectList> id = dal2.create(); ViewBag.BrandId = id[0]; ViewBag.AutoId = id[1]; return View(car); }
public void editStore(Car car) { db.Entry(car).State = EntityState.Modified; db.SaveChanges(); }
public void createStore(Car car) { db.Cars.Add(car); db.SaveChanges(); }
public ActionResult Edit(Car car) { if (ModelState.IsValid) { db.Entry(car).State = EntityState.Modified; db.SaveChanges(); /* CatalogManagerDAL dal = new CatalogManagerDAL(); dal.editStore(car); return RedirectToAction("Index");*/ } /*ViewBag.BrandId = new SelectList(db.Brands, "BrandId", "Name", car.BrandId); ViewBag.AutoId = new SelectList(db.Autos, "AutoId", "Name", car.AutoId);*/ CatalogManagerDAL dal2 = new CatalogManagerDAL(); List<SelectList> id = dal2.create(); ViewBag.BrandId = id[0]; ViewBag.AutoId = id[1]; return View(car); }