public IQueryable <tbl_Project> GetSearchedProjects(string searchField, string searchString, string searchOper) { var predicate = PredicateExtensions.True <tbl_Project>(); switch (searchField) { case "ID": if (searchOper == "bw") { predicate = predicate.And(p => p.Project_ID.ToString().StartsWith(searchString)); } if (searchOper == "eq") { predicate = predicate.And(p => p.Project_ID == int.Parse(searchString)); } if (searchOper == "cn") { predicate = predicate.And(p => p.Project_ID.ToString().Contains(searchString)); } break; case "Project_Number": if (searchOper == "bw") { predicate = predicate.And(p => p.Project_Number.ToString().StartsWith(searchString)); } if (searchOper == "eq") { predicate = predicate.And(p => p.Project_Number == int.Parse(searchString)); } if (searchOper == "cn") { predicate = predicate.And(p => p.Project_Number.ToString().Contains(searchString)); } break; case "SAP_Number": if (searchOper == "bw") { predicate = predicate.And(p => p.SAP_Number.StartsWith(searchString)); } if (searchOper == "eq") { predicate = predicate.And(p => p.SAP_Number == searchString); } if (searchOper == "cn") { predicate = predicate.And(p => p.SAP_Number.ToString().Contains(searchString)); } break; case "WBS": if (searchOper == "bw") { predicate = predicate.And(p => p.WBS.StartsWith(searchString)); } if (searchOper == "eq") { predicate = predicate.And(p => p.WBS == searchString); } if (searchOper == "cn") { predicate = predicate.And(p => p.WBS.ToString().Contains(searchString)); } break; case "Project_Name": if (searchOper == "bw") { predicate = predicate.And(p => p.Project_Name.StartsWith(searchString)); } if (searchOper == "eq") { predicate = predicate.And(p => p.Project_Name == searchString); } if (searchOper == "cn") { predicate = predicate.And(p => p.Project_Name.ToString().Contains(searchString)); } break; case "Status": if (searchOper == "bw") { predicate = predicate.And(p => p.tbl_Status.Status.StartsWith(searchString)); } if (searchOper == "eq") { predicate = predicate.And(p => p.tbl_Status.Status == searchString); } if (searchOper == "cn") { predicate = predicate.And(p => p.tbl_Status.Status.Contains(searchString)); } break; } return(db.tbl_Projects.Where(predicate)); }
public IQueryable <tbl_User> GetSearchedUsers(string searchField, string searchString, string searchOper) { var predicate = PredicateExtensions.True <tbl_User>(); switch (searchField) { case "User_CAI": if (searchOper == "bw") { predicate = predicate.And(p => p.User_CAI.ToString().StartsWith(searchString)); } if (searchOper == "eq") { predicate = predicate.And(p => p.User_CAI == searchString); } if (searchOper == "cn") { predicate = predicate.And(p => p.User_CAI.ToString().Contains(searchString)); } break; case "User_FirstName": if (searchOper == "bw") { predicate = predicate.And(p => p.User_FirstName.ToString().StartsWith(searchString)); } if (searchOper == "eq") { predicate = predicate.And(p => p.User_FirstName == searchString); } if (searchOper == "cn") { predicate = predicate.And(p => p.User_FirstName.ToString().Contains(searchString)); } break; case "User_LastName": if (searchOper == "bw") { predicate = predicate.And(p => p.User_LastName.StartsWith(searchString)); } if (searchOper == "eq") { predicate = predicate.And(p => p.User_LastName == searchString); } if (searchOper == "cn") { predicate = predicate.And(p => p.User_LastName.ToString().Contains(searchString)); } break; case "User_Role": if (searchOper == "bw") { predicate = predicate.And(p => p.tbl_User_Role.User_Role_Descr.StartsWith(searchString)); } if (searchOper == "eq") { predicate = predicate.And(p => p.tbl_User_Role.User_Role_Descr == searchString); } if (searchOper == "cn") { predicate = predicate.And(p => p.tbl_User_Role.User_Role_Descr.ToString().Contains(searchString)); } break; } return(db.tbl_Users.Where(predicate)); }