private void OnPropertyChanged(object sender, PropertyChangedEventArgs e) { TaxRateViewModel trvm = sender as TaxRateViewModel; if (trvm != null) { ReCalculateTaxes(trvm); } }
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); }
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); } }
public decimal CalculateTaxLiability(decimal pretaxEarning, TaxRateViewModel taxBracket) { return(taxBracket.BaseTaxAmount + (decimal)taxBracket.MarginalTaxRate * (pretaxEarning - taxBracket.MarginalRateFloor)); }
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); } }
public decimal CalculateTaxLiability(decimal pretaxEarning, TaxRateViewModel taxBracket) { return taxBracket.BaseTaxAmount + (decimal)taxBracket.MarginalTaxRate * (pretaxEarning - taxBracket.MarginalRateFloor); }