Пример #1
0
        public async Task <IEnumerable <EmployeeDto> > GetInfoEmployees(int id)
        {
            var employees = await _employeeRepo.GetAllAsync();

            var result = new List <EmployeeDto>();

            EmployeeFactory factory = null;

            foreach (var employee in employees)
            {
                switch (employee.ContractTypeName.ToLower())
                {
                case "hourlysalaryemployee":
                    factory = new HourlyFactory(employee.Id, employee.Name, employee.RoleName, employee.HourlySalary);
                    break;

                case "monthlysalaryemployee":
                    factory = new MonthlyFactory(employee.Id, employee.Name, employee.RoleName, employee.MonthlySalary);
                    break;

                default:
                    break;
                }

                result.Add(factory.GetEmployee());
            }

            if (id != 0)
            {
                result = result.FindAll(x => x.Id == id);
            }

            return(result);
        }
Пример #2
0
        public async Task <ActionResult> getEmployees(int id)
        {
            EmployeesController a = new EmployeesController();
            List <Contract>     listEmployeesContract = new List <Contract>();

            if (id == 0)
            {
                var ListEmployees = await a.Get();

                ContractFactory factory = null;

                foreach (var i in ListEmployees.Value.ToList())
                {
                    if (i.contractTypeName == "HourlySalaryEmployee")
                    {
                        factory = new HourlyFactory(i.name, i.roleName, i.roleDescription, i.hourlySalary);
                    }
                    if (i.contractTypeName == "MonthlySalaryEmployee")
                    {
                        factory = new MonthlyFactory(i.name, i.roleName, i.roleDescription, i.monthlySalary);
                    }

                    listEmployeesContract.Add(factory.GetContract());
                }
            }
            else
            {
                var ListEmployees = await a.Get(id);

                ContractFactory factory = null;

                if (ListEmployees.Value.contractTypeName == "HourlySalaryEmployee")
                {
                    factory = new HourlyFactory(ListEmployees.Value.name, ListEmployees.Value.roleName, ListEmployees.Value.roleDescription, ListEmployees.Value.hourlySalary);
                }
                if (ListEmployees.Value.contractTypeName == "MonthlySalaryEmployee")
                {
                    factory = new MonthlyFactory(ListEmployees.Value.name, ListEmployees.Value.roleName, ListEmployees.Value.roleDescription, ListEmployees.Value.monthlySalary);
                }

                listEmployeesContract.Add(factory.GetContract());
            }

            var model = new ResultModel
            {
                ListEmployeesContract = listEmployeesContract,
            };

            return(View("~/Views/Home/Result.cshtml", model));
        }