コード例 #1
0
        private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            TaxRateViewModel trvm = sender as TaxRateViewModel;

            if (trvm != null)
            {
                ReCalculateTaxes(trvm);
            }
        }
コード例 #2
0
        private TaxRateViewModel FindApplicableTaxRate(decimal value)
        {
            TaxRateViewModel result = null;

            foreach (var taxBracket in TaxSchedule)
            {
                if (value > taxBracket.RangeStart && value <= taxBracket.RangeEnd)
                {
                    result = taxBracket;
                    break;
                }
            }
            if (result == null)
            {
                throw new InvalidOperationException("Could not find applicable tax bracket");
            }
            return(result);
        }
コード例 #3
0
        private void ReCalculateTaxes(TaxRateViewModel updatedRate)
        {
            try
            {
                List <TaxReturnViewModel> affected = new List <TaxReturnViewModel>();
                foreach (var item in TaxReturns)
                {
                    TaxRateViewModel newRate = null;
                    try
                    {
                        newRate = FindApplicableTaxRate(item.PreTaxEarnings);
                    }
                    catch (InvalidOperationException)
                    {
                        item.TaxLiability    = decimal.Zero;
                        item.MarginalTaxRate = 0;
                    }
                    if (newRate == updatedRate)
                    {
                        affected.Add(item);
                    }
                }
                //var affected = from e in Earnings
                //               where FindApplicableTaxRate(e) == updatedRate
                //               let taxReturn = from r in TaxReturns
                //                               where r.PreTaxEarnings == e
                //                               select r
                //               select taxReturn;

                foreach (var item in affected)
                {
                    var newTax = CalculateTaxLiability(item.PreTaxEarnings, updatedRate);
                    item.TaxLiability    = newTax;
                    item.MarginalTaxRate = updatedRate.MarginalTaxRate;
                }
            }
            catch (InvalidOperationException ex)
            {
                Console.Error.WriteLine(ex.Message);
            }
        }
コード例 #4
0
 public decimal CalculateTaxLiability(decimal pretaxEarning, TaxRateViewModel taxBracket)
 {
     return(taxBracket.BaseTaxAmount + (decimal)taxBracket.MarginalTaxRate * (pretaxEarning - taxBracket.MarginalRateFloor));
 }
コード例 #5
0
        private void ReCalculateTaxes(TaxRateViewModel updatedRate)
        {
            try
            {
                List<TaxReturnViewModel> affected = new List<TaxReturnViewModel>();
                foreach (var item in TaxReturns)
                {
                    TaxRateViewModel newRate = null;
                    try
                    {
                        newRate = FindApplicableTaxRate(item.PreTaxEarnings);
                    }
                    catch (InvalidOperationException)
                    {
                        item.TaxLiability = decimal.Zero;
                        item.MarginalTaxRate = 0;
                    }
                    if (newRate == updatedRate)
                    {
                        affected.Add(item);
                    }
                }
                //var affected = from e in Earnings
                //               where FindApplicableTaxRate(e) == updatedRate
                //               let taxReturn = from r in TaxReturns
                //                               where r.PreTaxEarnings == e
                //                               select r
                //               select taxReturn;

                foreach (var item in affected)
                {
                    var newTax = CalculateTaxLiability(item.PreTaxEarnings, updatedRate);
                    item.TaxLiability = newTax;
                    item.MarginalTaxRate = updatedRate.MarginalTaxRate;
                }
            }
            catch (InvalidOperationException ex)
            {
                Console.Error.WriteLine(ex.Message);
            }
        }
コード例 #6
0
 public decimal CalculateTaxLiability(decimal pretaxEarning, TaxRateViewModel taxBracket)
 {
     return taxBracket.BaseTaxAmount + (decimal)taxBracket.MarginalTaxRate * (pretaxEarning - taxBracket.MarginalRateFloor);
 }