public IActionResult CalculateTax(string taxType, [FromBody] TaxCalculation taxCalcModel)
        {
            decimal tax = 0M;

            string  postalCode   = taxCalcModel.PostalCode;
            decimal annualIncome = taxCalcModel.AnnualIncome;

            switch (taxType)
            {
            case "Progressive":
                tax = _calculateTax.CalculateProgressiveTax(annualIncome);
                break;

            case "Flat Value":
                tax = _calculateTax.CalculateFlatValueTax(annualIncome);
                break;

            case "Flat Rate":
                tax = _calculateTax.CalculateFlatRateTax(annualIncome);
                break;
            }

            TaxCalculation calculation = new TaxCalculation()
            {
                AnnualIncome = annualIncome,
                PostalCode   = postalCode,
                TaxResult    = tax,
                Timestamp    = DateTime.Now
            };

            //Insert result in database
            _dataLayer.AddNewTaxCalculationResult(calculation);

            return(Ok(tax.ToString()));
        }
Exemple #2
0
        public void CalculateProgressiveRateTaxPass_0_to_8350_Range()
        {
            decimal annualIncome = 8350;
            var     expected     = annualIncome * 0.10M;

            var tax = _calculateTax.CalculateProgressiveTax(annualIncome);

            Assert.AreEqual(expected, tax);
            Assert.Pass();
        }