public ProductInventory WithProduct(Product product, int quantity, bool canPurchase = true) { if (this._products.Any(x => x.Product == product)) { throw new CoreException($"{product} is existing in {this}."); } var productInventory = ProductInventory.Create(product, this, quantity, canPurchase); this._products.Add(productInventory); return(productInventory); }
public ProductInventory WithInventory(Inventory inventory, int quantity, bool canPurchase = true) { if (inventory == null) { throw CoreException.NullOrEmptyArgument(nameof(inventory)); } if (this._inventories.Any(x => x.Inventory == inventory)) { throw new CoreException($"{this} is existing in {inventory}"); } var productInventory = ProductInventory.Create(this, inventory, quantity, canPurchase); this._inventories.Add(productInventory); return(productInventory); }