Exemple #1
0
        public ActionResult Calculate(BonusPoolCalculatorModel model)
        {
            /*I don't think there is a need for the VMB, this will need to change as we won't be
             * showing the same VMB as the Index page if we decided to take the VMB route.*/
            //var viewModel = _bonusPoolModelBuilder.Build();
            //Call off to the service, which calls off the DAL
            //var result = _employeeService.GetBonus(model);

            var selectedEmployeeId = model.SelectedEmployeeId;
            var totalBonusPool     = model.BonusPoolAmount;

            //load the details of the selected employee using the ID
            var hrEmployee = db.HrEmployees.FirstOrDefault(item => item.ID == selectedEmployeeId);

            var employeeSalary = hrEmployee.Salary;

            //get the total salary budget for the company
            var totalSalary = (int)db.HrEmployees.Sum(item => item.Salary);

            //calculate the bonus allocation for the employee
            var bonusPercentage = (decimal)employeeSalary / (decimal)totalSalary;
            var bonusAllocation = (int)(bonusPercentage * totalBonusPool);

            var result = new BonusPoolCalculatorResultModel
            {
                HrEmployee          = hrEmployee,
                BonusPoolAllocation = bonusAllocation
            };

            return(View(result));
        }
        public ActionResult Calculate(BonusPoolCalculatorRequest model)
        {
            BonusPoolCalculatorResultModel calcModel = new BonusPoolCalculatorResultModel();

            if (model.BonusPoolAmount < 0)
            {
                calcModel.ErrorMessage = "Bonus must be greater than 0";
                calcModel.Success      = false;
            }
            else
            {
                var employee = employeeRepository.Get(model.SelectedEmployeeId);
                if (employee != null)
                {
                    decimal bonusAllocation = bonusCalculatorService.CalculateBonus(model.BonusPoolAmount, model.SelectedEmployeeId);
                    calcModel.Result.hrEmployee          = employee;
                    calcModel.Result.bonusPoolAllocation = (int)bonusAllocation;
                    calcModel.Success = true;
                }
                else
                {
                    calcModel.ErrorMessage = "Employee was not found!";
                    calcModel.Success      = false;
                }
            }
            return(View(calcModel));
        }
        public ActionResult Calculate(BonusPoolCalculatorModel model)
        {
            int selectedEmployeeId = model.SelectedEmployeeId;
            int totalBonusPool     = model.BonusPoolAmount;

            //load the details of the selected employee using the ID
            HrEmployee hrEmployee = getEmployeeProfile(selectedEmployeeId);


            int employeeSalary = hrEmployee.Salary;


            //get the total salary budget for the company
            int totalSalary = getEmployeeTotalSalary();

            //calculate the bonus allocation for the employee
            int bonusAllocation = getBonusAllocation(employeeSalary, totalSalary, totalBonusPool);

            BonusPoolCalculatorResultModel result = new BonusPoolCalculatorResultModel();

            result.hrEmployee          = hrEmployee;
            result.bonusPoolAllocation = bonusAllocation;

            return(View(result));
        }
Exemple #4
0
        public BonusPoolCalculatorResultModel SetBonusPoolToEmployee(int selectedEmployeeId, int bonusAllocation)
        {
            var bonusResult = new BonusPoolCalculatorResultModel();

            bonusResult.hrEmployee          = _employeeRepository.GetById(selectedEmployeeId);
            bonusResult.bonusPoolAllocation = CalculateBonusPoolForEmployee(selectedEmployeeId, bonusAllocation);

            return(bonusResult);
        }
        public ActionResult Calculate(BonusPoolCalculatorModel model)
        {
            BonusPool newBonusPool = new BonusPool(new MvcInterviewV3Entities1());

            BonusPoolCalculatorResultModel result = new BonusPoolCalculatorResultModel();

            result.bonusPoolAllocation = newBonusPool.CalculateByEmployeeId(model.SelectedEmployeeId, model.BonusPoolAmount);

            return(View(result));
        }
Exemple #6
0
        public ActionResult Calculate(BonusPoolCalculatorModel model)
        {
            BonusPoolCalculatorResultModel result = new BonusPoolCalculatorResultModel
            {
                hrEmployee          = ServiceFactory.GetEmployeesService().Get(model.SelectedEmployeeId),
                bonusPoolAllocation = ServiceFactory.GetCalculateBonusService().CalculateEmployeeBonusPoolAllocation(model.SelectedEmployeeId, model.BonusPoolAmount)
            };

            return(View(result));
        }
Exemple #7
0
        public void Setup()
        {
            MockEmployeeRepository   = new Mock <IEmployeeRepository>();
            MockDepartmentRepository = new Mock <IDepartmentRepository>();


            EmployeeRepository             = new EmployeeRepository();
            DepartmentRepository           = new DepartmentRepository();
            BonusPoolCalculatorService     = new BonusPoolCalculatorService();
            BonusPoolCalculatorModel       = new BonusPoolCalculatorModel();
            BonusPoolCalculatorResultModel = new BonusPoolCalculatorResultModel();

            Target = new BonusPoolController(EmployeeRepository, DepartmentRepository, BonusPoolCalculatorService, BonusPoolCalculatorModel, BonusPoolCalculatorResultModel);
        }
        public async Task <ActionResult> Calculate(BonusPoolCalculatorModel model)
        {
            var selectedEmployeeId = model.SelectedEmployeeId;
            var totalBonusPool     = model.BonusPoolAmount;

            var hrEmployee = await _employeeService.GetEmployeeByIdAsync(selectedEmployeeId);

            var result = new BonusPoolCalculatorResultModel
            {
                HrEmployee          = hrEmployee,
                BonusPoolAllocation = await CalculateBonusForEmployee(hrEmployee.Salary, totalBonusPool)
            };

            return(View(result));
        }
        public ActionResult Calculate(BonusPoolCalculatorModel model)
        {
            //load the details of the selected employee using the ID
            var hrEmployee = GetEmployee(model.SelectedEmployeeId);

            // Get the bonus allocation from BonusCalculatorService
            var bonusAllocation = _bonusCalculatorService.Calculate(
                model.BonusPoolAmount,
                hrEmployee.Salary,
                totalSalary: _hrEmployeeRepository.GetTotalSalaries());

            BonusPoolCalculatorResultModel result = new BonusPoolCalculatorResultModel();

            result.hrEmployee          = hrEmployee;
            result.bonusPoolAllocation = bonusAllocation;

            return(View(result));
        }
        public ActionResult Calculate(BonusPoolCalculatorModel model)
        {
            int.TryParse(model.SelectedEmployeeId_Enc.Decrypt(), out int selectedEmployeeId);
            int                 totalBonusPool      = model.BonusPoolAmount;
            IHrEmployee         hrEmployee          = _employeeService.GetHrEmployee(selectedEmployeeId);
            decimal             bonusAllocation     = _employeeService.CalculateEmployeeBonus(totalBonusPool, hrEmployee, _employeeService.GetHrEmployees());
            HrEmployeeViewModel hrEmployeeViewModel = new HrEmployeeViewModel()
            {
                ID_Enc      = hrEmployee.HrDepartmentId.ToString()
                , Full_Name = hrEmployee.Full_Name
            };
            BonusPoolCalculatorResultModel result = new BonusPoolCalculatorResultModel
            {
                hrEmployee          = hrEmployee,
                bonusPoolAllocation = bonusAllocation
            };

            return(View(result));
        }
        public BonusPoolCalculatorResultModel PrepareBonusPoolCalculatorResultModel(int selectedEmployeeId, decimal bonusPoolAmount)
        {
            var model = new BonusPoolCalculatorResultModel();

            var hrEmployee = hrEmployeesService.FindById(selectedEmployeeId);

            if (hrEmployee == null)
            {
                return(model);
            }

            var hrDepartment = hrEmployee.HrDepartment; //hrDepartmentService.FindById(hrEmployee.HrDepartmentId);

            if (hrDepartment == null)
            {
                return(model);
            }

            //get all employees
            var hrEmployees = hrEmployeesService.GetAll();
            //employees filtered by selected employee's hr department
            var hrFilteredEmployees = hrEmployeesService.FilterByDepartment(hrEmployees, hrEmployee.HrDepartmentId);

            //get company salary budget
            int totalSalary = bonusPoolService.CalculateSalaryBudget(hrEmployees);
            //get department salary budget
            int totalSalaryByHrDepartment = bonusPoolService.CalculateSalaryBudget(hrFilteredEmployees);

            var hrEmployeeSalary = hrEmployee.Salary;

            //calculate bonus allocation without HrDepartment allocation
            decimal bonusAllocation = bonusPoolService.CalculateBonusAllocation(hrEmployeeSalary, totalSalary, bonusPoolAmount);
            //calculate bonus allocation considering HrDepartment allocation
            decimal?bonusAllocationByHrDepartment = bonusPoolService.CalculateBonusAllocationByHrDepartment(hrEmployeeSalary, totalSalaryByHrDepartment, bonusPoolAmount, hrDepartment.BonusPoolAllocationPerc);

            model.HrEmployee                       = hrEmployee;
            model.BonusPoolAllocation              = bonusAllocation;
            model.BonusPoolAllocationHrDepartment  = bonusAllocationByHrDepartment;
            model.HrDepartmentAllocationPercentage = hrDepartment.BonusPoolAllocationPerc;
            model.EmployeeHrDepartmentName         = hrDepartment.Title;

            return(model);
        }
        public ActionResult Calculate(BonusPoolCalculatorModel model)
        {
            int        selectedEmployeeId = model.SelectedEmployeeId;
            int        totalBonusPool     = model.BonusPoolAmount;
            HrEmployee hrEmployee         = (HrEmployee)db.HrEmployees.FirstOrDefault(item => item.ID == selectedEmployeeId);

            Payroll payroll = new Payroll();

            payroll.AllEmployees       = getEmployees();
            payroll.TotalCostToCompany = payroll.PayrollCostTocompany(payroll.AllEmployees);

            BonusPool bonusPool = new BonusPool();

            bonusPool.BonusPoolAmount = totalBonusPool;

            BonusPoolCalculatorResultModel result = new BonusPoolCalculatorResultModel();
            Allocation allocation = new Allocation();

            result.hrEmployee          = hrEmployee;
            result.bonusPoolAllocation = allocation.BonusAllocationCalculation(hrEmployee, payroll, bonusPool);
            return(View(result));
        }
Exemple #13
0
        public ActionResult Calculate(BonusPoolCalculatorModel model)
        {
            int selectedEmployeeId = model.SelectedEmployeeId;
            int totalBonusPool     = model.BonusPoolAmount;

            //load the details of the selected employee using the ID
            HrEmployee hrEmployee = (HrEmployee)db.HrEmployees.FirstOrDefault(item => item.ID == selectedEmployeeId);

            int employeeSalary = hrEmployee.Salary;

            //get the total salary budget for the company
            int totalSalary = (int)db.HrEmployees.Sum(item => item.Salary);

            //calculate the bonus allocation for the employee
            decimal bonusPercentage = (decimal)employeeSalary / (decimal)totalSalary;
            int     bonusAllocation = (int)(bonusPercentage * totalBonusPool);

            BonusPoolCalculatorResultModel result = new BonusPoolCalculatorResultModel();

            result.hrEmployee          = hrEmployee;
            result.bonusPoolAllocation = bonusAllocation;

            return(View(result));
        }
Exemple #14
0
        public ActionResult Calculate(BonusPoolCalculatorModel model)
        {
            int selectedEmployeeId = model.SelectedEmployeeId;
            int totalBonusPool     = model.BonusPoolAmount;

            //load the details of the selected employee using the ID
            HrEmployee hrEmployee = _hrEmployeeRepository.Get(selectedEmployeeId);

            int employeeSalary = hrEmployee.Salary;

            //get the total salary budget for the company
            int totalSalary = _hrEmployeeRepository.GetSumOfSalaries();

            //calculate the bonus allocation for the employee
            BonusPoolCalculator calculator      = new BonusPoolCalculator(totalSalary, totalBonusPool);
            decimal             bonusAllocation = calculator.CalculateBonusAllocation(employeeSalary);

            BonusPoolCalculatorResultModel result = new BonusPoolCalculatorResultModel();

            result.hrEmployee          = hrEmployee;
            result.bonusPoolAllocation = bonusAllocation;

            return(View(result));
        }