public decimal AddEmployee(Empoyee employee) { using (var context = new DBEntities()) { context.Empoyees.Add(employee); context.SaveChanges(); } UpdateEmployee(employee); return(employee.ID); }
public decimal UpdateEmployee(Empoyee employee) { using (var context = new DBEntities()) { var editEmployee = context.Empoyees.FirstOrDefault(x => x.ID == employee.ID); if (editEmployee == null) { editEmployee = new Empoyee(); context.Empoyees.Add(editEmployee); } editEmployee.FirstName = employee.FirstName; editEmployee.SurName = employee.SurName; editEmployee.Patronymic = employee.Patronymic; editEmployee.DepartmentID = employee.DepartmentID; editEmployee.Department = context.Departments.FirstOrDefault(x => x.ID == employee.DepartmentID); editEmployee.DateOfBirth = employee.DateOfBirth; editEmployee.Position = employee.Position; context.SaveChanges(); return(editEmployee.ID); } }