public async Task <IActionResult> CalculateBonus([FromBody] CalculateBonusDto request)
        {
            if (request == null || request.SelectedEmployeeId == 0)
            {
                return(ErrorResponse());
            }

            var employee = await _employeeService.GetEmployee(request.SelectedEmployeeId);

            if (employee == null)
            {
                return(ErrorResponse());
            }

            var totalSalary     = _employeeService.GetTotalSalary();
            var bonusAllocation = _bonusPoolService.Calculate(request.TotalBonusPoolAmount, totalSalary, employee.Salary);

            var result = new BonusPoolCalculatorResultDto
            {
                Employee = new EmployeeDto(employee),
                Amount   = bonusAllocation
            };

            return(Ok(result));
        }
예제 #2
0
        public ActionResult Calculate(BonusPoolCalculatorViewModel viewModel)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException("BonusPoolCalculatorViewModel shouldn't be null");
            }

            BonusPoolCalculatorResultViewModel result;

            try
            {
                var domainModel  = _mappable.Map <BonusPoolCalculatorDomainModel>(viewModel);
                var domainResult = _service.Calculate(domainModel);
                result = _mappable.Map <BonusPoolCalculatorResultViewModel>(domainResult);
            }
            catch (EmployeeNotFoundException)
            {
                return(new HttpNotFoundResult($"Employee was not found."));
            }

            return(View(result));
        }