private bool ValidateInvestigationData(WorkItemPostData postData, IConfiguration configuration) { JwtSecurityToken HRToken = new JwtSecurityToken(postData.Token); if (Helper.TokenValid(HRToken) == false) { return(false); } if (postData.ModuleTableEntryID == 0) { return(false); } if (postData.ProfileId == "") { return(false); } // Check if HR is up before calling HR routines var hrResponse = Helper.GetHRServerStatus(configuration); // We expect a 400 - Bad Request, if 404 Not Found, return an error if (hrResponse.StatusCode == 404) { return(false); } return(true); }
public void AlertJobsQueueEntity() { IEnumerable <AlertJobFilterData> AlertJobFilterDataItems = Enumerable.Empty <AlertJobFilterData>(); object t = new object(); AlertJobsQueueEntityData data = new AlertJobsQueueEntityData(); AlertJobsQueueEntity dataEntity = new AlertJobsQueueEntity(); AlertJobFilter filter = new AlertJobFilter(); Mock <IAlertJobsQueueEntityRepository> AlertJobsQueueEntityService = new Mock <IAlertJobsQueueEntityRepository>(); Guid guid = new Guid(); IConfiguration config = null; WorkItemPostData wrkitemdata = new WorkItemPostData(); AlertJobsQueueEntityDataSave datasave = new AlertJobsQueueEntityDataSave(); object obj = new object(); try { AlertJobsQueueEntityService.Setup(x => x.GetAlertBatchItems()).Returns(t); AlertJobsQueueEntityService.Setup(x => x.GetFilteredAlertEntities(It.IsAny <AlertJobFilter>())).Returns(AlertJobFilterDataItems); AlertJobsQueueEntityService.Setup(x => x.CheckWorkItemIDForEntity(It.IsAny <WorkItemPostData>(), It.IsAny <IConfiguration>())) .Returns(t); AlertJobsQueueEntityService.Setup(x => x.GetByGuid(It.IsAny <Guid>())).Returns(data); AlertJobsQueueEntityService.Setup(x => x.UpdateEntry(It.IsAny <AlertJobsQueueEntityDataSave>(), It.IsAny <IConfiguration>())) .Returns(dataEntity); var AlertJobsQueueEntityObject = AlertJobsQueueEntityService.Object; var p1 = AlertJobsQueueEntityObject.GetAlertBatchItems(); var p2 = AlertJobsQueueEntityObject.GetFilteredAlertEntities(filter); var p3 = AlertJobsQueueEntityObject.GetByGuid(guid); var p4 = AlertJobsQueueEntityObject.CheckWorkItemIDForEntity(wrkitemdata, config); var p5 = AlertJobsQueueEntityObject.UpdateEntry(datasave, config); Assert.IsAssignableFrom <object>(p1); Assert.IsAssignableFrom <IEnumerable <AlertJobFilterData> >(p2); Assert.IsAssignableFrom <AlertJobsQueueEntityData>(p3); Assert.IsAssignableFrom <object>(p4); Assert.IsAssignableFrom <AlertJobsQueueEntity>(p5); AlertJobsQueueEntityService.VerifyAll(); AlertJobsQueueEntityObject.Dispose(); } finally { AlertJobsQueueEntityService = null; } }
public static async Task UpdateWorkItem(string username, int id) { try { var personalAccessToken = "yggseimvsboxrc3rvodr4dzshnc6cch6shcyavjrqxxbydb6geda"; Console.ReadKey(); //var personalAccessToken = String.Empty; using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String( System.Text.ASCIIEncoding.ASCII.GetBytes( string.Format("{0}:{1}:{2}", username, personalAccessToken, id)))); WorkItemPostData wiPostData = new WorkItemPostData(); wiPostData.op = "replace"; wiPostData.path = "/fields/System.Title"; wiPostData.value = "Employee edits own profile in broser based app"; List <WorkItemPostData> wiPostDataArr = new List <WorkItemPostData> { wiPostData }; string wiPostDataString = JsonConvert.SerializeObject(wiPostDataArr); HttpContent wiPostDataContent = new StringContent(wiPostDataString, Encoding.UTF8, "application/json-patch+json"); //var param = "abc123"; var url = $"https://ndi-tfs.visualstudio.com/Web%20Hook/_apis/wit/workitems/{id}"; //https://ndi-tfs.visualstudio.com/Web%20Hook/_apis/wit/workitems?ids={id}&api-version=5.1 //process the response stream using (HttpResponseMessage response = await client.PatchAsync(url, wiPostDataContent)) { response.EnsureSuccessStatusCode(); string responseBody = await response.Content.ReadAsStringAsync(); Console.WriteLine(responseBody); //const Json = await Json(); } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.WriteLine(ex); } }
private static async void CreateWorkItem(string username, string password) { try { var type = "Product%20Backlog%20Item"; var personalAccessToken = "yggseimvsboxrc3rvodr4dzshnc6cch6shcyavjrqxxbydb6geda"; using (HttpClient client = new HttpClient()) { //if (!ModelState.IsValid) // throw new HttpResponseException(HttpStatusCode.BadRequest); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json-patch+json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String( System.Text.Encoding.ASCII.GetBytes( string.Format("{0}:{1}", username, password)))); WorkItemPostData wiPostData = new WorkItemPostData(); wiPostData.op = "add"; wiPostData.path = "/fields/System.Title"; wiPostData.value = "Employee edits other employees profile"; List <WorkItemPostData> wiPostDataArr = new List <WorkItemPostData> { wiPostData }; string wiPostDataString = JsonConvert.SerializeObject(wiPostDataArr); HttpContent wiPostDataContent = new StringContent(wiPostDataString, Encoding.UTF8, "application/json-patch+json"); string url = $"https://ndi-tfs.visualstudio.com/Web%20Hook/_apis/wit/workitems/${type}"; //"https://ndi-tfs.visualstudio.com/Web%20Hook/_apis/wit/workitems/create/Product%20Backlog%20Item"; using (HttpResponseMessage response = client.PatchAsync(url, wiPostDataContent).Result) { response.EnsureSuccessStatusCode(); string ResponseContent = await response.Content.ReadAsStringAsync(); } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.ReadLine(); } }
private bool ValidateWorkItemData(WorkItemPostData newdata, IConfiguration configuration) { JwtSecurityToken HRToken = new JwtSecurityToken(newdata.Token); if (Helper.TokenValid(HRToken) == false) { return(false); } if (newdata.ModuleTableEntryID == 0) { return(false); } if (newdata.ProfileId == "") { return(false); } if (newdata.Token == "") { return(false); } // Get the Entity Detail from MMMDB, return if not found var EntityDetails = _mmmcontext.Entities.Where(t => t.Ent_ID == Convert.ToInt32(newdata.ProfileId)).FirstOrDefault(); if (EntityDetails == null) { return(false); } // Check if HR is up before calling HR routines ApiWebResponse hrResponse = Helper.GetHRServerStatus(configuration); // We expect a 400 - Bad Request, if 404 Not Found, return an error if (hrResponse.StatusCode == 404) { return(false); } return(true); }
public object CheckWorkItemIDForInvestigationEntity(WorkItemPostData postData, IConfiguration configuration) { bool DataValid = ValidateInvestigationData(postData, configuration); if (DataValid == false) { return(null); } var HRtoken = postData.Token; // check for WorkItemID var InvestigationEntry = _context.Investigation.Where(t => t.InvestigationID == postData.ModuleTableEntryID); if (InvestigationEntry.Count() < 1) { return(null); } //check if there is an existing WorkItem previously defined var DefinedWorkItemGuid = (from inventry in InvestigationEntry where inventry.WorkItemID != null select inventry.WorkItemID).FirstOrDefault().ToString(); int WorkItemCount = 0; Guid GuidToSet; if (DefinedWorkItemGuid != "") { GuidToSet = new Guid(DefinedWorkItemGuid.ToString()); } else { var QueueGuid = (from module in _context.ApplicationModules where module.ModuleName == EditorialModules.Investigations select module.QueueGuid).FirstOrDefault(); var JsonData = JsonConvert.SerializeObject(InvestigationEntry); var QueueGuidString = QueueGuid.ToString(); var HRCreateRequest = Helper.BuildHRWorkItemRequest(EditorialModules.Investigations, QueueGuidString, JsonData, configuration, null, HRRequestMode.Create); var GuidResult = Helper.GetHRWorkItem((WorkItemRequest)HRCreateRequest, HRtoken, configuration); if (GuidResult.Value.workItemGuid == null) { return(null); } GuidToSet = new Guid(GuidResult.Value.workItemGuid); foreach (var investigation in InvestigationEntry) { if (investigation.WorkItemID == null) { WorkItemCount += 1; investigation.WorkItemID = GuidToSet; } } if (WorkItemCount > 0) { _context.SaveChanges(); } } return(new { WorkItemGuid = GuidToSet }); }
public object CheckWorkItemIDForEntity_v1(WorkItemPostData postData, IConfiguration configuration) { bool DataValid = ValidateAlertEntityQueueData(postData, configuration); if (DataValid == false) { return(null); } var token = postData.Token; // check for WorkItemID var AlertEntityEntry = _context.AlertJobsQueueEntity .Where(t => t.AlertNameID == postData.ModuleTableEntryID); //check if there is an existing WorkItemGuid previously defined var DefinedWorkItemGuid = (from alertentityentry in AlertEntityEntry where alertentityentry.WorkItemID != null select alertentityentry.WorkItemID).FirstOrDefault().ToString(); //int WorkItemCount = 0; Guid GuidToSet; if (DefinedWorkItemGuid != "") // Alert Entity has a WorkItemGuid { GuidToSet = new Guid(DefinedWorkItemGuid.ToString()); } else // Perform HR routine and create a WorkItemGuid { var Modules = _context.ApplicationModules; var QueueGuid = (from mods in Modules where mods.ModuleName == EditorialModules.Alerts select mods.QueueGuid).FirstOrDefault(); var QueueGuidString = QueueGuid.ToString(); var JsonData = JsonConvert.SerializeObject(AlertEntityEntry); var HRCreateRequest = Helper.BuildHRWorkItemRequest(EditorialModules.Alerts, QueueGuidString, JsonData, configuration, null, HRRequestMode.Create); var returnGuid = Helper.GetHRWorkItem((WorkItemRequest)HRCreateRequest, token, configuration); if (returnGuid.Value.workItemGuid == null) { return(null); } GuidToSet = new Guid(returnGuid.Value.workItemGuid); // add an entry to the mapping table [AlertJobsQueueEntity] AlertJobsQueueEntity NewAlertJobsQueueEntity = new AlertJobsQueueEntity { AlertNameID = postData.ModuleTableEntryID, WorkItemID = GuidToSet, AlertJobsQueueID = 0, // not used for now StatusID = 0, // not used for now DateCreatedUTC = DateTime.UtcNow, LastUpdatedUTC = DateTime.UtcNow, CreatedBy = postData.Appuserid.ToString(), UpdatedBy = postData.Appuserid.ToString() }; _context.AlertJobsQueueEntity.Add(NewAlertJobsQueueEntity); _context.SaveChanges(); } return(new { WorkItemGuid = GuidToSet }); }
public object CheckWorkItemIDForEntity(WorkItemPostData postData, IConfiguration configuration) { bool DataValid = ValidateAlertEntityQueueData(postData, configuration); if (DataValid == false) { return(null); } var token = postData.Token; // check for WorkItemID var AlertEntityEntry = _context.AlertJobsQueueEntity .Where(t => t.AlertJobsQueueEntityID == postData.ModuleTableEntryID); if (AlertEntityEntry.Count() < 1) { return(null); } //check if there is an existing WorkItemGuid previously defined var DefinedWorkItemGuid = (from alertentityentry in AlertEntityEntry where alertentityentry.WorkItemID != null select alertentityentry.WorkItemID).FirstOrDefault().ToString(); int WorkItemCount = 0; Guid GuidToSet; if (DefinedWorkItemGuid != "") // Alert Entity has a WorkItemGuid { GuidToSet = new Guid(DefinedWorkItemGuid.ToString()); } else // Perform HR routine and create a WorkItemGuid { var Modules = _context.ApplicationModules; var QueueGuid = (from mods in Modules where mods.ModuleName == EditorialModules.Alerts select mods.QueueGuid).FirstOrDefault(); var QueueGuidString = QueueGuid.ToString(); var JsonData = JsonConvert.SerializeObject(AlertEntityEntry); var HRCreateRequest = Helper.BuildHRWorkItemRequest(EditorialModules.Alerts, QueueGuidString, JsonData, configuration, null, HRRequestMode.Create); var returnGuid = Helper.GetHRWorkItem((WorkItemRequest)HRCreateRequest, token, configuration); if (returnGuid.Value.workItemGuid == null) { return(null); } GuidToSet = new Guid(returnGuid.Value.workItemGuid); } foreach (var alertentityentry in AlertEntityEntry) { if (alertentityentry.WorkItemID == null) { WorkItemCount += 1; alertentityentry.WorkItemID = GuidToSet; } } if (WorkItemCount > 0) { _context.SaveChanges(); } return(new { WorkItemGuid = GuidToSet }); }
public JsonResult CheckWorkItemIDForEntity([FromBody] WorkItemPostData postData) { if (!ModelState.IsValid) { var badrequest = new { Success = false, Message = "Error in Input" }; return(Json(badrequest)); } var Message = ""; if (postData.ModuleTableEntryID == 0) { Message = "No BWQ Entity given"; return(Json(Message)); } if (postData.ProfileId == "") { Message = "No Profile given"; return(Json(Message)); } if (postData.token == "") { Message = "No token given"; return(Json(Message)); } // Check if HR is up var hruri = _configuration.GetSection("HumanReview:uri").Value + "auth/token"; var hrResponse = Common.ServerStatusBy(hruri); // We expect a 400 - Bad Request, anything else specifically 404 Not Found, return an error if (hrResponse.StatusCode == 404) { { return(Json("Error: Human Review Service unavailable")); } } var token = postData.token; // check for WorkItemID var BwqEntity = _context.BWQEntities.Where(t => t.BWQEntitiesID == postData.ModuleTableEntryID); //check if there is an existing WorkItem previously defined var DefinedWorkItemGuid = (from bwqents in BwqEntity where bwqents.WorkItemID != null select bwqents.WorkItemID).FirstOrDefault().ToString(); // Get the Entity Detail from MMM, return if not found var EntityDetails = _mmmcontext.Entities.Where(t => t.Ent_ID == Convert.ToInt32(postData.ProfileId)).FirstOrDefault(); if (EntityDetails == null) { var notfound = new { Success = false, Message = "Profile not found in Profile Database" }; return(Json(notfound)); } int WorkItemCount = 0; ReturnData retValue; Guid GuidToSet; if (DefinedWorkItemGuid != "") { GuidToSet = new Guid(DefinedWorkItemGuid.ToString()); } else { var Modules = _context.ApplicationModules; var QueueGuid = (from mods in Modules where mods.ModuleName == "BWQ" select mods.QueueGuid).FirstOrDefault(); var BWQEntityInstructions = _context.BWQInstructions.Where(t => t.BWQEntitiesID == postData.ModuleTableEntryID); var JsonData = JsonConvert.SerializeObject(BWQEntityInstructions); WorkItemRequest req = new WorkItemRequest(); req.name = "Work Item ID entry for BWQ Entity " + postData.ModuleTableEntryID + " and Profile " + postData.ProfileId; req.description = "Work Item ID entry for BWQ Entity " + postData.ModuleTableEntryID + " and Profile " + postData.ProfileId; req.queueGuid = QueueGuid; req.statusDetailTypeGuid = _configuration.GetSection("HumanReview:statusDetailTypeGuid_ins").Value; req.reviewTypeGuid = _configuration.GetSection("HumanReview:reviewTypeGuid_ins").Value; req.formDefinitionJson = JsonData; req.isActive = true; var returnGuid = Common.getWorkItemAsync(req, token, _configuration); // workitem here if (returnGuid.value.workItemGuid == null) { var workitemnotcreated = new { Success = false, Message = "WorkItem not created" }; return(Json(workitemnotcreated)); // TODO: LOG THIS ERROR } GuidToSet = new Guid(returnGuid.value.workItemGuid); } foreach (var ent in BwqEntity) { if (ent.WorkItemID == null) { WorkItemCount += 1; // Set workitemGuid ent.WorkItemID = GuidToSet; } } if (WorkItemCount > 0) { retValue = _context.SaveData(); if (retValue.Message != "Success") { return(Json(retValue)); } // return error if workitemid was not updated for this bwq entity } return(Json(new { WorkItemGuid = GuidToSet })); }
/// <summary> /// Gets / Sets a workitem ID entry for a news Entity /// </summary> /// <param name="postData"></param> /// <param name="configuration"></param> /// <returns></returns> public object CheckNewsWorkItemID(WorkItemPostData postData, IConfiguration configuration) { bool DataValid = ValidateNewsData(postData, configuration); if (DataValid == false) { return(null); } var HRtoken = postData.Token; var NewsEntry = _newsfeedcontext.FeedItemQueue.Where(t => t.id == postData.ModuleTableEntryID).FirstOrDefault(); if (NewsEntry == null) { return(null); } Guid GuidToSet; // check for WorkItemID var MappingEntry = _context.HRWorkItemDataMap.Where(t => t.ModuleTableEntryID == postData.ModuleTableEntryID).FirstOrDefault(); var DefinedWorkItemGuid = ""; if (MappingEntry != null) { DefinedWorkItemGuid = MappingEntry.WorkItemID.ToString(); } if (DefinedWorkItemGuid != "") { GuidToSet = new Guid(DefinedWorkItemGuid.ToString()); } else { var QueueGuid = (from module in _context.ApplicationModules where module.ModuleName == EditorialModules.News select module.QueueGuid).FirstOrDefault(); var JsonData = JsonConvert.SerializeObject(NewsEntry); var QueueGuidString = QueueGuid.ToString(); var HRCreateRequest = Helper.BuildHRWorkItemRequest(EditorialModules.News, QueueGuidString, JsonData, configuration, null, HRRequestMode.Create); var GuidResult = Helper.GetHRWorkItem((WorkItemRequest)HRCreateRequest, HRtoken, configuration); if (GuidResult.Value.workItemGuid == null) { return(null); } GuidToSet = new Guid(GuidResult.Value.workItemGuid); if (MappingEntry == null) // No Entry in HR WorkItemGuid table, insert one { var newDataMap = new HRWorkItemDataMap { WorkUnitTypeID = 5, // Module type /* * 3 Investigation * 4 Alerts * 5 News Queue * 6 BWQ */ // Row ID in Module table, in this case id column of NewsFeed..FeedItemQueue ModuleTableEntryID = postData.ModuleTableEntryID, WorkItemID = GuidToSet, //HR WorkItem GUID UpdatedBy = postData.Appuserid.ToString(), CreatedBy = postData.Appuserid.ToString(), DateCreatedUTC = DateTime.UtcNow, LastUpdatedUTC = DateTime.UtcNow }; _context.HRWorkItemDataMap.Add(newDataMap); _context.SaveChanges(); } } return(new { WorkItemGuid = GuidToSet }); }
public JsonResult CheckWorkItemID([FromBody] WorkItemPostData postData) { if (!ModelState.IsValid) { var badrequest = new { Success = false, Message = "Error in Input" }; return(Json(badrequest)); } // Check if HR is up var hruri = _configuration.GetSection("HumanReview:uri").Value + "auth/token"; var hrResponse = Common.ServerStatusBy(hruri); // We expect a 400 - Bad Request, anything else specifically 404 Not Found, return an error if (hrResponse.StatusCode == 404) { { return(Json("Error: Human Review Service unavailable")); } } var Message = ""; if (postData.ModuleTableEntryID == 0) { Message = "No News Entry given"; return(Json(Message)); } if (postData.token == "") { Message = "No token given"; return(Json(Message)); } var token = postData.token; // check if News Entry exists var NewsEntry = _NewsDBcontext.FeedItemQueue.Where(t => t.id == postData.ModuleTableEntryID).FirstOrDefault(); if (NewsEntry == null) { Message = "News Entry does not exist"; return(Json(Message)); } // check for WorkItemID var MappingEntry = _context.HRWorkItemDataMap.Where(t => t.ModuleTableEntryID == postData.ModuleTableEntryID).FirstOrDefault(); //check if there is an existing WorkItem previously defined var DefinedWorkItemGuid = ""; if (MappingEntry != null) { DefinedWorkItemGuid = MappingEntry.WorkItemID.ToString(); } ReturnData retValue; Guid GuidToSet; if (DefinedWorkItemGuid != "") { GuidToSet = new Guid(DefinedWorkItemGuid.ToString()); } else { var Modules = _context.ApplicationModules; var QueueGuid = (from mods in Modules where mods.ModuleName == "News Queue" select mods.QueueGuid).FirstOrDefault(); var JsonData = JsonConvert.SerializeObject(NewsEntry); WorkItemRequest req = new WorkItemRequest(); req.name = "Work Item ID entry for News Entry " + postData.ModuleTableEntryID; req.description = "Work Item ID entry for News Entry " + postData.ModuleTableEntryID; req.queueGuid = QueueGuid; req.statusDetailTypeGuid = _configuration.GetSection("HumanReview:statusDetailTypeGuid_ins").Value; req.reviewTypeGuid = _configuration.GetSection("HumanReview:reviewTypeGuid_ins").Value; req.formDefinitionJson = JsonData; req.isActive = true; var returnGuid = Common.getWorkItemAsync(req, token, _configuration); if (returnGuid.value.workItemGuid == null) { var workitemnotcreated = new { Success = false, Message = "WorkItem not created" }; return(Json(workitemnotcreated)); // TODO: LOG THIS ERROR } GuidToSet = new Guid(returnGuid.value.workItemGuid); } if (MappingEntry == null) // No Entry in HR WorkItemGuid table, insert one { var newDataMap = new HRWorkItemDataMap(); newDataMap.WorkUnitTypeID = 5; // Module type /* * 3 Investigation * 4 Alerts * 5 News Queue * 6 BWQ */ // Row ID in Module table, in this case id column of NewsFeed..FeedItemQueue newDataMap.ModuleTableEntryID = postData.ModuleTableEntryID; newDataMap.WorkItemID = GuidToSet; //HR WorkItem GUID newDataMap.UpdatedBy = postData.appuserid.ToString(); newDataMap.CreatedBy = postData.appuserid.ToString(); newDataMap.DateCreatedUTC = DateTime.UtcNow; newDataMap.LastUpdatedUTC = DateTime.UtcNow; _context.HRWorkItemDataMap.Add(newDataMap); retValue = _context.SaveData(); if (retValue.Message != "Success") { return(Json(retValue)); } } return(Json(new { WorkItemGuid = GuidToSet })); }
/// <summary> /// /// </summary> /// <param name="wrkItemData"></param> /// <param name="configuration"></param> /// <returns></returns> public object GetWorkItemID(WorkItemPostData wrkItemData, IConfiguration configuration) { bool DataValid = ValidateWorkItemData(wrkItemData, configuration); if (DataValid == false) { return(null); } string HRtoken = wrkItemData.Token; int TableEntryId = wrkItemData.ModuleTableEntryID; // Get the BWQ Entity entry var BwqEntity = _context.BWQEntities.Where(t => t.BWQEntitiesID == TableEntryId); if (BwqEntity.Count() < 1) { return(null); } //Get the Guid if its defined var DefinedWorkItemGuid = (from bwqents in BwqEntity where bwqents.WorkItemID != null select bwqents.WorkItemID).FirstOrDefault().ToString(); int WorkItemCount = 0; Guid GuidToSet; if (DefinedWorkItemGuid != "") { GuidToSet = new Guid(DefinedWorkItemGuid.ToString()); } else { var QueueGuid = (from module in _context.ApplicationModules where module.ModuleName == EditorialModules.BWQ select module.QueueGuid).FirstOrDefault(); var BWQEntityInstructions = _context.BWQInstructions.Where(t => t.BWQEntitiesID == TableEntryId); if (BWQEntityInstructions.Count() < 1) { return(null); } var JsonData = JsonConvert.SerializeObject(BWQEntityInstructions); var QueueGuidString = QueueGuid.ToString(); // This Section calls Human Review to Create the Workitem GUid for this Instruction entry var HRCreateRequest = Helper.BuildHRWorkItemRequest(EditorialModules.BWQ, QueueGuidString, JsonData, configuration, null, HRRequestMode.Create); var GuidResult = Helper.GetHRWorkItem((WorkItemRequest)HRCreateRequest, HRtoken, configuration); if (GuidResult.Value.workItemGuid == null) { return(null); } GuidToSet = new Guid(GuidResult.Value.workItemGuid); } foreach (var ent in BwqEntity) { if (ent.WorkItemID == null) { WorkItemCount += 1; ent.WorkItemID = GuidToSet; } } if (WorkItemCount > 0) { _context.SaveChanges(); } return(new { WorkItemGuid = GuidToSet }); }
public IActionResult CheckWorkItemIDForInvestigationEntity([FromBody] WorkItemPostData postData) { var result = _repository.CheckWorkItemIDForInvestigationEntity(postData, _configuration); return(Helper.CheckResult(result)); }
public JsonResult GetInstructionsByEntity([FromBody] WorkItemPostData postData) { var Message = ""; if (postData.ModuleTableEntryID == 0) { Message = "No BWQ Entity given"; return(Json(Message)); } if (postData.ProfileId == "") { Message = "No Profile given"; return(Json(Message)); } if (postData.token == "") { Message = "No token given"; return(Json(Message)); } var BwqEntities = _context.BWQEntities.Where(t => t.BWQEntitiesID == postData.ModuleTableEntryID); //var token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJocmV2dXNlcjIiLCJzaWQiOiI4OTI4MjkyNzI4MjI4MjgyODcxMDIiLCJqdGkiOiJmYzliODk5Ny0wZTM4LTQwMjUtYTlmYy04OTY2OWY2MDhmMDkiLCJyb2wiOlt7ImlzYWRtIjp0cnVlLCJybmFtZSI6ImhyLWFkbWluIiwiZ3JwIjpbeyJnbmFtZSI6IkhSV0NPSk9CIn1dfV0sImRtbl9hZG0iOlt7ImRuYW1lIjoiYWRmNDgxOGItYzQxYy00ZjZhLTg1NjAtM2U0NjQxNWQyYzkzIn1dLCJpcHMiOlsiMTI3LjAuMC4xLzEyNy4wLjAuMSJdLCJleHAiOjE1MzkwODk3NjAsImlzcyI6Imh0dHA6Ly9odW1hbnJldmlldy5hcGkucmlzay5sZXhpc25leGlzLmNvbSIsImF1ZCI6Imh0dHA6Ly9odW1hbnJldmlldy5yaXNrLmxleGlzbmV4aXMuY29tIn0.D0JIe7CWT53Lmzfz3BsPzdSHWdDnK-cXxDj7TYdS3SI"; var token = postData.token; var Modules = _context.ApplicationModules; var QueueGuid = (from mods in Modules where mods.ModuleName == "BWQ" select mods.QueueGuid).FirstOrDefault(); //Queue Guid "D673666A-C99A-4219-9378-032B15FD0C08" ReturnData retValue; int WorkItemCount = 0; foreach (var ent in BwqEntities) { if (ent.WorkItemID == null) { WorkItemCount += 1; var BWQEntityInstructions = _context.BWQInstructions.Where(t => t.BWQEntitiesID == ent.BWQEntitiesID); var JsonData = JsonConvert.SerializeObject(BWQEntityInstructions); WorkItemRequest req = new WorkItemRequest(); req.name = "Work Item ID entry for " + postData.ModuleTableEntryID + " and Profile " + postData.ProfileId; req.description = "Work Item ID entry for BWQ Entity " + postData.ModuleTableEntryID + " and Profile " + postData.ProfileId; req.queueGuid = QueueGuid; req.statusDetailTypeGuid = _configuration.GetSection("HumanReview:statusDetailTypeGuid_upd").Value;; req.reviewTypeGuid = _configuration.GetSection("HumanReview:reviewTypeGuid_upd").Value;; req.formDefinitionJson = JsonData; req.isActive = true; var returnGuid = postWorkItemForEntityAsync(req, token); // workitem here if (returnGuid.value.workItemGuid != null) { ent.WorkItemID = new Guid(returnGuid.value.workItemGuid); } } } if (WorkItemCount > 0) { retValue = _context.SaveData(); if (retValue.Message != "Success") { return(Json(retValue)); } // return error if workitemid was not updated for this bwq entity } var ret = from ins in _context.BWQInstructions join ents in _context.BWQEntities on ins.BWQEntitiesID equals ents.BWQEntitiesID join bwqs in _context.BWQ on ents.BWQID equals bwqs.BWQID join bwqf in _context.BWQFieldSelect on ins.BWQFieldSelectID equals bwqf.BWQFieldSelectID where ents.BWQEntitiesID == postData.ModuleTableEntryID select new { BWQInstructionsID = ins.BWQInstructionsID, BWQDispositionsID = ins.BWQDispositionsID, BWQEntitiesID = ins.BWQEntitiesID, BWQFieldSelectID = ins.BWQFieldSelectID, BWQDispositions = ins.BWQDispositions, //BWQEntities = ins.BWQEntities, //BWQFieldSelect = ins.BWQFieldSelect, Instructions = ins.Instructions, CreatedBy = ins.CreatedBy, DateCreatedUTC = ins.DateCreatedUTC, UpdatedBy = ins.UpdatedBy, LastUpdatedUTC = ins.LastUpdatedUTC, BatchName = bwqs.BatchName, WorkItemId = ents.WorkItemID, Item = bwqf.FieldDisplayName }; if (ret.Count() < 1) { { Message = "Instructions not found for BWQ Entity " + postData.ModuleTableEntryID; return(Json(Message)); } } return(Json(ret)); }
public IActionResult GetWorkItemID([FromBody] WorkItemPostData wrkItemData) { object result = _repository.GetWorkItemID(wrkItemData, _configuration); return(Helper.CheckResult(result)); }
public IActionResult CheckNewsWorkItemID([FromBody] WorkItemPostData postData) { object data = _repository.CheckNewsWorkItemID(postData, _configuration); return(Helper.CheckResult(data)); }
public IActionResult CheckWorkItemIDForEntity_v1([FromBody] WorkItemPostData postData) { var data = _repository.CheckWorkItemIDForEntity_v1(postData, _configuration); return(Helper.CheckResult(data)); }
public JsonResult CheckWorkItemIDForEntity([FromBody] WorkItemPostData postData) { if (!ModelState.IsValid) { var badrequest = new { Success = false, Message = "Error in Input" }; return(Json(badrequest)); } // Check if HR is up var hruri = _configuration.GetSection("HumanReview:uri").Value + "auth/token"; var hrResponse = Common.ServerStatusBy(hruri); // We expect a 400 - Bad Request, anything else specifically 404 Not Found, return an error if (hrResponse.StatusCode == 404) { { return(Json("Error: Human Review Service unavailable")); } } var Message = ""; if (postData.ModuleTableEntryID == 0) { Message = "No Alert Entry given"; return(Json(Message)); } if (postData.token == "") { Message = "No token given"; return(Json(Message)); } var token = postData.token; // check for WorkItemID var AlertEntityEntry = _context.AlertJobsQueueEntity .Where(t => t.AlertJobsQueueEntityID == postData.ModuleTableEntryID); //check if there is an existing WorkItem previously defined var DefinedWorkItemGuid = (from alertentityentry in AlertEntityEntry where alertentityentry.WorkItemID != null select alertentityentry.WorkItemID).FirstOrDefault().ToString(); int WorkItemCount = 0; ReturnData retValue; Guid GuidToSet; if (DefinedWorkItemGuid != "") { GuidToSet = new Guid(DefinedWorkItemGuid.ToString()); } else { var Modules = _context.ApplicationModules; var QueueGuid = (from mods in Modules where mods.ModuleName == "Alerts" select mods.QueueGuid).FirstOrDefault(); var JsonData = JsonConvert.SerializeObject(AlertEntityEntry); WorkItemRequest req = new WorkItemRequest(); req.name = "Created WorkItem for Alert Entity " + postData.ModuleTableEntryID; req.description = "Created WorkItem for Alert Entity " + postData.ModuleTableEntryID; req.queueGuid = QueueGuid; req.statusDetailTypeGuid = _configuration.GetSection("HumanReview:statusDetailTypeGuid_ins").Value; req.reviewTypeGuid = _configuration.GetSection("HumanReview:reviewTypeGuid_ins").Value; req.formDefinitionJson = JsonData; req.isActive = true; var returnGuid = Common.getWorkItemAsync(req, token, _configuration); // workitem here if (returnGuid.value.workItemGuid == null) { var workitemnotcreated = new { Success = false, Message = "WorkItem not created" }; return(Json(workitemnotcreated)); // TODO: LOG THIS ERROR } GuidToSet = new Guid(returnGuid.value.workItemGuid); } foreach (var alertentityentry in AlertEntityEntry) { if (alertentityentry.WorkItemID == null) { WorkItemCount += 1; alertentityentry.WorkItemID = GuidToSet; } } if (WorkItemCount > 0) { retValue = _context.SaveData(); if (retValue.Message != "Success") { return(Json(retValue)); } } return(Json(new { WorkItemGuid = GuidToSet })); }