diff --git a/ClientLibrary/Samples/Work/BoardsSample.cs b/ClientLibrary/Samples/Work/BoardsSample.cs new file mode 100644 index 00000000..1abddbdf --- /dev/null +++ b/ClientLibrary/Samples/Work/BoardsSample.cs @@ -0,0 +1,35 @@ +using Microsoft.VisualStudio.Services.WebApi; +using Microsoft.TeamFoundation.Core.WebApi.Types; +using Microsoft.TeamFoundation.Work.WebApi; +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.TeamFoundation.Core.WebApi; + +namespace Microsoft.Azure.DevOps.ClientSamples.Work +{ + [ClientSample(WorkWebConstants.RestArea, "boards")] + public class BoardsSample : ClientSample + { + [ClientSampleMethod] + public Board GetTeamStoriesBoard() + { + VssConnection connection = Context.Connection; + WorkHttpClient workClient = connection.GetClient(); + + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + WebApiTeamRef team = ClientSampleHelpers.FindAnyTeam(this.Context, project.Id); + + TeamContext context = new TeamContext(project.Id, team.Id); + context.Team = team.Name; + context.Project = project.Name; + + Board board = workClient.GetBoardAsync(context, "Stories").Result; + + Context.Log("Columns for 'Stories' Board for Project '{0}' and Team '{1}'", context.Project, context.Team); + Context.Log(""); + + return board; + } + } +} diff --git a/ClientLibrary/Samples/WorkItemTracking/WorkItemsSample.cs b/ClientLibrary/Samples/WorkItemTracking/WorkItemsSample.cs index b4784545..49a9bda7 100644 --- a/ClientLibrary/Samples/WorkItemTracking/WorkItemsSample.cs +++ b/ClientLibrary/Samples/WorkItemTracking/WorkItemsSample.cs @@ -1101,6 +1101,58 @@ public WorkItemTemplate ReplaceTemplate() return result; } + [ClientSampleMethod] + public WorkItem UpdateWorkItemBoardColumn() + { + string targetColumn = "Testing"; //need to set to match your board + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient witClient = connection.GetClient(); + + JsonPatchDocument patchDocument = new JsonPatchDocument(); + + //create a work item that drops into the new column by default + WorkItem workItem = this.CreateWorkItem("Board Column Test", "User Story"); + + string wefField = ""; + + //find the WEF field + //todo: do something smarter rather than loop through all fields to find the WEF + foreach (var field in workItem.Fields) + { + if (field.Key.Contains("_Kanban.Column")) + { + wefField = field.Key.ToString(); + break; + } + } + + //build a patch document to update the WEF field + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Test, + Path = "/rev", + Value = "1" + } + ); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/fields/" + wefField, + Value = targetColumn + } + ); + + WorkItem result = witClient.UpdateWorkItemAsync(patchDocument, Convert.ToInt32(workItem.Id)).Result; + + Context.Log("Updated work item to teams board column '" + targetColumn + "'"); + + return result; + } + [ClientSampleMethod] public void DeleteTemplate() {