public static WorkItem UpdateWorkItemFields(int WIId, Dictionary <string, object> Fields) { try { JsonPatchDocument patchDocument = new JsonPatchDocument(); foreach (var key in Fields.Keys) { JsonPatchOperation Jsonpatch = new JsonPatchOperation() { Operation = Operation.Replace, Path = "/fields/" + key, Value = Fields[key] }; if (!patchDocument.Contains(Jsonpatch)) { patchDocument.Add(Jsonpatch); } } if (patchDocument.Count != 0) { return(WitClient.UpdateWorkItemAsync(patchDocument, WIId).Result); } else { return(null); } } catch (Exception E) { throw (E); } }
public void CreateWork(WebHookRequestModel webhook) { try { string PAT = "mwcoyft3jyr2hilu4jsibj2lz32hxe5cxawpa2tlwqtibag76wmq"; string BaseURL = webhook.resourceContainers.project.baseUrl; string Project = webhook.resourceContainers.project.id; //string RequestBody = Request.; int daysToAdd = 7; DateTime date = Convert.ToDateTime("2020-05-19T09:04:02.72Z"); while (daysToAdd > 0) { date = date.AddDays(1); if (date.DayOfWeek != DayOfWeek.Saturday && date.DayOfWeek != DayOfWeek.Sunday) { daysToAdd -= 1; } } JsonPatchDocument patchDocument = new JsonPatchDocument(); JsonPatchOperation Jsonpatch = new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/" + "Custom.EndDate", Value = date.ToString("yyyy-MM-dd'T'HH:mm:ss.fffffff'Z'") }; if (!patchDocument.Contains(Jsonpatch)) { patchDocument.Add(Jsonpatch); } ConnectWithPAT(BaseURL, PAT); WitClient.UpdateWorkItemAsync(patchDocument, webhook.resource.id); } catch (Exception e) { throw e; } }