private IQueryable <Applicant_QuickSearch.Projection> Filter(IQueryable <Applicant_QuickSearch.Projection> query) { query = query.Where(x => x.IsApplicant); if (Hired == ApplicantHiredFilter.Exclude) { query = query.Where(x => !x.IsHired); } else if (Hired == ApplicantHiredFilter.OnlyHired) { query = query.Where(x => x.IsHired); } Expression <Func <Applicant_QuickSearch.Projection, bool> > predicate = x => x.FullName1.StartsWith(Term) || x.FullName2.StartsWith(Term) || x.Companies.Any(y => y.StartsWith(Term)) || x.Skills.StartsWith(Term) || x.TechnicalSkills.Any(y => y.StartsWith(Term)) || x.AttachmentNames.Any(y => y.StartsWith(Term)); if (SearchInAttachments) { predicate = predicate.Or(x => x.AttachmentContent.Any(y => y.StartsWith(Term))); } query = query.Where(predicate); foreach (var slug in WithEvents.EmptyIfNull()) { query = query.Where(x => x.EventSlugs == slug); } if (Highlighted) { query = query.Where(x => x.IsHighlighted); } return(query); }
private IQueryable <Applicant_QuickSearch.Projection> Filter(IQueryable <Applicant_QuickSearch.Projection> query) { query = query.Where(x => x.IsApplicant); if (Hired == ApplicantHiredFilter.Exclude) { query = query.Where(x => !x.IsHired); } else if (Hired == ApplicantHiredFilter.OnlyHired) { query = query.Where(x => x.IsHired); } string firstPart = ""; string SecondPart = ""; var isSplit = false; if (Term != null) { if (Term.Contains(",")) { firstPart = Term.Split(',')[0].Replace(" ", string.Empty); SecondPart = Term.Split(',')[1].Replace(" ", string.Empty); isSplit = true; } else if (Term.Contains(" ")) { firstPart = Term.Split(' ')[0].Replace(" ", string.Empty); SecondPart = Term.Split(' ')[1].Replace(" ", string.Empty); isSplit = true; } } Expression <Func <Applicant_QuickSearch.Projection, bool> > predicate = x => x.FullName1.StartsWith(Term) || x.FullName2.StartsWith(Term) || x.Companies.Any(y => y.StartsWith(Term)) || x.Skills.StartsWith(Term) || x.TechnicalSkills.Any(y => y.StartsWith(Term)) || x.AttachmentNames.Any(y => y.StartsWith(Term)); if (isSplit) { predicate = predicate.Or(x => (x.FirstName.StartsWith(firstPart) && x.LastName.StartsWith(SecondPart)) || (x.FirstName.StartsWith(SecondPart) && x.LastName.StartsWith(firstPart))); } if (SearchInAttachments) { predicate = predicate.Or(x => x.AttachmentContent.Any(y => y.StartsWith(Term))); } query = query.Where(predicate); foreach (var slug in WithEvents.EmptyIfNull()) { query = query.Where(x => x.EventSlugs == slug); } if (Highlighted) { query = query.Where(x => x.IsHighlighted); } return(query); }