//Find index of product.
        public int FindIndex(string productName)
        {
            int index = OrderItems.FindIndex(x => x.ProductName == productName);

            if (index <= -1)
            {
                throw new KeyNotFoundException("Product Name Not Found");
            }
            return(index);
        }
Example #2
0
        public void UpdateItems(OrderItem orderItem)
        {
            int index = OrderItems.FindIndex(item => item.Commodity.Equals(orderItem.Commodity));

            if (index == -1)
            {
                OrderItems.Add(orderItem.DeepClone());
            }
            else
            {
                OrderItems[index].Quantity += orderItem.Quantity;
                if (OrderItems[index].Quantity <= 0)
                {
                    Delete(OrderItems[index]);
                }
            }
        }