public List <Employee> GetAllEmployees() { using (var context = new EmployeesEFContext()){ var query = from e in context.Employees orderby e.Id select e; return(query.ToList()); } }
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()); } }
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()); } }
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(); } }
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(); } }
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(); } }