Пример #1
0
        public void AddToCart(Costume costume)
        {
            // Get the matching cart and costume instances
            var cartItem = storeDB.Carts.SingleOrDefault(
            c => c.CartId == ShoppingCartId
            && c.CostumeId == costume.CostumeId);

            if (cartItem == null)
            {
                // Create a new cart item if no cart item exists
                cartItem = new Cart
                {
                    CostumeId = costume.CostumeId,
                    CartId = ShoppingCartId,
                    Count = 1,
                    DateCreated = DateTime.Now
                };

                storeDB.Carts.Add(cartItem);
            }
            else
            {
                // If the item does exist in the cart, then add one to the quantity
                cartItem.Count++;
            }

            // Save changes
            storeDB.SaveChanges();
        }
        public ActionResult Create(Costume costume)
        {
            if (ModelState.IsValid)
            {
                db.Costumes.Add(costume);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.Genres = new SelectList(db.Genres, "GenreId", "Name", costume.GenreId);
            return View(costume);
        }
 public ActionResult Edit(Costume costume)
 {
     if (ModelState.IsValid)
     {
         db.Entry(costume).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.Genres = new SelectList(db.Genres, "GenreId", "Name", costume.GenreId);
     return View(costume);
 }