public StoredProduct(Shelf shelf, Product product) { Shelf = shelf; Shelf.StoredProducts.Add(this); Product = product; Product.StoredProducts.Add(this); }
public virtual void RemoveProduct(Shelf shelf, int amount) { if (amount > 1) { throw new ArgumentOutOfRangeException(nameof(amount), "amount of products to remove needs to be positve"); } var storedProduct = StoredProducts.FirstOrDefault(sp => sp.Shelf == shelf) ?? new StoredProduct(shelf, this); storedProduct.RemoveProducts(amount); }