예제 #1
0
 public ShoppingCartCookie(ProductCookie productCookie)
 {
     Products = new List <ProductCookie>()
     {
         productCookie
     };
 }
예제 #2
0
 public void AddProduct(ProductCookie productCookie)
 {
     if (productCookie == null)
     {
         throw new ArgumentNullException(nameof(productCookie));
     }
     if (Products.Any(p => p.InventoryId == productCookie.InventoryId))
     {
         var product = Products.FirstOrDefault(p => p.InventoryId == productCookie.InventoryId);
         if (product != null)
         {
             product.IncreaseAmount();
         }
         else
         {
             throw new Exception("Something went wrong inside appending a cookie");
         }
     }
     else
     {
         Products.Add(productCookie);
     }
 }