예제 #1
0
 public List <Employee> GetAllEmployees()
 {
     using (var context = new EmployeesEFContext()){
         var query = from e in context.Employees
                     orderby e.Id
                     select e;
         return(query.ToList());
     }
 }
예제 #2
0
 public List <Employee> SearchEmployees(string searchTerm)
 {
     using (var context = new EmployeesEFContext())
     {
         var query = from e in context.Employees
                     where e.Name == searchTerm
                     select e;
         return(query.ToList());
     }
 }
예제 #3
0
 public Employee GetEmployee(int id)
 {
     using (var context = new EmployeesEFContext())
     {
         var query = from e in context.Employees
                     where e.Id == id
                     select e;
         return(query.First());
     }
 }
예제 #4
0
 public void DeleteEmployee(int id)
 {
     using (var context = new EmployeesEFContext())
     {
         var query = from e in context.Employees
                     where e.Id == id
                     select e;
         Employee emp = query.First();
         context.Employees.Remove(emp);
         context.SaveChanges();
     }
 }
예제 #5
0
 public void UpdateEmployee(Employee emp)
 {
     using (var context = new EmployeesEFContext())
     {
         var query = from e in context.Employees
                     where e.Id == emp.Id
                     select e;
         foreach (Employee e in query)
         {
             e.Name      = emp.Name;
             e.StartDate = emp.StartDate;
         }
         context.SaveChanges();
     }
 }
예제 #6
0
 public void AddEmployee(Employee emp)
 {
     using (var context = new EmployeesEFContext())
     {
         //id problem
         var query = context.Employees.OrderByDescending(e => e.Id).FirstOrDefault();
         if (query == null)
         {
             emp.Id = 1;
         }
         else
         {
             emp.Id = query.Id + 1;
         }
         context.Employees.Add(emp);
         context.SaveChanges();
     }
 }