Ejemplo n.º 1
0
 public void Delete(int employeeKey)
 {
     using (var context = new CodeFirstModels())
     {
         context.Database.ExecuteSqlCommand("DELETE FROM HR.Employee WHERE EmployeeKey = @p0", employeeKey);
     }
 }
Ejemplo n.º 2
0
 public IList <Employee> GetByManager(int managerKey)
 {
     using (var context = new CodeFirstModels())
     {
         return(context.Employees.Where(e => e.ManagerKey == managerKey).AsNoTracking().ToList());
     }
 }
Ejemplo n.º 3
0
 public IList <Employee> GetAll()
 {
     using (var context = new CodeFirstModels())
     {
         return(context.Employees.AsNoTracking().ToList());
     }
 }
Ejemplo n.º 4
0
 public Employee Get(int employeeKey)
 {
     using (var context = new CodeFirstModels())
     {
         return(context.Employees.Where(e => e.EmployeeKey == employeeKey).AsNoTracking().First());
     }
 }
Ejemplo n.º 5
0
 public void Update(Employee employee)
 {
     using (var context = new CodeFirstModels())
     {
         context.Entry(employee).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Ejemplo n.º 6
0
 public Employee InsertAndReturn(Employee employee)
 {
     using (var context = new CodeFirstModels())
     {
         context.Employees.Add(employee);
         context.SaveChanges();
         return(employee);
     }
 }
Ejemplo n.º 7
0
 public int Insert(Employee employee)
 {
     using (var context = new CodeFirstModels())
     {
         context.Employees.Add(employee);
         context.SaveChanges();
         return(employee.EmployeeKey);
     }
 }
Ejemplo n.º 8
0
 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();
     }
 }
Ejemplo n.º 9
0
 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();
     }
 }
Ejemplo n.º 10
0
 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
         }).AsNoTracking().ToList());
     }
 }
Ejemplo n.º 11
0
        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);
            }
        }
Ejemplo n.º 12
0
 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);
     }
 }