コード例 #1
0
ファイル: CartService.cs プロジェクト: pslymagic/WebApis
        public void AddToCart(int pid)
        {
            // Get the matching cart and album instances
            var cartItem = context.Carts.SingleOrDefault(c => c.UniqueIdentifier == ShoppingCartId
                && c.ProductId == pid);

            if (cartItem == null)
            {

                cartItem = new Cart
                {
                    ProductId = pid,
                    UniqueIdentifier = ShoppingCartId,
                    Quantity = 1,
                    DateCreated = DateTime.Now
                };

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

            // Save changes
            context.SaveChanges();
        }
コード例 #2
0
 /// <summary>
 /// Create a new Cart object.
 /// </summary>
 /// <param name="cartId">Initial value of the CartId property.</param>
 /// <param name="uniqueIdentifier">Initial value of the UniqueIdentifier property.</param>
 /// <param name="productId">Initial value of the ProductId property.</param>
 public static Cart CreateCart(global::System.Int32 cartId, global::System.Guid uniqueIdentifier, global::System.Int32 productId)
 {
     Cart cart = new Cart();
     cart.CartId = cartId;
     cart.UniqueIdentifier = uniqueIdentifier;
     cart.ProductId = productId;
     return cart;
 }
コード例 #3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Carts EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCarts(Cart cart)
 {
     base.AddObject("Carts", cart);
 }