コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }