Esempio n. 1
0
        public void AddToWishList(Game game)
        {
            var wishListItem = storeDB.WishLists.SingleOrDefault(
                w => w.WishListId == WishListId &&
                     w.GameId == game.GameId);

            if (wishListItem == null)
            {
                // create a new wishlist item if none exists
                wishListItem = new WishList()
                {
                    GameId = game.GameId,
                    WishListId = WishListId,
                    Count = 1,
                    DateCreated = DateTime.Now
                };

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

            storeDB.SaveChanges();
        }
Esempio n. 2
0
        public void AddToCart(Game game)
        {
            var cartItem = storeDB.Carts.SingleOrDefault(
                c => c.CartId == ShoppingCartId &&
                     c.GameId == game.GameId);

            if (cartItem == null)
            {
                // Create a new cart item if no cart exists
                cartItem = new Cart
                {
                    GameId = game.GameId,
                    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++;
            }

            storeDB.SaveChanges();
        }