コード例 #1
0
        public void AddToCart(Album album)
        {
            // Get the matching cart and album instances
//            var cartItem = storeDB.Carts.SingleOrDefault(
            //c => c.CartId == ShoppingCartId
            //&& c.AlbumId == album.Id);
            var cartItem = _cartsPersister.LoadByAlbumAndShoppingCartId(album.Id, ShoppingCartId);

            if (cartItem == null)
            {
                // Create a new cart item if no cart item exists
                cartItem = new Cart
                {
                    Album       = album,
                    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();
            _cartsPersister.Store(cartItem);
        }
コード例 #2
0
        public void AddToCart(Album album)
        {
            var cartItem = _cartsPersister.LoadByAlbumAndShoppingCartId(album.Id, ShoppingCartId);

            if (cartItem == null)
            {
                cartItem = new Cart
                {
                    Album       = album,
                    CartId      = ShoppingCartId,
                    Count       = 1,
                    DateCreated = DateTime.Now
                };
            }
            else
            {
                cartItem.Count++;
            }

            _cartsPersister.Store(cartItem);
        }