public IList <Employee> GetAll() { using (var context = new CodeFirstModels()) { return(context.Employees.ToList()); } }
public IList <Employee> GetByManager(int managerKey) { using (var context = new CodeFirstModels()) { return(context.Employees.Where(e => e.ManagerKey == managerKey).ToList()); } }
public Employee Get(int employeeKey) { using (var context = new CodeFirstModels()) { return(context.Employees.Where(e => e.EmployeeKey == employeeKey).First()); } }
public void Delete(int employeeKey) { using (var context = new CodeFirstModels()) { context.Database.ExecuteSqlCommand("DELETE FROM HR.Employee WHERE EmployeeKey = @p0", employeeKey); } }
public void Update(Employee employee) { using (var context = new CodeFirstModels()) { context.Entry(employee).State = EntityState.Modified; context.SaveChanges(); } }
public void Delete(int employeeKey) { using (var context = new CodeFirstModels()) { var employee = context.Employees.Where(e => e.EmployeeKey == employeeKey).First(); context.Employees.Remove(employee); context.SaveChanges(); } }
public Employee InsertAndReturn(Employee employee) { using (var context = new CodeFirstModels()) { context.Employees.Add(employee); context.SaveChanges(); return(employee); } }
public int Insert(Employee employee) { using (var context = new CodeFirstModels()) { context.Employees.Add(employee); context.SaveChanges(); return(employee.EmployeeKey); } }
public void Update(EmployeeOfficePhone employee) { using (var context = new CodeFirstModels()) { var entity = context.Employees.Where(e => e.EmployeeKey == employee.EmployeeKey).First(); entity.FirstName = employee.FirstName; entity.LastName = employee.LastName; entity.OfficePhone = employee.OfficePhone; context.SaveChanges(); } }
public IList <EmployeeOfficePhone> GetOfficePhoneNumbers() { using (var context = new CodeFirstModels()) { return(context.Employees.Select(e => new EmployeeOfficePhone() { EmployeeKey = e.EmployeeKey, FirstName = e.FirstName, LastName = e.LastName, OfficePhone = e.OfficePhone }).ToList()); } }
public void Update(EmployeeOfficePhone employee) { const string sql = @"UPDATE HR.Employee SET FirstName = @p0, LastName = @p1, OfficePhone = @p2 WHERE EmployeeKey = @p3 "; using (var context = new CodeFirstModels()) { context.Database.ExecuteSqlCommand(sql, employee.FirstName, employee.LastName, employee.OfficePhone, employee.EmployeeKey); } }
public int Upsert(Employee employee) { using (var context = new CodeFirstModels()) { if (employee.EmployeeKey == 0) { context.Entry(employee).State = EntityState.Added; } else { context.Entry(employee).State = EntityState.Modified; } context.SaveChanges(); return(employee.EmployeeKey); } }