Esempio n. 1
0
 /// <summary>
 /// Add item
 /// </summary>
 /// <param name="item">Item</param>
 public void AddItem(CartItem item)
 {
     if (Items.Contains(item))
     {
         var index = Items.IndexOf(item);
         Items[index].Quantity += item.Quantity;
     }
     else { Items.Add(item); }
 }
Esempio n. 2
0
        /// <summary>
        /// Add item to cart
        /// </summary>
        /// <param name="inputObject">DataModel</param>
        /// <returns>DataModel</returns>
        private BuyDataModel AddInfo(BuyDataModel inputObject)
        {
            // Local variable declaration
            BuyDataModel getResult = null;
            CartCom cartCom = null;

            // Variable initialize
            getResult = new BuyDataModel();
            cartCom = new CartCom(inputObject.Cart);

            // Get data
            var cartItem = new CartItem();
            cartItem.ItemCd = inputObject.ItemCd;
            cartItem.Quantity = inputObject.ItemQtty.Value;
            cartCom.AddItem(cartItem);

            // Set value
            getResult.Cart = cartCom.Items;

            // Return value
            return getResult;
        }
Esempio n. 3
0
 /// <summary>
 /// Delete item
 /// </summary>
 /// <param name="item">Item</param>
 public void DeleteItem(CartItem item)
 {
     if (Items.Contains(item)) Items.Remove(item);
 }
Esempio n. 4
0
        /// <summary>
        /// Update item
        /// </summary>
        /// <param name="item">Item</param>
        public void UpdateItem(CartItem item)
        {
            if (Items.Contains(item))
            {
                // If we are setting the quantity to 0, remove the item entirely
                if (item.Quantity == decimal.Zero)
                {
                    DeleteItem(item);
                    return;
                }

                var index = Items.IndexOf(item);
                Items[index].Quantity = item.Quantity;
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Delete item
 /// </summary>
 /// <param name="item">ItemCd</param>
 public void DeleteItem(string itemCd)
 {
     var item = new CartItem(itemCd);
     DeleteItem(item);
 }
Esempio n. 6
0
        /// <summary>
        /// Update item to cart
        /// </summary>
        /// <param name="inputObject">DataModel</param>
        /// <returns>DataModel</returns>
        private UpdateDataModel UpdateInfo(UpdateDataModel inputObject)
        {
            // Local variable declaration
            UpdateDataModel getResult = null;
            CartCom cartCom = null;

            // Variable initialize
            getResult = new UpdateDataModel();
            cartCom = new CartCom(inputObject.Cart);

            // Get data
            foreach (var obj in inputObject.ListItems)
            {
                if (DataCheckHelper.IsNull(obj.Quantity)
                    || obj.Quantity < decimal.Zero) continue;
                var item = new CartItem();
                item.ItemCd = obj.ItemCd;
                item.Quantity = obj.Quantity.Value;
                cartCom.UpdateItem(item);
            }

            // Set value
            getResult.Cart = cartCom.Items;

            // Return value
            return getResult;
        }