Exemple #1
0
        //UC3
        public EmployeeContract AddEmployee(EmployeeContract employeeContract)
        {
            Emp_Payroll employee = new Emp_Payroll()
            {
                name   = employeeContract.Name,
                email  = employeeContract.Email,
                salary = employeeContract.Salary
            };

            employeeManagementEntitiesObj.Emp_Payroll.Add(employee);
            employeeManagementEntitiesObj.SaveChanges();
            employeeContract.Id = employee.id;
            return(employeeContract);
        }
Exemple #2
0
        //UC5
        public int UpdateEmployee(EmployeeContract employeeContract, int EmpId)
        {
            Emp_Payroll employee = employeeManagementEntitiesObj
                                   .Emp_Payroll.Find(EmpId);

            if (employee != null)
            {
                employee.email  = employeeContract.Email;
                employee.name   = employeeContract.Name;
                employee.salary = employeeContract.Salary;
                return(employeeManagementEntitiesObj.SaveChanges());
            }
            else
            {
                throw new Exception("Employee do not exists");
            }
        }
Exemple #3
0
        //UC4
        public List <EmployeeContract> AddMultipleEmployees(List <EmployeeContract> employeeContract)
        {
            foreach (EmployeeContract emp in employeeContract)
            {
                Emp_Payroll employee = new Emp_Payroll()
                {
                    name   = emp.Name,
                    email  = emp.Email,
                    salary = emp.Salary
                };
                employeeManagementEntitiesObj.Emp_Payroll.Add(employee);
                employeeManagementEntitiesObj.SaveChanges();
                emp.Id = employee.id;
            }

            return(employeeContract);
        }
        /// UC2
        /// Retrieving an employee with the help of the id and
        /// filling up the EmployeeContract object with the obtained data
        public EmployeeContract GetById(int empId)
        {
            EmployeeContract employeeContract = null;
            Emp_Payroll      Employee         = employeeRepository.GetById(empId);

            if (Employee != null)
            {
                employeeContract = new EmployeeContract()
                {
                    Name   = Employee.name,
                    Email  = Employee.email,
                    Salary = (int)Employee.salary,
                    Id     = Employee.id
                };
                return(employeeContract);
            }
            else
            {
                return(employeeContract);
            }
        }