public IHttpActionResult CreateWI() { string requestData = Request.Content.ReadAsStringAsync().Result; WebHookRequestModel webhook = JsonConvert.DeserializeObject <WebHookRequestModel>(requestData); control.CreateWork(webhook); return(Ok(true)); }
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; } }