/// <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 IActionResult Create([FromBody] HRWorkItemDataMap newentry) { var result = _repository.Add(newentry); return(Helper.CheckResult(result)); }
public IActionResult Update([FromBody] HRWorkItemDataMap editentry) { var result = _repository.Update(editentry, editentry.HRWorkItemDataMapID); return(Helper.CheckResult(result)); }
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 })); }