Пример #1
0
 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
 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;
 }