コード例 #1
0
        public Employee UpdateEmployee(EmployeeDepartmentModel employee)
        {
            Employee modifyEmployee = db.Employees.FirstOrDefault(emp => emp.EmployeeId == employee.EmployeeId);

            modifyEmployee.FirstName    = employee.FirstName;
            modifyEmployee.LastName     = employee.LastName;
            modifyEmployee.EmailId      = employee.Email;
            modifyEmployee.DepartmentId = db.Departments.FirstOrDefault(d => d.DepartmentName == employee.Department).DepartmentId;
            modifyEmployee.ManagerId    = db.Employees.FirstOrDefault(e => e.FirstName == employee.Manager).EmployeeId;

            db.Entry(modifyEmployee).State = EntityState.Modified;
            db.SaveChanges();
            return(modifyEmployee);
        }
コード例 #2
0
 public Employee AddEmployee(EmployeeDepartmentModel employee)
 {
     if (employee != null)
     {
         Employee newEmployee = new Employee
         {
             FirstName    = employee.FirstName,
             LastName     = employee.LastName,
             EmailId      = employee.Email,
             DepartmentId = db.Departments.FirstOrDefault(d => d.DepartmentName == employee.Department).DepartmentId,
             ManagerId    = db.Employees.FirstOrDefault(e => e.FirstName == employee.Manager).EmployeeId
         };
         db.Employees.Add(newEmployee);
         db.SaveChanges();
         //SendEmail(newEmployee.EmailId);
         return(newEmployee);
     }
     return(null);
 }