コード例 #1
0
 public static tblEmployee GetEmployeeById(int id)
 {
     try
     {
         using (dbFirmEntities context = new dbFirmEntities())
         {
             tblEmployee result = (from x in context.tblEmployees where x.employeeId == id select x).FirstOrDefault();
             return(result);
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception " + ex.Message.ToString());
         return(null);
     }
 }
コード例 #2
0
 public static tblEmployee AddEmployee(tblEmployee employee)
 {
     try
     {
         using (dbFirmEntities context = new dbFirmEntities())
         {
             if (employee.employeeId == 0)
             {
                 //add
                 tblEmployee newEmployee = new tblEmployee();
                 newEmployee.qualificationsId = employee.qualificationsId;
                 newEmployee.sectorId         = employee.sectorId;
                 if (employee.positionID != 0)
                 {
                     newEmployee.positionID = employee.positionID;
                 }
                 newEmployee.yearsOfService = employee.yearsOfService;
                 newEmployee.managerId      = employee.managerId;
                 newEmployee.userID         = employee.userID;
                 context.tblEmployees.Add(newEmployee);
                 context.SaveChanges();
                 employee.employeeId = newEmployee.employeeId;
                 return(employee);
             }
             else
             {
                 tblEmployee employeeToEdit = (from x in context.tblEmployees where x.employeeId == employee.employeeId select x).FirstOrDefault();
                 employeeToEdit.Salary           = employee.Salary;
                 employeeToEdit.positionID       = employee.positionID;
                 employeeToEdit.sectorId         = employee.sectorId;
                 employeeToEdit.managerId        = employee.managerId;
                 employeeToEdit.yearsOfService   = employee.yearsOfService;
                 employeeToEdit.qualificationsId = employee.qualificationsId;
                 employeeToEdit.userID           = employee.userID;
                 context.SaveChanges();
                 return(employee);
             }
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message.ToString());
         return(null);
     }
 }