TFS Query: get only topmost elements assigned to me - tfs

I am trying to build a tfs query, which will return only the topmost items that are assigned to me.
Examples:
UserStory (US) is assigned to me and contains tasks that are assigned
to me => query returns only the US
US is assigned to someone else,
but it contains tasks that are assigned to me => query returns the
tasks
US is assigned to me, but tasks are assigned to someone else =>
query returns the US
I struggling to figure out, how to access the parent of a task or maybe this isn't even the right approach. I am working with VS and TFS 2010. Ideas?
[EDIT]
Another idea would be to write a wiql query, that finds all items assigned to me and than checks if the link has some properties, but iam not sure about that. In TFS2013 there supposed to be something similar ("match top-level workitems first"), unless this is just a sorting option.

This is not possible with one query, at least you need 2, because you can't combine link filters with parts of a query:
Flat List
WorkItemType = UserStory AND AssignedTo = #ME
Work Items and Direct Links
WorkItemType = Task AND AssignedTo = #ME
Filters for linked work items:
WorkItemType = UserStory AND AssignedTo <> #ME
Return all top level work items
The first query will just list all User Stories assigned to you, no matter if something is linked or not. The second query will list all Task that are assigned to you, but have no UserStory linked that is assigned to you.
[EDIT]
Another option could be to combine both queries, but I can't test it in my environment:
Work Items and Direct Links
(WorkItemType = Task OR WorkItemType = User Story) AND AssignedTo = #ME
Filters for linked work items:
WorkItemType = UserStory AND AssignedTo <> #ME
Return all top level work items
This will list all User Stories and Tasks that are assigned to you, but have no parent User Story linked.
[EDIT2]
<?xml version="1.0" encoding="utf-8"?><WorkItemQuery Version="1"><TeamFoundationServer>http://tfs:8080/tfs/DefaultCollection</TeamFoundationServer><TeamProject>Test</TeamProject><Wiql>SELECT [System.Id], [System.Links.LinkType], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State] FROM WorkItemLinks WHERE ([Source].[System.TeamProject] = #project AND ( [Source].[System.WorkItemType] = 'Task' OR [Source].[System.WorkItemType] = 'UserStory' ) AND [Source].[System.AssignedTo] = #me) And ([System.Links.LinkType] <> '') And ([Target].[System.WorkItemType] = 'UserStory' AND [Target].[System.AssignedTo] <> #me) ORDER BY [System.Id] mode(MayContain)</Wiql></WorkItemQuery>

Related

Accesing the content from immediate parent in Umbraco

I am trying to access content from my level 2 document type from a sub level in Umbraco. level 2 has multiple pages of same document type. I am using the code below
var rootByTraversing = Umbraco.AssignedContentItem.AncestorOrSelf(2);
var openingTimesByDescendants = rootByTraversing.Descendants().Where(f => f.DocumentTypeAlias == "PageLevel2").FirstOrDefault();
Is it possible for me to get the immediate parent node of this document type and not FirstOrDefault node?
I don't want to access the content through node id.
Not sure I follow entirely, especially why you don't want to access via node ID... Your current content item has a Path property in which all ancestors IDs are listed in a comma separated list. Couldn't you just split that string and select whichever level (like ancestors[2] for level 2, I'd guess) to get the ID of that node. Then you could go something like
var level2AncestorId = Umbraco.AssignedContentItem.Path.Split(',')[2];
var openingTimesByDescendants = rootByTraversing.Descendants().Where(f => f.Id == (int)level2AncestorId && f.DocumentTypeAlias == "PageLevel2").FirstOrDefault();
Which should only give you one node and it should be the direct ancestor. Right?

MVC Display Offences List By User State

I am just starting learning MVC and I am stuck on this issue. I will appreciate if anyone has come across this before. Thanks
I would like to display the list by station. E.g Police of New-York can only see list of offences in New-York.
enter image description here This is the most recent change but still not working.
I would like to display the list of offences by the USER state.
At the moment I am displaying all the users regardless of their state id.
Here are two options that come to mind. One, you can filter out the offenses by iterating over them and pulling out only the values you need into a new list in C#. Two, you could edit the stored procedure to pass in parameters (such as a State ID or User ID) and then filter out the list of offenses returned from the database using a WHERE clause. Below is some sample code based on your image.
Idea One:
public ActionResult ViewOffenceList(int filterStateID)
{
PageModel model = new PageModel();
DBFile db = new DBFile();
var details = db.Offence.ToList();
List<Offence> filteredList = new List<Offence>();
foreach (var offence in details)
{
if (offence.StateID == filterStateID)
{
filteredList.Add(offence);
}
}
model.OffenceList = filteredList;
return View(model);
}
Idea Two:
CREATE PROCEDURE dbo.fwsp_GetOffenceList
#FilterStateID TINYINT
AS
SELECT *
FROM dbo.offences o
WHERE o.StateID = #FilterStateID
GO
These are just some quick overviews of the two options that come to mind given my experiences. In general, grab the ID of the state you wish to filter on, and use that to filter out which data to actually display. It sounds like you may have a User object which may have an associated State which you could use as the "filterStateID" in my examples.
If you're just starting out I'd suggest finding some tutorials online and walking through them. Here's one directly from Microsoft: https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/start-mvc?tabs=aspnetcore2x

Creating Query Variable in TFS

We've a requirement to pass a custom query variable to filter the TFS records by running saved TFS query.
As we have #Me, #Project, #Today and [Any] can we use a custom variable like below, if yes how can we do this or is there any better approach for this.
UserEmailAddress = #EmailAddress, to get the records which matches the #EmailAddress which is passed from C# source code and we will add the variable and call the saved TFS query.
var variables = new Dictionary<string, string>() { { "project", "ESE_Proj" }, {"EmailAddress", "test} };
wiQuery = new Query(wiStore(), query.QueryText, variables);
wiTrees = wiQuery.RunLinkQuery();
Field name of a Work Item Type, we have created work item types, say example Person is a work item type with UserEmailAddress as field in it. I want to create a query in tfs such that user can call query from c# by passing email address by taking it from text box and run the query for the entered email address –
You will not be able to store the query in TFS. While you can create and use custom variables in c# with the API TFS has no understanding of them.
You can only use #me, #project, #today, and #currentiteration in a stored query.
Ok, got it. Because the query is also used by the rest of the team in the team explorer. I left the #project in there, but when I need it, I replace #project with the actual project name.

All TFS User and Status

I have created a webform that has a couple of controls on it. One of those controls is a Status Combobox, which needs to be populated with Status (Which has been shown in TFS Combobox same like that in my webform). I am unable to find status collection object in TFS.
And, I also need to populate All users in a combobox on my form in the same manner.
Can anyone have any idea how to populte all TFS user in my web from Combobox
and Status Collection of WorkItem in Staus Combobox
Thanks
There are two places that a list of values can be defined. It can be defined in a global list, or it can be defined in the work item's definition. Assuming that what you're talking about in your question are the "State" and "AssignedTo" fields, the following code will iterate through those values.
Note - these can vary between work item types, so you will need to know two pieces of information before you make this call:
The team project that contains the work item.
The work item type you are working on
In this example, I'm using the first team project in the collection, and the relatively-generic "Task" work item type. You will probably want to specify a specific project (wis.Projects[]), and a specific work item type (WorkItemTypes[]).
TfsTeamProjectCollection coll = new TfsTeamProjectCollection(new Uri("http://sw100429:8080"));
WorkItemStore wis = coll.GetService<WorkItemStore>();
var values = wis.Projects[0].WorkItemTypes["Task"].FieldDefinitions[CoreField.State].AllowedValues;
for (int i = 0; i < values.Count; i++)
{
System.Console.WriteLine(values[i]);
}
Similarly, you can do the same with the AssignedTo field:
values = wis.Projects[0].WorkItemTypes["Task"].FieldDefinitions[CoreField.AssignedTo].AllowedValues;
for (int i = 0; i < values.Count; i++)
{
System.Console.WriteLine(values[i]);
}

Determining which checkboxes are not checked in ASP.NET MVC?

Imagine a page which uses checkboxes to keep track of mailing list subscriptions about pets:
cats-list ( )
dogs-list (*)
birds-list ( )
horses-list (*)
I use ASP.NET MVC's Html.Checkbox extension method in a loop (not shown):
<%= Html.Checkbox("subscriptions[" + i +"]", item.subscribed, item.listName) %>
"i" is the iteration variable in the loop. Using this convention allows my controller action to model bind subscriptions[i] to a List<string> which then contains a list of mailing list names to subscribe to.
How can I keep track of what's not checked? For example, if a user unchecks "dogs-list" to unsubscribe from that list, how can I tell? I'll only get "false" back from the hidden form field.
EDIT: The only solution which comes to mind is for the controller action to unsubscribe from all mailing lists, and then resubscribe to lists contained in the List<string> from the checkboxes. That's not ideal though.
You basically answered it yourself with the edit but something a bit more elegant would be better. I.e. Don't delete them all first, just determin which need to be added, which need to be deleted and which need to just remain.
E.g. (air code)
List<string> selectedSubscriptions; //This is passed in from the form using the model binder
List<string> mailingListsToRemove = GetCurrentMailingLists(); //Looks odd but bear with me
List<string> mailingListsToAdd = new List<string>();
//Loop through all the mailing lists they had selected
foreach (string selectedMailingList in selectedSubscriptions)
{
//if the mailing list exists in the list to remove, remove it from that list
//because they obviously don't want it removed
//Remember that this list also contains their current lists.
if (mailingListsToRemove.Contains(selectedMailingList))
{
mailingListsToRemove.Remove(selectedMailingList);
}
else //If it's not in the list to remove then add it
{
mailingListsToAdd.Add(selectedMailingList);
}
}
So at the end of that loop you should have two lists - one containing all the mailing lists that the user wants removed and one containing all the new mailing lists they want to be subscribed to. The mailing lists that they were already subscribed to and still wish to be subscribed to should just be left alone.
HTHs,
Charles

Resources