Example #1
0
        public VatTaxCalculator(IList <CountryVatTax> taxes)
        {
            this.taxes = new List <CountryVatTax>(taxes);

            //shorter version using LINQ:
            //defaultTax = this.taxes.FirstOrDefault(t => t.IsDefault);
            foreach (var t in this.taxes)
            {
                if (t.IsDefault)
                {
                    defaultTax = t;
                    break;
                }
            }

            if (defaultTax == null)
            {
                throw new ArgumentException("No default tax");
            }
        }
        public VatTaxCalculator(IList<CountryVatTax> taxes)
        {
            this.taxes = new List<CountryVatTax>(taxes);

            //shorter version using LINQ:
            //defaultTax = this.taxes.FirstOrDefault(t => t.IsDefault);
            foreach(var t in this.taxes)
            {
                if(t.IsDefault)
                {
                    defaultTax = t;
                    break;
                }
            }

            if(defaultTax == null)
            {
                throw new ArgumentException("No default tax");
            }
        }
        private static ShopInventory.ShopInventory GetInventory()
        {
            var taxes = new CountryVatTax[]
            {
                new CountryVatTax("BG", 0.2, true),
                new CountryVatTax("GB", 0.3, false),
                new CountryVatTax("US", 0.4, false),
                new CountryVatTax("ISIS", 10, false),
                new CountryVatTax("ZAMUNDA", 0, false)
            };

            var calculator = new VatTaxCalculator(taxes);

            var products = new Product[]
            {
                new Product(1, "BG Apples", "BG", 2, 10, calculator),
                new Product(2, "BG Pears", "BG", 3, 15, calculator),
                new Product(3, "GB Apples", "GB", 5, 10, calculator),
                new Product(4, "ISIS Apples", "ISIS", 100, 10, calculator),
                new Product(5, "ZAMUNDA Apples", "ZAMUNDA", 0, 99999, calculator)
            };

            return new ShopInventory.ShopInventory(products);
        }
Example #4
0
        public double CalculateTax(string countryId, double productPrice)
        {
            //shorter version using LINQ:
            //var tax = taxes.FirstOrDefault(t => t.CountryId == countryId);
            CountryVatTax tax = null;

            foreach (var t in taxes)
            {
                if (t.CountryId == countryId)
                {
                    tax = t;
                    break;
                }
            }

            if (tax != null)
            {
                return(CalculateTax(tax, productPrice));
            }
            else
            {
                throw new NotSupportedCountryException(countryId);
            }
        }
Example #5
0
 private double CalculateTax(CountryVatTax tax, double productPrice)
 {
     return(tax.VatTax * productPrice);
 }
 private double CalculateTax(CountryVatTax tax, double productPrice)
 {
     return tax.VatTax * productPrice;
 }