当前位置: 首页>>代码示例>>C#>>正文


C# CartItem类代码示例

本文整理汇总了C#中CartItem的典型用法代码示例。如果您正苦于以下问题:C# CartItem类的具体用法?C# CartItem怎么用?C# CartItem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CartItem类属于命名空间,在下文中一共展示了CartItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddToCart

        public void AddToCart(int id)
        {
            // Retrieve the product from the database.           
            ShoppingCartId = GetCartId();

            var cartItem = _db.ShoppingCartItems.SingleOrDefault(
                c => c.CartId == ShoppingCartId
                && c.ProductId == id);
            if (cartItem == null)
            {
                // Create a new cart item if no cart item exists.                 
                cartItem = new CartItem
                {
                    ItemId = Guid.NewGuid().ToString(),
                    ProductId = id,
                    CartId = ShoppingCartId,
                    Product = _db.Products.SingleOrDefault(
                   p => p.ProductID == id),
                    Quantity = 1,
                    DateCreated = DateTime.Now
                };

                _db.ShoppingCartItems.Add(cartItem);
            }
            else
            {
                // If the item does exist in the cart,                  
                // then add one to the quantity.                 
                cartItem.Quantity++;
            }
            _db.SaveChanges();
        }
开发者ID:JayOwl,项目名称:Shopping-Cart,代码行数:32,代码来源:ShoppingCartActions.cs

示例2: AddToCartAsync

 public bool AddToCartAsync(int cartId, int ProductID)
 {
     myHandler = new BusinessLogicHandler();
     item = new CartItem();
     item = myHandler.CheckIfExist(cartId, ProductID);
     if(item == null)
     {
         item = new CartItem();
         item.CartID = cartId;
         item.ProductID = ProductID;
         item.DateAdded = DateTime.Now;
         item.Quantity = 1;
         if (myHandler.AddCartItem(item))
         { return true; }
         else
             return false;
     }
     else
     {
         item.Quantity += 1;
         if (myHandler.UpdateCartItem(item))
         { return true; }
         else
             return false;
     }
 }
开发者ID:Gcobani,项目名称:urbanbooks,代码行数:26,代码来源:CartActions.cs

示例3: AddItem

    /**
     * AddItem() - Adds an item to the shopping
     */
    public void AddItem(int productId, int kolicina)
    {
        if (HttpContext.Current.Session["ASPNETShoppingCart"] == null)
        {
            ShoppingCart Instance;
            Instance = new ShoppingCart();
            Instance.Items = new List<CartItem>();
            HttpContext.Current.Session["ASPNETShoppingCart"] = Instance;
        }

        // Create a new item to add to the cart
        CartItem newItem = new CartItem(productId);

        // If this item already exists in our list of items, increase the quantity
        // Otherwise, add the new item to the list
        if (Items.Contains(newItem))
        {
            foreach (CartItem item in Items)
            {
                if (item.Equals(newItem))
                {
                    item.Quantity = item.Quantity + kolicina;
                    return;
                }
            }
        }
        else
        {
            newItem.Quantity = kolicina;
            Items.Add(newItem);
        }
    }
开发者ID:sokac237,项目名称:Barun-trenk,代码行数:35,代码来源:ShoppingCart.cs

示例4: btnAdd_Click

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        selectedProduct = new Product();
        this.selectedProduct.Course_id = course_id.ToString();

        if (Page.IsValid)
        {
            CartItemList cart = CartItemList.GetCart();
            int locCount = cart.Count;
            locCount = locCount + 1;
            this.selectedProduct.assignmentNumber = locCount.ToString();
            this.selectedProduct.aGUID = Guid.NewGuid().ToString();
            this.selectedProduct.Num_Assignment = locCount;
            CartItem cartItem = new CartItem();

            int Num_Assignments=0;
            int assignment = 1; //will be produced from loop according to Num_Assignments
            cart = CartItemList.GetCart();
            cartItem = cart[selectedProduct.Course_id];

            if (cartItem == null)
            {
                cart.AddItem(selectedProduct, Num_Assignments,assignment);
            }
            else
            {
                cart.AddItem(selectedProduct, Num_Assignments, assignment);
                cartItem.AddQuantity(1);
            }
            this.DisplayCart();

        }
    }
开发者ID:cweber-wou,项目名称:capstone,代码行数:33,代码来源:OrderPage.aspx.cs

示例5: AddItem

        /**
     * AddItem() - Adds an item to the shopping 
     */
        public void AddItem(int productId, string productName, int productQuantity, decimal productPrice)
        {
            // Create a new item to add to the cart
            CartItem newItem = new CartItem(productId, productName, productQuantity, productPrice);

            // If this item already exists in our list of items, increase the quantity
            // Otherwise, add the new item to the list
            if (Items.Contains(newItem))
            {
                foreach (CartItem item in Items)
                {
                    if (item.Equals(newItem))
                    {
                        //item.ProductQuantity++;
                        item.ProductQuantity += productQuantity;
                        return;
                    }
                }
            }
            else
            {
                //newItem.ProductQuantity = 1;
                Items.Add(newItem);
            }
        }
开发者ID:MarioMaio,项目名称:projeto_parte_III,代码行数:28,代码来源:ShoppingCart.cs

示例6: Add

		/// <summary>
		/// Add an item to the cart.
		/// When ItemId to be added has already existed, this method will update the quantity instead.
		/// </summary>
		/// <param name="itemId">Item Id of item to add</param>
		public void Add(string itemId)
		{
			CartItem cartItem;

			if (!_items.TryGetValue(itemId, out cartItem))
			{
				Item item = new ProductManager().GetItem(itemId);

				if (item != null)
				{
					cartItem = new CartItem();

					cartItem.ItemID     = itemId;
					cartItem.Name       = item.ProductName;
					cartItem.Price      = (decimal)item.Price;
					cartItem.Type       = item.Name;
					cartItem.CategoryID = item.CategoryID;
					cartItem.ProductID  = item.ProductID;

					_items.Add(itemId, cartItem);
				}
			}

			cartItem.Quantity++;
		}
开发者ID:MajidSafari,项目名称:bltoolkit,代码行数:30,代码来源:Cart.cs

示例7: AddItem

        public void AddItem(CartItem item)
        {
            if (Items.Contains(item))
                return;

            Items.Add(item);
        }
开发者ID:sideez,项目名称:LearningTTDCSharp,代码行数:7,代码来源:Cart.cs

示例8: AddToCart

        public void AddToCart(Product product, decimal price)
        {
            // Get the matching cart and product instances
            var cartItem = db.CartItems.SingleOrDefault(
                c => c.CartID == ShoppingCartId
                && c.ProductID == product.ProductID);

            if (cartItem == null)
            {
                // Create a new cart item if no cart item exists
                cartItem = new CartItem
                {
                    ProductID = product.ProductID,
                    CartID = ShoppingCartId,
                    Amount = 1,
                    Price = price,
                    Creation = DateTime.Now
                };

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

            // Save changes
            db.SaveChanges();
        }
开发者ID:rogerex,项目名称:shopnet,代码行数:30,代码来源:ShoppingCart.cs

示例9: Comparer_DifferentInstancesWithSameValues_ReturnsTrue

        public void Comparer_DifferentInstancesWithSameValues_ReturnsTrue()
        {
            Guid memberId = new Guid("3E522B6E-9F75-4E9A-BB11-52CE00827977");
            Guid productId = new Guid("6C7133F7-143A-4CF1-90C5-8661A4AC6B87");
            int quantity = 4;
            bool isNew = true;

            CartItem item1 = new CartItem
            {
                IsNew = isNew,
                MemberId = memberId,
                ProductId = productId,
                Quantity = quantity
            };
            CartItem item2 = new CartItem
            {
                IsNew = isNew,
                MemberId = memberId,
                ProductId = productId,
                Quantity = quantity
            };

            bool result = CartItem.CartItemComparer.Equals(item1, item2);

            Assert.That(result, Is.True);
        }
开发者ID:kylezimmerman,项目名称:prog3050,代码行数:26,代码来源:CartItemTests.cs

示例10: AddToCart

        public void AddToCart(int Id)
        {
            ShoppingCartId = GetCartid();

            var cartitem = db.CartItems.SingleOrDefault(p => p.CartId == ShoppingCartId && p.ProductId == Id);

            if (cartitem == null)
            {
                cartitem = new CartItem
                {
                    ItemId = Guid.NewGuid().ToString(),
                    CartId = GetCartid(),
                    Quantity = 1,
                    CreateDate = DateTime.Now,
                    Product = db.Products.SingleOrDefault(p => p.Id == Id),
                    ProductId = Id
                };
                db.CartItems.Add(cartitem);
            }
            else
            {
                cartitem.Quantity++;
            }
            db.SaveChanges();
        }
开发者ID:SamYao779,项目名称:WebFormCartUsingEF,代码行数:25,代码来源:CartAction.cs

示例11: AddToCart

        public CartItem AddToCart(long userId, long productId, string variationName, int quantity)
        {
            var cartItemQuery = cartItemRepository
                .Query()
                .Include(x => x.Product)
                .Where(x => x.ProductId == productId && x.UserId == userId);

            var cartItem = cartItemQuery.FirstOrDefault();

            if (cartItem == null)
            {
                cartItem = new CartItem
                {
                    UserId = userId,
                    ProductId = productId,
                    Quantity = quantity,
                    CreatedOn = DateTime.Now
                };

                cartItemRepository.Add(cartItem);
            }
            else
            {
                cartItem.Quantity = quantity;
            }

            cartItemRepository.SaveChange();

            return cartItem;
        }
开发者ID:ciker,项目名称:SimplCommerce,代码行数:30,代码来源:CartService.cs

示例12: CartItemViewModel

 public CartItemViewModel(CartItem cartItem)
 {
     ItemID = cartItem.ItemID;
     //SeasonNo = "NA";
     Category = cartItem.ItemCategory;
     QuantityRequired = cartItem.NoOfCopies;
     AmountPerItem = cartItem.Cost;
 }
开发者ID:ashu030711,项目名称:testASPMVC1,代码行数:8,代码来源:CartItemViewModel.cs

示例13: Comparer_SameInstance_ReturnsTrue

        public void Comparer_SameInstance_ReturnsTrue()
        {
            CartItem item = new CartItem();

            bool result = CartItem.CartItemComparer.Equals(item, item);

            Assert.That(result, Is.True);
        }
开发者ID:kylezimmerman,项目名称:prog3050,代码行数:8,代码来源:CartItemTests.cs

示例14: RemoveItem_should_remove_item_from_shopping_cart

        public void RemoveItem_should_remove_item_from_shopping_cart()
        {
            var cartItem = new CartItem();
            _shoppingCart.AddItem(cartItem);
            _shoppingCart.RemoveItem(cartItem);

            Assert.IsEmpty(_shoppingCart.CartItems);
        }
开发者ID:ramomex1,项目名称:SOLID,代码行数:8,代码来源:ShoppingCartTests.cs

示例15: addToCart1_Click

    protected void addToCart1_Click(object sender, EventArgs e)
    {
        //
        CartItem newItem = new CartItem(name, price, itemPic, type,
                            quantity, total, mPrice, dayDelivered, discount, prod_id);

        // Add Current product to Shopping cart when button clicked
        Profile.ShoppingCart.Items.Add(newItem);
    }
开发者ID:vjudragon,项目名称:Shopping-Cart,代码行数:9,代码来源:product-details.aspx.cs


注:本文中的CartItem类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。