public ActionResult Index(LeaveSearch search) { if (ModelState.IsValid) { LoadDdlLTypes(Convert.ToInt32(search.Criteria.LTypeID)); LoadDdlAllEmployees(Convert.ToInt32(search.Criteria.EmployeeID)); DateTime EndDate = search.Criteria.EndDate.AddDays(1); var query = from lvs in db.Leaves join emp in db.Employees on lvs.EmployeeID equals emp.ID join typ in db.LTypes on lvs.LTypeID equals typ.ID join rsn in db.Reasons on lvs.ReasonID equals rsn.ID where lvs.Deleted == false && lvs.LeaveDate >= search.Criteria.StartDate && lvs.LeaveDate < EndDate && (search.Criteria.LTypeID >= 1 ? lvs.LTypeID == search.Criteria.LTypeID : 1 == 1) && (search.Criteria.EmployeeID >= 1 ? lvs.EmployeeID == search.Criteria.EmployeeID : 1 == 1) orderby lvs.LeaveDate descending select new LeaveResult() { ID = lvs.ID, LeaveDate = lvs.LeaveDate, EmployeeName = emp.LastName + ", " + emp.FirstName, LTypeName = typ.Name, ReasonDesc = rsn.Desc }; search.LeaveResults = query.ToArray(); } return View(search); }
// GET: /Leaves/ public ActionResult Index() { LeaveSearch search = new LeaveSearch(); LoadDdlLTypes(); LoadDdlAllEmployees(); var query = from lvs in db.Leaves join emp in db.Employees on lvs.EmployeeID equals emp.ID join typ in db.LTypes on lvs.LTypeID equals typ.ID join rsn in db.Reasons on lvs.ReasonID equals rsn.ID where lvs.Deleted == false orderby lvs.LeaveDate descending select new LeaveResult() { ID = lvs.ID, LeaveDate = lvs.LeaveDate, EmployeeName = emp.LastName + ", " + emp.FirstName, LTypeName = typ.Name, ReasonDesc = rsn.Desc }; search.LeaveResults = query.ToArray(); return View(search); }