public EmployeeVO2 CreateEmployee(EmployeeVO2 vo) { try { using (var db = new EmployeeTrainingModelContainer()) { var employee = new Employee { EmployeeNumber = vo.EmployeeNumber, FirstName = vo.FirstName, MiddleName = vo.MiddleName, LastName = vo.LastName, DateOfBirth = vo.DateOfBirth, HireDate = vo.HireDate }; db.Employees.Add(employee); db.SaveChanges(); var query = from b in db.Employees where b.EmployeeNumber == vo.EmployeeNumber select b; vo.ID = query.First().Id; } } catch (Exception ex) { LogError(ex); } return(vo); }
public void DeleteEmployee(int id) { try { using (var db = new EmployeeTrainingModelContainer()) { Employee employee = (Employee)db.Employees.Where(b => b.Id == id).First(); db.Employees.Remove(employee); db.SaveChanges(); } } catch (Exception ex) { LogError(ex); } }