I have a bunch of these Jobs based on LINQ queries. I am looking for a good way to reorganize them and make them easier to read and allow changes to requests depending on the language / region, etc.
var mailTaskOne = CreateTask(() => myService.Mail.Where(p => p.ProjectName == "Delta" && (p.MailLang== (int)MailLanguage.EU || p.MailLang == (int)MailLanguage.RU) && (p.DateEntered >= startDate && p.DateEntered <= endDate) && p.MailPriority == (int)MailPriority.High).Count());
One way, in my opinion, would be convenient to split the request into something like this.
var results = myService.Mail.Where(x => x.ProjectName == "Delta"); results = results.Where(p => p.MailLang== (int)MailLanguage.EU); results = results.Where(p => p.DateModified >= startDate && p.DateModified <= endDate);
This would allow me to do this without repeating the entire query for each region.
if (MailLanguage == "English") results = results.Where(p => p.MailLang== (int)MailLanguage.EU); else results = results.Where(p => p.MailLang== (int)MailLanguage.RU);
Is there anyone who knows a better solution for this? I get huge features since I need to make 20 of these queries depending on requirements; such as Region, Project Name, etc.
Edit:
Due to some limitations that I did not know about using the back-end (web services / api), I, unfortunately, could not use some of the wonderful answers mentioned in this question.
For example, this does not work out correctly, but in no case, because the answer is incorrect, it just does not work with the API I'm working with, possibly because it is poorly implemented.
public bool IsValid(Type x) { return (xa == b) && (xc ==d) && (xd == e); }
In any case, anyone looking for similar solutions is all the correct answers, but in the end I ended up with something similar to a snurre solution.