All TFS User and Status - tfs

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]);
}

Related

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

TFS Query: get only topmost elements assigned to me

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>

Sending custom values on save and update using Telerik Grid

I have a Telerik grid in my asp.net mvc application that looks something like:
Now it lists all the regions in a zone selected from the list placed just above the grid. zoneid is foreign key in the grid. Now I want that when I add new region in the grid the zoneID should be taken from the list instead of what is present in zone column of the grid because that value is just to display the zone and that can also be removed from the grid as it as apparent from the list which zone the listed regions belong to.
I understand that I could have used editor templates to show this list inside the grid on edit but I prefer it to be outside the grid and provide some filtering on basis of the zone as we are likely to have many regions per zone. so my concern here, now, is how can I set ZoneID of a region (edited or newly added) equal to selected value of list that shows just above the grid control.
When you click on the AddNewRecord button, why don't you set the Value of your zone equals to the zoneId selected in the combobox value ?
I've done something a little similar, but I had to get the value from a Treeview.
private void btnAddContact_Click(object sender, EventArgs e)
{
Int64 companyId = Int64.Parse(treeCompany.SelectedNode.Name);
dsSociete.ContactRow newContact = dsSociete.Contact.NewContactRow();
newContact.SocieteId = societeId;
dsSociete.Contact.AddContactRow(newContact);
}
And once i add a new Contact, it gets automatically its Company (Societe is Company in French) set.
I did it in Winform, but I guess you can do the same in Web?
I solved this problem by hooking the onSave event of Telerik grid like
<%
Html.Telerkik.Grid<xyz.company>()
.Name("name")
.// other properties
.Events(even=>even.onSave("onSave")
.Render();%>
Inside onSave event handler in JS I have written something like
function onSave(e)
{
var data = e.values;
data["companyID"] = $("#CompanySelectList").val();
e.values = data;
return true;
}
onSave event adds the companyID at companyID index of json that will be submitted to the server and modelbinder will bind it with concerning property name of model.

How to loop through the FormCollection to check if textboxes have values?

I have a search page that has 6 textboxes which i pass as FormCollection to the action in the controller. I dont want to search for records if ther is no values in textboxes.
Is there a way to loop through all textboxes in FormCollection to check which ones have values in them?
I am a student in the college and this project is part of my summer experience program.
I realize that this is a newbie question :)
Thank you!
You can loop through the FormCollection like this:
foreach( string key in forms.Keys )
{
...
}
However, note that the browser only sends you names and values. It does not send you the types of inputs, so you have no way to check if the value is a checkbox, unless you know all checkboxes names in advance. But if that's the case, you don't need to loop - just take them out of the collection by name.
List<string> list = new List<string>();
for(int i= 0; i< form.AllKeys.Count(); ++i)
{
list.Add(form.Get(i));
}
This will give you all the actual values for each key

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