//public JsonResult WorkitemDeadline() public List <ValueNew> WorkitemDeadlineGet(string projectName) { Session.Remove("WorkItemstotal"); WorkNew urlResponse = new WorkNew(); string queryString = @"Select [Work Item Type],[State], [Title],[Created By] From WorkItems "; if (Org.ProjectName != null) { queryString += "where [System.TeamProject]='" + projectName + "' "; //+ Org.ProjectName + "' "; } queryString += "Order By [Stack Rank] Desc, [Backlog Priority] Desc"; var wiql = new { query = queryString }; var content = JsonConvert.SerializeObject(wiql); string url = "https://dev.azure.com/" + Org.OrganizationName + "/_apis/wit/wiql?api-version=5.1"; ResponseWI wiqlResponse = Store.GetApi <ResponseWI>(url, "POST", content); if (wiqlResponse.workItems == null || wiqlResponse.workItems.Count == 0) { return(null); } //if (wiqlResponse.count >= 0) //{ // Session["WorkItemstotal"] = wiqlResponse.count; //} string defaultUrl = "https://dev.azure.com/" + Org.OrganizationName + "/_apis/wit/workitems?ids="; url = defaultUrl; urlResponse.value = new List <ValueNew>(); string endUrl = "&$expand=all&api-version=5.1"; for (int j = 0; j < wiqlResponse.workItems.Count; j++) { if (j % 200 == 0 && j != 0) { var batchResponse = Store.GetApi <WorkNew>(url + endUrl); urlResponse.count += batchResponse.count; foreach (var item in batchResponse.value) { urlResponse.value.Add(item); } url = defaultUrl; } if (j % 200 == 0) { url += wiqlResponse.workItems[j].id; } else { url += "," + wiqlResponse.workItems[j].id; } } url += endUrl; var lastBatchResponse = Store.GetApi <WorkNew>(url); urlResponse.count += lastBatchResponse.count; foreach (var item in lastBatchResponse.value) { urlResponse.value.Add(item); } System.Web.HttpContext.Current.Session["EWorkItems"] = urlResponse; List <ValueNew> Types = new List <ValueNew>(); List <ValueNew> Types1 = new List <ValueNew>(); List <ValueNew> BugFind = new List <ValueNew>(); List <IterationDetails> iterationsListStore = new List <IterationDetails>(); iterationsListStore = IterationsList(Org.OrganizationName, projectName);//Org.ProjectName); Session["WorkItemstotal"] = urlResponse.count; ViewBag.WorkItemstotal = urlResponse.count; int sessioncount = 0; foreach (var i in urlResponse.value) { i.totalworkItemCounts = urlResponse.count; //Types.Add(i); sessioncount += 1; if (i.fields.WorkItemType == "Bug" || i.fields.WorkItemType == "Task" || i.fields.WorkItemType == "UserStory") { foreach (var iter in iterationsListStore) { foreach (var iter1 in iter.value) { if (i.fields.Sprint == iter1.path) { DateTime finishDate = Convert.ToDateTime(iter1.attributes.finishDate); string fin = finishDate.ToString(DateTime.Now.ToString("MM/dd/yyyy")); string toDate = DateTime.Now.ToString("MM/dd/yyyy"); var Today = DateTime.Today; string finishDateSprint = iter1.attributes.finishDate; // DateTime finishdateConvert=new DateTime(); int value = DateTime.Compare(finishDate, Today); DateTime date = Convert.ToDateTime("01-01-0001 00:00:00"); // checking if (finishDate != null && finishDate != date) { if (value < 0) { Types.Add(i); } } } } } } } Session["WorkItemExtendedDate"] = Types; return(Types);//return output; }
// public List <ValueNew> Workitemlist123(string projectName) { Session.Remove("WorkItemscount"); WorkNew urlResponse = new WorkNew(); // string queryString = @"Select [Work Item Type]= 'Bug',[State], [Title],[Created By] From WorkItems "; // if (Org.ProjectName != null) // //WHERE[System.AssignedTo] = 'joselugo' WHERE[Adatum.CustomMethodology.Severity] >= 2 // queryString += "where [System.TeamProject]='" + projectName + "' "; //+ Org.ProjectName + "' "; //// queryString += "Order By [Stack Rank] Desc, [Backlog Priority] Desc"; // var wiql = new { query = queryString }; // var content = JsonConvert.SerializeObject(wiql); string url = "https://dev.azure.com/" + Org.OrganizationName + "/_apis/wit/wiql?api-version=5.1"; object wiql = new { query = "Select [Work Item Type],[State], [Title],[Created By] " + "From WorkItems " + // "Where [Work Item Type] = '" + workItemName + "' " + "Where [Work Item Type] = 'Bug' " + //"OR [Work Item Type]='Task'" + //"OR [Work Item Type]='Feature'" + //"And [Work Item Type] = 'Epic' " + "And [System.TeamProject] = '" + projectName + "' " + "Order By [Stack Rank] Desc, [Backlog Priority] Desc" }; var postValue = new StringContent(JsonConvert.SerializeObject(wiql), Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Org.pat); var response = client.PostAsync(url, postValue).Result; } var content = JsonConvert.SerializeObject(wiql); ResponseWI wiqlResponse = Store.GetApi <ResponseWI>(url, "POST", content); if (wiqlResponse.workItems == null || wiqlResponse.workItems.Count == 0) { return(null); } string defaultUrl = "https://dev.azure.com/" + Org.OrganizationName + "/_apis/wit/workitems?ids="; url = defaultUrl; urlResponse.value = new List <ValueNew>(); string endUrl = "&$expand=all&api-version=5.1"; for (int j = 0; j < wiqlResponse.workItems.Count; j++) { if (j % 200 == 0 && j != 0) { var batchResponse = Store.GetApi <WorkNew>(url + endUrl); urlResponse.count += batchResponse.count; foreach (var item in batchResponse.value) { urlResponse.value.Add(item); } url = defaultUrl; } if (j % 200 == 0) { url += wiqlResponse.workItems[j].id; } else { url += "," + wiqlResponse.workItems[j].id; } } url += endUrl; var lastBatchResponse = Store.GetApi <WorkNew>(url); urlResponse.count += lastBatchResponse.count; foreach (var item in lastBatchResponse.value) { urlResponse.value.Add(item); } System.Web.HttpContext.Current.Session["EWorkItems"] = urlResponse; List <ValueNew> Types = new List <ValueNew>(); List <ValueNew> BugFind = new List <ValueNew>(); List <IterationDetails> iterationsListStore = new List <IterationDetails>(); iterationsListStore = IterationsList(Org.OrganizationName, projectName);//Org.ProjectName); Session["WorkItemscount"] = urlResponse.count; ViewBag.WorkItemscount = urlResponse.count; foreach (var i in urlResponse.value) { if (i.fields.WorkItemType == "Bug" && i.fields.Severity == "1 - Critical") { //BugDetails bugStore=BugDetails(i.id); //if(bugStore.fields.Severity== "1 - Critical") //{ Types.Add(i); // } //&& i.fields.Severity == "1 - Critical" // if (!Types.Contains(i.fields.__invalid_name__SystemWorkItemType)) // Types.Add(i);//.__invalid_name__SystemWorkItemType); } } //string output = JsonConvert.SerializeObject(Types); //return Json(Types, JsonRequestBehavior.AllowGet); //Session["criticalBug"] = Types; return(Types); }
//public JsonResult Workitem() //{ // logic.GetWorkItem(); // return null; //} // public JsonResult Workitem() public List <ValueNew> Workitemlist(string projectName) { Session.Remove("WorkItemscount"); WorkNew urlResponse = new WorkNew(); string queryString = @"Select [Work Item Type],[State], [Title],[Created By] From WorkItems "; if (Org.ProjectName != null) { queryString += "where [System.TeamProject]='" + projectName + "' "; //+ Org.ProjectName + "' "; } queryString += "Order By [Stack Rank] Desc, [Backlog Priority] Desc"; var wiql = new { query = queryString }; var content = JsonConvert.SerializeObject(wiql); string url = "https://dev.azure.com/" + Org.OrganizationName + "/_apis/wit/wiql?api-version=5.1"; ResponseWI wiqlResponse = Store.GetApi <ResponseWI>(url, "POST", content); if (wiqlResponse.workItems == null || wiqlResponse.workItems.Count == 0) { return(null); } string defaultUrl = "https://dev.azure.com/" + Org.OrganizationName + "/_apis/wit/workitems?ids="; url = defaultUrl; urlResponse.value = new List <ValueNew>(); string endUrl = "&$expand=all&api-version=5.1"; for (int j = 0; j < wiqlResponse.workItems.Count; j++) { if (j % 200 == 0 && j != 0) { var batchResponse = Store.GetApi <WorkNew>(url + endUrl); urlResponse.count += batchResponse.count; foreach (var item in batchResponse.value) { urlResponse.value.Add(item); } url = defaultUrl; } if (j % 200 == 0) { url += wiqlResponse.workItems[j].id; } else { url += "," + wiqlResponse.workItems[j].id; } } url += endUrl; var lastBatchResponse = Store.GetApi <WorkNew>(url); urlResponse.count += lastBatchResponse.count; foreach (var item in lastBatchResponse.value) { urlResponse.value.Add(item); } System.Web.HttpContext.Current.Session["EWorkItems"] = urlResponse; List <ValueNew> Types = new List <ValueNew>(); List <ValueNew> BugFind = new List <ValueNew>(); List <IterationDetails> iterationsListStore = new List <IterationDetails>(); iterationsListStore = IterationsList(Org.OrganizationName, projectName);//Org.ProjectName); Session["WorkItemscount"] = urlResponse.count; ViewBag.WorkItemscount = urlResponse.count; foreach (var i in urlResponse.value) { if (i.fields.WorkItemType == "Bug" && i.fields.Severity == "1 - Critical") { //BugDetails bugStore=BugDetails(i.id); //if(bugStore.fields.Severity== "1 - Critical") //{ Types.Add(i); // } //&& i.fields.Severity == "1 - Critical" // if (!Types.Contains(i.fields.__invalid_name__SystemWorkItemType)) // Types.Add(i);//.__invalid_name__SystemWorkItemType); } } //string output = JsonConvert.SerializeObject(Types); //return Json(Types, JsonRequestBehavior.AllowGet); //Session["criticalBug"] = Types; return(Types); }