Beispiel #1
0
        public List <decimal> IncomeTaxCalculatorHandler(IncomeTaxRequest request, ILambdaContext context)
        {
            if (request.Income < 0)
            {
                throw new ArgumentException("Income value must not be null.");
            }

            var calculatedIncomeTaxes = new List <decimal>();

            using (var dbContext = new IncomeTaxDbContext())
            {
                foreach (var incomeTax in dbContext.IncomeTaxes)
                {
                    if (request.Income > incomeTax.UpperLimit &&
                        incomeTax.UpperLimit > 0)
                    {
                        var tax = ((incomeTax.UpperLimit - incomeTax.LowerLimit) * incomeTax.Percentage) / 100;
                        calculatedIncomeTaxes.Add(Math.Round(tax, 2));
                    }

                    if (request.Income > incomeTax.LowerLimit &&
                        ((request.Income <= incomeTax.UpperLimit && incomeTax.UpperLimit > 0) || incomeTax.UpperLimit == 0))
                    {
                        var tax = ((request.Income - incomeTax.LowerLimit) * incomeTax.Percentage) / 100;
                        calculatedIncomeTaxes.Add(Math.Round(tax, 2));
                    }
                }
            }

            return(request.Detailed ? calculatedIncomeTaxes : new List <decimal> {
                Math.Round(calculatedIncomeTaxes.Sum(), 2)
            });
        }
 public IncomeTaxController(IncomeTaxDbContext _context)
 {
     this._context = _context;
 }
 public StudentController(IncomeTaxDbContext _context)
 {
     this._context = _context;
 }