187 public IQueryable<Talent> GetTalents(string searchExpression)
188 {
189 IQueryable<Talent> t;
190 if (string.IsNullOrEmpty(searchExpression))
191 {
192 t = _repository.GetTalents();
193 }
194 else
195 {
196 t = BasicSearch(searchExpression);
197 }
198 return t;
199 }
200
201 private static readonly char[] SplitDelimiters = " ".ToCharArray();
202
203 // search should come in as 'jon johnny323@yahoo.com rodgers'
204 private IQueryable<Talent> BasicSearch(string search)
205 {
206 // Just replacing " " with " " wouldn't help with "a b"
207 string[] terms = search.Trim()
208 .ToLower()
209 .Split(SplitDelimiters,
210 StringSplitOptions.RemoveEmptyEntries);
211 IQueryable<Talent> talents = _repository.GetTalents();
212 foreach (string s in terms)
213 {
214 talents = AddBasicSearch(talents, s);
215 }
216 return talents;
217 }
218
219 private IQueryable<Talent> AddBasicSearch(IQueryable<Talent> t, string s)
220 {
221 return t.Where(x => x.FirstName.ToLower().Contains(s)
222 || x.LastName.ToLower().Contains(s)
223 || x.Email.ToLower().Contains(s)
224 || x.LanguagesString.ToLower().Contains(s)
225 );
226 }
No comments:
Post a Comment