So I’ve just started working with linq as well as using lambda expressions. I’ve run into a small hiccup while trying to get some data that I want. This method should return a list of all projects that are open or in progress from Jira
Here’s the code
public static List<string> getOpenIssuesListByProject(string _projectName)
{
JiraSoapServiceService jiraSoapService = new JiraSoapServiceService();
string token = jiraSoapService.login(DEFAULT_UN, DEFAULT_PW);
string[] keys = { getProjectKey(_projectName) };
RemoteStatus[] statuses = jiraSoapService.getStatuses(token);
var desiredStatuses = statuses.Where(x => x.name == "Open" || x.name == "In Progress")
.Select(x=>x.id);
RemoteIssue[] AllIssues = jiraSoapService.getIssuesFromTextSearchWithProject(token, keys, "", 99);
IEnumerable<RemoteIssue> openIssues = AllIssues.Where(x=>
{
foreach (var v in desiredStatuses)
{
if (x.status == v)
return true;
else
return false;
}
return false;
});
return openIssues.Select(x => x.key).ToList();
}
Right now this only select issues that are “Open”, and seems to skip those that are “In Progress”.
My question: First, why am I only getting the “Open” Issues, and second is there a better way to do this?
The reason I get all the statuses first is that the issue only stores that statuses ID, so I get all the statuses, get the ID’s that match “Open” and “In Progress”, and then match those ID numbers to the issues status field.
The code you had was only checking the first state and returning false. You need to iterate all states and return false only if it’s not in the list at all.