How about something like this:
if (!string.IsNullOrWhiteSpace(jobNumber)) return _context.Jobs.Where(j => j.JobNumber.Contains(jobNumber)); if (!string.IsNullOrWhiteSpace(jobName)) return _context.Jobs.Where(j => j.JobName.Contains(jobName)); if (!string.IsNullOrWhiteSpace(projectDirectorName)) return _context.Jobs.Where(j => j.ProjectDirectorFullName.Contains(projectDirectorName)); if (!string.IsNullOrWhiteSpace(groupName)) return _context.Jobs.Where(j => j.GroupName.Contains(groupName)); else throw new ArgumentException ("No arguments specified");
Or something that reads better:
if (!string.IsNullOrWhiteSpace(jobNumber)) return FilterJobsByNumber(jobNumber); if (!string.IsNullOrWhiteSpace(jobName)) return FilterJobsByName(jobName); if (!string.IsNullOrWhiteSpace(projectDirectorName)) return FilterJobsByDirector(projectDirectorName); if (!string.IsNullOrWhiteSpace(groupName)) return FilterJobsByGroupName(groupName); else throw new ArgumentException ("No arguments specified");
For a suitable type FilterJobsByNumber, etc.
source share