public async Task Calculate() { var employee = _fixture.Create <HrEmployee>(); _mockedEmployeeService.Setup(svc => svc.GetEmployeeByIdAsync(It.IsAny <int>())) .ReturnsAsync(employee); var totalSalary = 100000; _mockedEmployeeService.Setup(svc => svc.GetTotalSalaryOfAllEmployees()) .ReturnsAsync(totalSalary); var bonusShare = 30; _mockedBonusCalculator.Setup(svc => svc.GetBonusForEmployee(It.IsAny <decimal>(), It.IsAny <decimal>(), It.IsAny <decimal>())) .Returns(bonusShare); var request = new BonusPoolCalculatorModel { SelectedEmployeeId = 2, BonusPoolAmount = 10000 }; var result = await SUT.Calculate(request); _mockedEmployeeService.Verify(svc => svc.GetEmployeeByIdAsync(request.SelectedEmployeeId), Times.Once); _mockedEmployeeService.Verify(svc => svc.GetTotalSalaryOfAllEmployees(), Times.Once); _mockedBonusCalculator.Verify(svc => svc.GetBonusForEmployee(employee.Salary, totalSalary, request.BonusPoolAmount)); var viewResult = result.ShouldBeAssignableTo <ViewResult>(); var resultModel = viewResult.Model.ShouldBeAssignableTo <BonusPoolCalculatorResultModel>(); resultModel.HrEmployee.ShouldBe(employee); resultModel.BonusPoolAllocation.ShouldBe(bonusShare); }
// GET: BonusPool public ActionResult Index() { BonusPoolCalculatorModel model = new BonusPoolCalculatorModel(); model.AllEmployees = employeeRepository.GetAll(); return(View(model)); }
public ActionResult Index() { BonusPoolCalculatorModel model = new BonusPoolCalculatorModel(); model.AllEmployees = getEmployees(); return(View(model)); }
public ActionResult Calculate(BonusPoolCalculatorModel model) { int selectedEmployeeId = model.SelectedEmployeeId; int totalBonusPool = model.BonusPoolAmount; var employees = employeeRepository.GetEmployees(); var employee = employeeRepository.GetEmployee(employees, selectedEmployeeId); if (!ModelState.IsValid) { ViewBag.ErrorMessage = "Please check BonusPoolAmount !!"; bonusPoolCalculatorResultModel.Employee = employee; bonusPoolCalculatorResultModel.BonusPoolAllocation = 0; return(View(bonusPoolCalculatorResultModel)); } //load the details of the selected employee using the ID //get the total salary budget for the company int bonusAllocation = bonusPoolCalculatorService.CalculateBonusPool(employees, selectedEmployeeId, totalBonusPool); bonusPoolCalculatorResultModel.Employee = employee; bonusPoolCalculatorResultModel.BonusPoolAllocation = bonusAllocation; return(View(bonusPoolCalculatorResultModel)); }
public BonusPoolCalculatorResultModel CalculateEmployeeBonus(BonusPoolCalculatorModel bonusPoolCalculatorModel) { var hrDepartments = _hrDepartmentRepository.GetHrDepartments(); var hrEmployees = _hrEmployeeRepository.GetHrEmployees().ToList(); var hrEmployeeSelected = hrEmployees.FirstOrDefault(x => x.ID == bonusPoolCalculatorModel.SelectedEmployeeId); var bonusesByDepartment = ProcessGlobalHrDepartmentBonusDistribution(bonusPoolCalculatorModel, hrDepartments); var employeesOfHrDepartment = hrEmployees.Where(x => x.HrDepartmentId == hrEmployeeSelected?.HrDepartmentId).ToList(); var bonusPercentageBasedOnSalary = ProcessGlobalHrDepartmentEmployeePercentage(employeesOfHrDepartment); var bonusOfDepartment = (decimal)bonusesByDepartment.FirstOrDefault(x => x.Key == hrEmployeeSelected?.HrDepartmentId).Value; var actualBonusesForEmployeesInHrDepartment = GetActualBonusForHrDepartmentEmployees( employeesOfHrDepartment, bonusPercentageBasedOnSalary, bonusOfDepartment); var actualBonus = actualBonusesForEmployeesInHrDepartment[hrEmployeeSelected.ID]; return(new BonusPoolCalculatorResultModel() { BonusPoolAllocation = Convert.ToInt32(actualBonus), HrEmployee = hrEmployeeSelected }); }
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 BonusPoolCalculatorModel PrepareBonusPoolCalculatorModel() { var model = new BonusPoolCalculatorModel(); model.AllEmployees = hrEmployeesService.GetAll(); return(model); }
public IActionResult Index() { BonusPoolCalculatorModel model = new BonusPoolCalculatorModel(); model.AllEmployees = _hrEmployeeService.GetHrEmployees(); return(View(model)); }
public BonusPoolCalculatorResultModel CalculateBonusForEmployee(BonusPoolCalculatorModel model) { var employee = SelectEmployeeById(model); var bonus = CalculateBonus(employee.Salary, model.BonusPoolAmount); return(CreateResultModel(employee, (int)bonus)); }
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)); }
// GET: BonusPool public ActionResult Index() { BonusPoolCalculatorModel model = new BonusPoolCalculatorModel(); model.AllEmployees = db.HrEmployees.ToList <HrEmployee>(); return(View(model)); }
public void Should_pass_down_model_to_CalculateBonusForEmployee_when_Calculate_called() { var fakeModel = new BonusPoolCalculatorModel(); _controller.Calculate(fakeModel); _mockCalculatorService.Received(1).CalculateBonusForEmployee(fakeModel); }
public BonusPoolCalculatorModel AddEmployeesToResultModel() { var bonusResult = new BonusPoolCalculatorModel(); bonusResult.AllEmployees = _employeeRepository.Read().ToList(); return(bonusResult); }
// GET: BonusPool public ActionResult Index() { BonusPoolCalculatorModel model = new BonusPoolCalculatorModel(); model.AllEmployees = _hrRepository.GetHrEmployees().ToList(); return(View(model)); }
// GET: BonusPool public ActionResult Index() { var result = new BonusPoolCalculatorModel { AllEmployees = ServiceFactory.GetEmployeesService().GetAll() }; return(View(result)); }
// GET: BonusPool public async Task <ActionResult> Index() { var allEmployees = await _employeeService.GetAllEmployeesAsync(); var model = new BonusPoolCalculatorModel { AllEmployees = allEmployees }; return(View(model)); }
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)); }
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)); }
public Dictionary <int, decimal?> ProcessGlobalHrDepartmentBonusDistribution( BonusPoolCalculatorModel bonusPoolCalculatorModel, IEnumerable <HrDepartment> hrDepartments) { var hrDepartmentsGlobalBonuses = new Dictionary <int, decimal?>(); foreach (var hrDepartment in hrDepartments) { hrDepartmentsGlobalBonuses.Add(hrDepartment.ID, CalculateBonusForHrDepartment(hrDepartment.BonusPoolAllocationPerc, bonusPoolCalculatorModel.BonusPoolAmount)); } return(hrDepartmentsGlobalBonuses); }
public ActionResult Calculate(BonusPoolCalculatorModel model) { try { var resultToDisplay = _bonusService.SetBonusPoolToEmployee(model.SelectedEmployeeId, model.BonusPoolAmount); return(View(resultToDisplay)); } catch (KeyNotFoundException e) { return(View(Index())); } }
// GET: BonusPool public ActionResult Index() { //I don't think there is a need for the VMB //var model = _bonusPoolModelBuilder.Build(); //Call off to the service //var model = _employeeService.GetAllEmployees(); BonusPoolCalculatorModel model = new BonusPoolCalculatorModel(); model.AllEmployees = db.HrEmployees.ToList(); return(View(model)); }
public ActionResult Index() { BonusPoolCalculatorModel model = new BonusPoolCalculatorModel { AllEmployees = _employeeService.GetHrEmployees().Select(x => new HrEmployeeViewModel() { ID_Enc = x.HrDepartmentId.ToString() , Full_Name = x.Full_Name }).ToList <HrEmployeeViewModel>() }; return(View(model)); }
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 GetBonus(BonusPoolCalculatorModel model) { var selectedEmployeeId = model.SelectedEmployeeId; var totalBonusPool = model.BonusPoolAmount; var selectedEmployee = _repository.GetSelectedEmployeeById(selectedEmployeeId); var employeeSalary = selectedEmployee.Salary; var totalSalary = _repository.GetTotalSalaryBudgetForCompany(); var bonusPercentage = (decimal)employeeSalary / (decimal)totalSalary; var bonusAllocation = (int)(bonusPercentage * totalBonusPool); return(new BonusPoolCalculatorResultModel { HrEmployee = selectedEmployee, BonusPoolAllocation = bonusAllocation }); }
public void Before_each() { //NOTE: yes, I did not use an interface here - please see the readme var calculatorModel = new BonusPoolCalculatorModel { AllEmployees = new List <Employee> { new Employee { Id = 0, FullName = "Alf Stokes", Salary = 10000 }, new Employee { Id = 1, FullName = "Bender Rodriguez", Salary = 1000 } } }; _mockIndexService = Substitute.For <IBonusPoolIndexService>(); _mockIndexService.GenerateIndexModel().Returns(calculatorModel); _mockCalculatorService = Substitute.For <IBonusPoolCalculatorService>(); _controller = new BonusPoolController(_mockIndexService, _mockCalculatorService); }
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 = _hrRepository.GetHrEmployee(selectedEmployeeId); int employeeSalary = _bonusCalculator.GetSalary(hrEmployee); IEnumerable <HrEmployee> allEmployees = _hrRepository.GetHrEmployees(); //get the total salary budget for the company int totalSalary = _bonusCalculator.GetTotalSalary(allEmployees); int bonusAllocation = _bonusCalculator.Calculate(employeeSalary, totalSalary, totalBonusPool); var result = ToBonusPoolCalculatorResultModel(hrEmployee, bonusAllocation); return(View(result)); }
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)); }