Using lambda expressions and linq
Posted
by Andy
on Stack Overflow
See other posts from Stack Overflow
or by Andy
Published on 2010-05-19T16:21:19Z
Indexed on
2010/05/19
16:40 UTC
Read the original article
Hit count: 253
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.
© Stack Overflow or respective owner