Esempio n. 1
0
 /// <summary>
 /// Updates the quantity of an item to the given number; If item does not exist in the cart it will be added
 /// </summary>
 /// <param name="item"></param>
 /// <param name="quantity"></param>
 /// <param name="lineTotal">optional parameter that override the line total</param>
 public void AddOrUpdate(Item item, int quantity, decimal?lineTotal = null)
 {
     if (CartItems.TryGetValue(item.Name, out CartItem cartItem))
     {
         cartItem.Quantity = quantity;
         if (lineTotal.HasValue)
         {
             cartItem.LineTotal = lineTotal.Value;
         }
     }
     else
     {
         CartItems.Add(
             item.Name,
             new CartItem()
         {
             Item      = item,
             Quantity  = quantity,
             LineTotal = lineTotal.HasValue ? lineTotal.Value : quantity * item.DefaultUnitPrice
         });
     }
 }