Example #1
0
        /**
         * SetItemQuantity() - Changes the quantity of an item in the cart
         */
        public void SetItemQuantity(int productId, int quantity)
        {
            // If we are setting the quantity to 0, remove the item entirely
            if (quantity == 0)
            {
                RemoveItem(productId);
                return;
            }

            // Find the item and update the quantity
            ElementyKoszyka updatedItem = new ElementyKoszyka(productId);

            foreach (ElementyKoszyka item in Items)
            {
                if (item.Equals(updatedItem))
                {
                    item.Quantity = quantity;
                    return;
                }
            }
        }
Example #2
0
        /**
         * AddItem() - Adds an item to the shopping
         */
        public void AddItem(int productId)
        {
            // Create a new item to add to the cart
            ElementyKoszyka newItem = new ElementyKoszyka(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 (ElementyKoszyka item in Items)
                {
                    if (item.Equals(newItem))
                    {
                        item.Quantity++;
                        return;
                    }
                }
            }
            else
            {
                newItem.Quantity = 1;
                Items.Add(newItem);
            }
        }
Example #3
0
        /**
         * RemoveItem() - Removes an item from the shopping cart
         */
        public void RemoveItem(int productId)
        {
            ElementyKoszyka removedItem = new ElementyKoszyka(productId);

            Items.Remove(removedItem);
        }