Example #1
0
        // GET api/<controller>
        public Taxcard Get(string id)
        {
            var taxcard = new Taxcard {
                TaxPercentage = 34M, TaxcardId = id
            };

            return(taxcard);

            //GetEmployerQuery query = new GetEmployerQuery("foo");
            //return query.Execute();
        }
        public SalaryCalculationResults CalculateSalary(Taxcard taxCard, decimal grossSalary)
        {
            if (taxCard == null)
            {
                throw new SalaryCalculationException("Salary calculation requires a valid tax card.");
            }

            decimal taxPercentage = taxCard.TaxPercentage;
            decimal tax           = grossSalary * (taxPercentage / 100);
            decimal netSalary     = grossSalary - tax;

            var results = new SalaryCalculationResults();

            results.NetSalary = netSalary;
            results.Tax       = tax;

            return(results);
        }
        public override void Execute()
        {
            //The BL is not allowed to run any queries, it can not even reference this assembly containing the
            //queries because that would be a cyclical reference. We need to give all data to the BL.
            IQueryable <SalaryCalculation> previousSalaries =
                QueryRunner.ExecuteQuery(new GetSalaryCalculationsForAnEmployee(db, _employeeId));

            var validation = new SalaryCalculationValidation();

            validation.ValidateSalaryCalculationPreConditions(_periodStartDate, _periodEndDate, previousSalaries);

            string idString = _employeeId;

            Taxcard taxCard = db.Taxcards.SingleOrDefault(card => card.EmployeeId == idString);

            var calculator = new SalaryCalculator();
            SalaryCalculationResults res = calculator.CalculateSalary(taxCard, _grossSalary);

            //Saving the new calculation is not BL, that's why it is here.
            var salaryCalc = new SalaryCalculation
            {
                //EmployeeId = _employeeId,
                //GrossAmount = _grossSalary,
                //NetAmount = res.NetSalary,
                //PeriodStartDate = _periodStartDate,
                //PeriodEndDate = _periodEndDate,
                //Tax = res.Tax,
                SalaryCalculationId = Guid.NewGuid().ToString()
            };

            db.SalaryCalculations.Add(salaryCalc);

            db.SaveChanges();

            //You could argue that sending this event could be BL. Or you can say it is an infrastructural concern, like using
            //a transaction (if that was required here). However, it can not really exist in the salary calculation core because
            //the core only calculates and the whole process is not done until the result is persisted. So I would say this is
            //the right place after all.
            MessageBus.Send(new SalaryCalculationDoneEvent());
        }
Example #4
0
 // POST api/<controller>
 public void Post([FromBody] Taxcard value)
 {
 }