public IActionResult Update([FromBody] BWQInstructionsData editentry) { var result = _repository.UpdateInstruction(editentry, _configuration); if (result == null) { return(Helper.CheckResult(result, false, true)); } else { return(Helper.CheckResult(result)); } }
public void BWQInstructions() { IQueryable <BWQInstructions> BWQInstructionsBWQInstructions = Enumerable.Empty <BWQInstructions>().AsQueryable(); BWQInstructions ct = new BWQInstructions { BWQInstructionsID = 1, CreatedBy = "Test BWQInstructions" }; Mock <IBWQInstructionsRepository> BWQInstructionsService = new Mock <IBWQInstructionsRepository>(); BWQInstructionsData binsdata = new BWQInstructionsData(); IConfiguration configuration = null; try { BWQInstructionsService.Setup(x => x.GetAll()).Returns(BWQInstructionsBWQInstructions); BWQInstructionsService.Setup(x => x.Get(It.IsAny <int>())).Returns(ct); BWQInstructionsService.Setup(x => x.Add(It.IsAny <BWQInstructions>())).Returns(ct); BWQInstructionsService.Setup(x => x.Delete(It.IsAny <BWQInstructions>())).Verifiable(); BWQInstructionsService.Setup(x => x.UpdateInstruction(It.IsAny <BWQInstructionsData>(), It.IsAny <IConfiguration>())).Returns(ct); var BWQInstructionsObject = BWQInstructionsService.Object; var p1 = BWQInstructionsObject.GetAll(); var p2 = BWQInstructionsObject.Get(1); var p3 = BWQInstructionsObject.UpdateInstruction(binsdata, configuration); var p4 = BWQInstructionsObject.Add(ct); BWQInstructionsObject.Delete(ct); Assert.IsAssignableFrom <IQueryable <BWQInstructions> >(p1); Assert.IsAssignableFrom <BWQInstructions>(p2); Assert.Equal("Test BWQInstructions", p2.CreatedBy); Assert.IsAssignableFrom <object>(p3); BWQInstructionsService.VerifyAll(); BWQInstructionsObject.Dispose(); } finally { BWQInstructionsService = null; } }
private bool ValidateBatchInstruction(BWQInstructionsData newdata, IConfiguration configuration) { var HRToken = new JwtSecurityToken(newdata.HRToken); if (Helper.TokenValid(HRToken) == false) { return(false); } if (newdata.instructions.Count() < 1) { 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 object UpdateInstruction(BWQInstructionsData editentry, IConfiguration configuration) { bool DataValid = ValidateBatchInstruction(editentry, configuration); if (DataValid == false) { return(null); } int BWQEntityID = 0; int MMMProfileID = 0; string WorkItemGuid = ""; #region Editorial section foreach (var updateobj in editentry.instructions) { var targetObject = _context.BWQInstructions.FirstOrDefault(t => t.BWQInstructionsID == updateobj.BWQInstructionsID); //check if instruction exists if (targetObject == null) { return(null); } //Instruction disposition can only be 2, "Open" fail otherwise if (!(targetObject.BWQDispositionsID == 2)) { return(null); } var BWQEntity = _context.BWQEntities.FirstOrDefault(u => u.BWQEntitiesID == targetObject.BWQEntitiesID); if (BWQEntity == null) { return(null); } // TODO check the lock table if its still valid // WorkUnitTypeID == 6 is BWQ var thislock = _context.RecordLocks .Where(v => v.WorkUnitTypeID == 6 && v.IDFromWorkUnitsDBTable == BWQEntity.BWQEntitiesID); foreach (var locks in thislock) { if (locks.AppUserID != Convert.ToInt32(updateobj.UpdatedBy)) // record lock found for another user { var lockedToUser = _context.AppUser.FirstOrDefault(u => u.AppUserID == Convert.ToInt32(updateobj.UpdatedBy)); return(null); } if (locks != null) // no locks { _context.RecordLocks.Remove(locks); } } // Save Instruction _context.Entry(targetObject).CurrentValues.SetValues(updateobj); BWQEntityID = BWQEntity.BWQEntitiesID; MMMProfileID = BWQEntity.MMMEntityID; WorkItemGuid = BWQEntity.WorkItemID.ToString(); if (WorkItemGuid == "") { return(null); } } _context.SaveChanges(); // Save Editorial data #endregion #region Human Review Data var QueueGuid = (from module in _context.ApplicationModules where module.ModuleName == EditorialModules.BWQ select module.QueueGuid).FirstOrDefault(); var QueueGuidString = QueueGuid.ToString(); var JsonData = JsonConvert.SerializeObject(editentry.instructions); var HRCreateRequest = Helper.BuildHRWorkItemRequest(EditorialModules.BWQ, QueueGuidString, JsonData, configuration, WorkItemGuid, HRRequestMode.Update); var GuidResult = Helper.PutHRWorkItem((WorkItemPutRequest)HRCreateRequest, editentry.HRToken, configuration); #endregion return(editentry.instructions); }
public IActionResult UpdateEntry([FromBody] BWQInstructionsData objupd) { // Check if HR is up var hruri = _configuration.GetSection("HumanReview:uri").Value + "auth/token"; var hrResponse = Common.ServerStatusBy(hruri); // 400 - Not Found // 401 - Unauthorized (unlikely) // 404 - Bad Request // We expect a 400 - Bad Request, anything else specifically 404 Not Found, return an error if (hrResponse.StatusCode == 404) { { return(NotFound("Human Review Service Not Found")); } } int BWQEntityID = 0; int MMMProfileID = 0; string workItemGuid = ""; ReturnData ret; // Update the Editorial Data #region Save Editorial data foreach (var updateobj in objupd.instructions) { var targetObject = _context.BWQInstructions.FirstOrDefault(t => t.BWQInstructionsID == updateobj.BWQInstructionsID); if (targetObject == null) { return(NotFound("BWQ Instruction not found")); } var BWQEntity = _context.BWQEntities.FirstOrDefault(u => u.BWQEntitiesID == targetObject.BWQEntitiesID); if (BWQEntity == null) { return(NotFound("No BWQ Entity found for this BWQ Instruction")); } // TODO check the lock table if its still valid // WorkUnitTypeID == 6 is BWQ var thislock = _context.RecordLocks .Where(v => v.WorkUnitTypeID == 6 && v.IDFromWorkUnitsDBTable == BWQEntity.BWQEntitiesID); //&& v.AppUserID == Convert.ToInt32(targetObject.UpdatedBy) foreach (var locks in thislock) { if (locks.AppUserID != Convert.ToInt32(updateobj.UpdatedBy)) // record lock found for another user { var lockedToUser = _context.AppUser.FirstOrDefault(u => u.AppUserID == Convert.ToInt32(updateobj.UpdatedBy)); return(BadRequest("BWQ Instruction locked to: " + lockedToUser.AppUserName)); } if (locks != null) // no locks { _context.RecordLocks.Remove(locks); } } // Save Instruction _context.Entry(targetObject).CurrentValues.SetValues(updateobj); BWQEntityID = BWQEntity.BWQEntitiesID; MMMProfileID = BWQEntity.MMMEntityID; workItemGuid = BWQEntity.WorkItemID.ToString(); if (workItemGuid == "") { return(NotFound("No WorkItem Found for instruction " + BWQEntityID)); } } ret = _context.SaveData(); // Save Editorial data if (ret.Message != "Success") { return(Json(ret)); } #endregion #region Update HR Data try { var Modules = _context.ApplicationModules; var QueueGuid = (from mods in Modules where mods.ModuleName == "BWQ" select mods.QueueGuid).FirstOrDefault(); var JsonData = JsonConvert.SerializeObject(objupd.instructions); WorkItemPutRequest HRPutRequest = new WorkItemPutRequest(); HRPutRequest.isActive = true; HRPutRequest.name = "Updating Entries for BWQ Entity " + BWQEntityID + " and Profile ID " + MMMProfileID; HRPutRequest.description = "Updating Entries for BWQ Entity " + BWQEntityID + " and Profile " + MMMProfileID; HRPutRequest.queueGuid = QueueGuid; HRPutRequest.statusDetailTypeGuid = _configuration.GetSection("HumanReview:statusDetailTypeGuid_upd").Value; HRPutRequest.reviewTypeGuid = _configuration.GetSection("HumanReview:reviewTypeGuid_upd").Value; HRPutRequest.formDefinitionJson = JsonData; HRPutRequest.workitemGuid = workItemGuid; var returnDataFromHR = putWorkItemForEntityAsync(HRPutRequest, objupd.HRToken); } catch (Exception e) { var LogInfo = e.Message; } #endregion if (ret.Message == "Success") { return(Ok()); } return(NotFound(ret)); }