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; }
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; }