Exemplo n.º 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());
     }
 }
Exemplo n.º 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());
     }
 }
Exemplo n.º 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());
     }
 }
Exemplo n.º 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();
     }
 }
Exemplo n.º 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();
     }
 }
Exemplo n.º 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();
     }
 }