コード例 #1
0
 private TaxCalculatedValue PopulateTaxCalculatedValue(decimal calculatedTax, TaxToCalculateDTO taxToCalculateDTO)
 {
     return(new TaxCalculatedValue {
         ValueCalculated = calculatedTax,
         DateCalculated = DateTime.Now,
         AnnualIncome = taxToCalculateDTO.AnnualIncome,
         PostalCode = taxToCalculateDTO.PostalCode
     });
 }
コード例 #2
0
        public async Task <IActionResult> calculateTaxAsync(TaxToCalculateDTO taxToCalculateDTO)
        {
            decimal calculatedTax = 0;
            var     populatedTaxCalculatedValues = new TaxCalculatedValue();

            switch (taxToCalculateDTO.PostalCode)
            {
            case string _postalCode when taxToCalculateDTO.PostalCode == "7441":
                calculatedTax = _repo.calculateProgressiveTax(taxToCalculateDTO.AnnualIncome, ref calculatedTax);
                populatedTaxCalculatedValues = PopulateTaxCalculatedValue(calculatedTax, taxToCalculateDTO);
                _repo.Add(populatedTaxCalculatedValues);
                if (await _repo.SaveAll())
                {
                    return(Ok(populatedTaxCalculatedValues));
                }
                break;

            case string _postalCode when taxToCalculateDTO.PostalCode == "A100":
                calculatedTax = _repo.calculateFlatValue(taxToCalculateDTO.AnnualIncome, ref calculatedTax);
                populatedTaxCalculatedValues = PopulateTaxCalculatedValue(calculatedTax, taxToCalculateDTO);
                _repo.Add(populatedTaxCalculatedValues);
                if (await _repo.SaveAll())
                {
                    return(Ok(populatedTaxCalculatedValues));
                }
                break;

            case string _postalCode when taxToCalculateDTO.PostalCode == "7000":
                calculatedTax = _repo.calculateFlatRate(taxToCalculateDTO.AnnualIncome, ref calculatedTax);
                populatedTaxCalculatedValues = PopulateTaxCalculatedValue(calculatedTax, taxToCalculateDTO);
                _repo.Add(populatedTaxCalculatedValues);
                if (await _repo.SaveAll())
                {
                    return(Ok(populatedTaxCalculatedValues));
                }
                break;

            case string _postalCode when taxToCalculateDTO.PostalCode == "1000":
                calculatedTax = _repo.calculateProgressiveTax(taxToCalculateDTO.AnnualIncome, ref calculatedTax);
                populatedTaxCalculatedValues = PopulateTaxCalculatedValue(calculatedTax, taxToCalculateDTO);
                _repo.Add(populatedTaxCalculatedValues);
                if (await _repo.SaveAll())
                {
                    return(Ok(populatedTaxCalculatedValues));
                }
                break;
            }

            return(Ok(calculatedTax));
        }