示例#1
0
文件: EmployeeData.cs 项目: pebezo/HR
 public int CreateNewEmployee(Employee employee)
 {
     int result;
     try
     {
         var newEmployee = DbContext.Employees.Create();
         newEmployee.Name = employee.Name;
         newEmployee.Telephone = employee.Telephone;
         newEmployee.EmploymentDate = employee.EmploymentDate;
         newEmployee.Address = employee.Address;
         newEmployee.EmployeeTypeId = employee.EmployeeTypeId;
         DbContext.Employees.Add(newEmployee);
         DbContext.SaveChanges();
         result = newEmployee.Id;
     }
     catch (Exception e)
     {
         result = 0;
     }
     return result;
 }
示例#2
0
文件: EmployeeData.cs 项目: pebezo/HR
 public int UpdateEmployee(Employee employee)
 {
     int result;
     try
     {
         var modifiedEmployee = DbContext.Employees.Find(employee.Id);
         modifiedEmployee.Name = employee.Name;
         modifiedEmployee.Telephone = employee.Telephone;
         modifiedEmployee.EmploymentDate = employee.EmploymentDate;
         modifiedEmployee.Address = employee.Address;
         modifiedEmployee.EmployeeTypeId = employee.EmployeeTypeId;
         DbContext.SaveChanges();
         result = modifiedEmployee.Id;
     }
     catch (Exception e)
     {
         result = 0;
     }
     return result;
 }