public ActionResult GetWorkItems(string accountName, string projectName) { AccountDetail accountDetail = new AccountDetail { WorkItemDetails = new List <WorkItemDetail>(), SelectedAccountName = accountName, SelectedProjectName = projectName }; try { if (Convert.ToString(Session["PAT"]) != null) { string token = Convert.ToString(Session["PAT"]); CLWorkItem cLWorkItem = new CLWorkItem(token); var workItems = cLWorkItem.GetWorkItemsByQuery(accountName, projectName); if (workItems.Status) { var splitWI = cLWorkItem.WIAsList(workItems.ResponseAsDynamicObj.workItems); foreach (var wi in splitWI) { var wiDetils = cLWorkItem.GetWIByIds(accountName, projectName, wi); if (wiDetils.Status) { var wiDs = JsonConvert.DeserializeObject <AzureDevOpsService.Models.WorkItemFetchResponse.WorkItems>(wiDetils.ResponseAsString); foreach (var widetail in wiDs.value) { var wiDetailsMdel = new WorkItemDetail { Id = Convert.ToString(widetail.id), Name = Convert.ToString(widetail.fields.SystemTitle), Type = Convert.ToString(widetail.fields.SystemWorkItemType), AttachmentPath = new List <Attachment>() }; if (widetail.relations != null) { foreach (var rel in widetail.relations) { if (rel != null) { if (rel.rel == "AttachedFile") { Attachment attachment = new Attachment { Uri = rel.url }; string attachmentUrl = rel.url; int index = attachmentUrl.LastIndexOf("/"); string attachmentId = attachmentUrl.Substring(index + 1); attachment.AttachmentId = attachmentId; attachment.Name = rel.attributes["name"]; wiDetailsMdel.AttachmentPath.Add(attachment); } } //wiDetailsMdel.AttachmentPath.Add() } } accountDetail.WorkItemDetails.Add(wiDetailsMdel); } } } } return(PartialView("_GetWorkItems", accountDetail)); } else { return(RedirectToAction("../Account/Verify")); } } catch (Exception) { return(View(accountDetail)); } }
// TODO: This should be returned by API private string GetWorkItemUrl(WorkItemDetail item) { return($"https://{_instanceName}.visualstudio.com/{item.WorkItemProject}/_workitems/edit/{item.WorkItemId}"); }