public void MonthlyEmployeeTest() { Employee employee = employeeFactory.CreateContract("MonthlySalaryEmployee"); employee.ContractTypeName = "MonthlySalaryEmployee"; employee.HourlySalary = 100; employee.Id = 1; employee.MonthlySalary = 2000; employee.Role = new Role() { RoleId = 1, RoleName = "Administrator" }; employee.CalculateSalary(); Assert.AreEqual(employee.AnnualSalary, 24000); }
public List <Employee> GetAllEmployees() { EmployeeBusiness employeeRepository = new EmployeeBusiness(new ApiEmployeeRepository()); List <EmployeeDTO> employeesDto = employeeRepository.GetEmployees(); List <Employee> employees = new List <Employee>(); EmployeeFactory contractFactory = new EmployeeFactory(); var config = new MapperConfiguration(cfg => { cfg.CreateMap <EmployeeDTO, Employee>(); }); IMapper iMapper = config.CreateMapper(); if (employeesDto != null) { foreach (var employeeDto in employeesDto) { Employee employee = contractFactory.CreateContract(employeeDto.ContractTypeName); iMapper.Map <EmployeeDTO, Employee>(employeeDto, employee); employee.CalculateSalary(); employees.Add(employee); } } return(employees); }
private static Employee GetEmployeesById(int id) { var employeeDto = GetEmployeesDto().FirstOrDefault(i => i.Id == id); var employeeFactory = new EmployeeFactory(); var config = new MapperConfiguration(cfg => { cfg.CreateMap <EmployeeDto, Employee>(); }); IMapper iMapper = config.CreateMapper(); Employee employee = employeeFactory.CreateContract(employeeDto.ContractTypeName); iMapper.Map(employeeDto, employee); employee.Role = new Role(employeeDto); employee.CalculateSalary(); return(employee); }
private static List <Employee> GetEmployees() { var employeesDto = GetEmployeesDto(); var employees = new List <Employee>(); var employeeFactory = new EmployeeFactory(); var config = new MapperConfiguration(cfg => { cfg.CreateMap <EmployeeDto, Employee>(); }); IMapper iMapper = config.CreateMapper(); if (employeesDto != null) { foreach (var employeeDto in employeesDto) { Employee employee = employeeFactory.CreateContract(employeeDto.ContractTypeName); iMapper.Map(employeeDto, employee); employee.Role = new Role(employeeDto); employee.CalculateSalary(); employees.Add(employee); } } return(employees); }
public Employee GetEmployee(int id) { EmployeeBusiness employeeRepository = new EmployeeBusiness(new ApiEmployeeRepository()); EmployeeDTO employeeDto = employeeRepository.GetEmployee(id); if (employeeDto == null) { throw new ApiException("Employee not found."); } EmployeeFactory contractFactory = new EmployeeFactory(); Employee employee = contractFactory.CreateContract(employeeDto.ContractTypeName); var config = new MapperConfiguration(cfg => { cfg.CreateMap <EmployeeDTO, Employee>(); }); IMapper iMapper = config.CreateMapper(); iMapper.Map <EmployeeDTO, Employee>(employeeDto, employee); employee.CalculateSalary(); return(employee); }