示例#1
0
        /// <summary>
        /// calculates the tax owed based on age and salary
        /// </summary>
        public void CalculateTax(TaxViewModel viewModel)
        {
            var taxDiscount = _taxReliefBrackets.SingleOrDefault(x => viewModel.Age >= x.Min && viewModel.Age <= x.Max);

            viewModel.MonthlyTaxRelief = taxDiscount == null ? 0m : taxDiscount.Discount;

            // TODO: do we apply the tax relief before or after computing the tax owed?
            var monthlySalary = viewModel.MonthlySalary - viewModel.MonthlyTaxRelief;

            viewModel.MonthlyTaxAmount = 0m;

            // we could LINQ this but we'd lose some readability...
            foreach (var bracket in _taxBrackets)
            {
                if (monthlySalary <= bracket.Low)
                {
                    break;
                }
                var taxableAtThisRate = Math.Min(bracket.High - bracket.Low, monthlySalary - bracket.Low);
                var taxThisBand       = taxableAtThisRate * bracket.Rate;
                viewModel.MonthlyTaxAmount += taxThisBand;
            }
        }
示例#2
0
 public MainWindow()
 {
     InitializeComponent();
     DataContext = new TaxViewModel();
 }