public void Buy(Product item) { this.Items.Add(item); }
public void Remove(Product item) { var itemToRemove = this.Items.LastOrDefault(i => i.Name.Equals(item.Name)); if (itemToRemove != null) { this.Items.Remove(itemToRemove); } }
public void BuyProducts() { var importedCD = new Product("imported CD", 10.99m, SalesTaxType.Default, DutyTaxType.Import); var perfume = new Product("perfume", 19.99m, SalesTaxType.Default, DutyTaxType.Domestic); var headachePills = new Product("headache pills", 4.65m, SalesTaxType.Medical, DutyTaxType.Domestic); var importedChocolates = new Product("imported chocolates", 16.45m, SalesTaxType.Food, DutyTaxType.Import); ShoppingCart shoppingCart = new ShoppingCart(); shoppingCart.Buy(importedCD); shoppingCart.Buy(perfume); shoppingCart.Buy(headachePills); shoppingCart.Buy(importedChocolates); #region Manually Dependency Injection. // Builds all calculators. List<ICalculator> calculators = new List<ICalculator> { new DefaultTaxCalculator(), new FoodTaxCalculator(), new BookTaxCalculator(), new MedicalTaxCalculator(), new DomesticTaxCalculator(), new ImportTaxCalculator() }; // Builds ICalculatorResolver instance and injects all calculators. ICalculatorResolver calculatorResolver = new CalculatorResolver(calculators); // Builds ITaxService instance and injects ICalculatorResolver. ITaxService taxService = new TaxService(calculatorResolver); // Builds Cashier instance and injects ITaxService. Cashier cashier = new Cashier(taxService); #endregion cashier.Checkout(shoppingCart); }