Exemple #1
0
        public void ModifyEmployee(int id, int selectedPositionId, int selectedDepartmentId, int?selectedHeadId, Employee employee)
        {
            using (var context = new PowerCoEntity())
            {
                Employee emp = context.Employees.FirstOrDefault(e => e.EmployeeId == id);
                emp.Salary     = employee.Salary;
                emp.FullName   = employee.FullName;
                emp.Department = employee.Department;
                emp.Position   = context.EmployeePositions.FirstOrDefault(d => d.Id == selectedPositionId);
                emp.Department = context.Deprtments.FirstOrDefault(d => d.DepartmentId == selectedDepartmentId);
                if (selectedHeadId != null)
                {
                    emp.Head = GetHeadName(selectedHeadId.Value);
                }
                else
                {
                    emp.Head = "";
                }

                emp.Salary               = employee.Salary;
                emp.FullName             = employee.FullName;
                context.Entry(emp).State = EntityState.Modified;
                context.SaveChanges();
            }
        }
Exemple #2
0
 public void AddUser(User user)
 {
     using (var context = new PowerCoEntity())
     {
         context.Users.Add(user);
         context.SaveChanges();
     }
 }
Exemple #3
0
 public void RemoveEmployee(int id)
 {
     using (var context = new PowerCoEntity())
     {
         var employee = context.Employees.FirstOrDefault(e => id == e.EmployeeId);
         context.Employees.Remove(employee);
         context.SaveChanges();
     }
 }
Exemple #4
0
 public void AddEmployee(Employee employee)
 {
     using (var context = new PowerCoEntity())
     {
         context.EmployeePositions.Attach(employee.Position);
         context.Deprtments.Attach(employee.Department);
         context.Employees.Add(employee);
         context.SaveChanges();
     }
 }