Exemplo n.º 1
0
        public void AddToCart(Game game)
        {
            // Get the matching cart and game instances
            var cartItem = storeDB.Carts.SingleOrDefault(
            c => c.CartID == ShoppingCartId
            && c.GameID == game.GameID);

            if (cartItem == null)
            {
                // Create a new cart item if no cart item exists
                cartItem = new Cart
                {
                    GameID = game.GameID,
                    CartID = ShoppingCartId,
                    ItemsCount = 1,
                    DateCreated = DateTime.Now
                };

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

            // Save changes
            storeDB.SaveChanges();
        }
Exemplo n.º 2
0
        public ActionResult Create(Game game)
        {
            if (ModelState.IsValid)
            {
                db.Games.Add(game);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.PlatformID = new SelectList(db.Platforms, "PlatformID", "Name", game.PlatformID);
            ViewBag.GenreID = new SelectList(db.Genres, "GenreID", "Name", game.GenreID);
            return View(game);
        }
Exemplo n.º 3
0
 public ActionResult Edit(Game game)
 {
     if (ModelState.IsValid)
     {
         db.Entry(game).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.PlatformID = new SelectList(db.Platforms, "PlatformID", "Name", game.PlatformID);
     ViewBag.GenreID = new SelectList(db.Genres, "GenreID", "Name", game.GenreID);
     return View(game);
 }