public List <ShiftsEmployee> GetEmployeesBySearch(string fname, string lname, Nullable <int> dep) { List <ShiftsEmployee> list = new List <ShiftsEmployee>(); List <Employee> emplist = db.Employees.Where(x => x.FirstName.Contains(fname) && x.LastName.Contains(lname) && x.DepatmentID == dep).ToList(); // List<Employee> emplist = new List<Employee>(); // // if(dep != null) // { // emplist = elist.Where(x => x.DepatmentID == dep).ToList(); // } // else // { // emplist = elist; // } foreach (var item in emplist) { var result = from emp in db.Employees join empshift in db.EmployeeShifts on emp.ID equals empshift.EmployeeID join shift in db.Shifts on empshift.ShiftID equals shift.ID where empshift.EmployeeID == item.ID select new Shifts { Date = (DateTime)shift.Date, StartTime = shift.StartTime, EndTime = shift.EndTime }; List <Shifts> slist = new List <Shifts>(); foreach (var x in result) { Shifts s = x; slist.Add(s); } ShiftsEmployee se = new ShiftsEmployee(); se.EmployeeID = item.ID; se.FirstName = item.FirstName; se.LastName = item.LastName; se.StartWorkYear = item.StartWorkYear; se.DepartmentID = item.DepatmentID; se.list = slist; list.Add(se); } return(list); }
public List <ShiftsEmployee> GetAllEmployeeData() { List <ShiftsEmployee> list = new List <ShiftsEmployee>(); List <Employee> emplist = db.Employees.ToList(); foreach (var item in emplist) { var result = from emp in db.Employees join empshift in db.EmployeeShifts on emp.ID equals empshift.EmployeeID join shift in db.Shifts on empshift.ShiftID equals shift.ID where empshift.EmployeeID == item.ID select new Shifts { Date = (DateTime)shift.Date, StartTime = shift.StartTime, EndTime = shift.EndTime }; List <Shifts> slist = new List <Shifts>(); foreach (var x in result) { Shifts s = x; slist.Add(s); } ShiftsEmployee se = new ShiftsEmployee(); se.EmployeeID = item.ID; se.FirstName = item.FirstName; se.LastName = item.LastName; se.StartWorkYear = item.StartWorkYear; se.DepartmentID = item.DepatmentID; se.list = slist; list.Add(se); } return(list); }