示例#1
0
        public InvestigationActivity AddInvestigationActivity(InvestigationDataSave investigationactivity)
        {
            var investigationEntry = investigationactivity.Investigation;

            var targetinvestigationEntry = _context.Investigation.FirstOrDefault(t => t.InvestigationID == investigationEntry.InvestigationID);

            if (targetinvestigationEntry == null)
            {
                return(null);
            }

            int ActivityTypeValue = 0;

            if (investigationEntry.PriorityTypeID != targetinvestigationEntry.PriorityTypeID)                                // Priority change
            {
                ActivityTypeValue = 5;                                                                                       // Priority type, table [ActivityType]
            }
            else if (investigationEntry.CountryID != targetinvestigationEntry.CountryID)                                     // Country change
            {
                ActivityTypeValue = 3;                                                                                       // Country Type, table [ActivityType]
            }
            else if (investigationEntry.InvestigationStatusID != targetinvestigationEntry.InvestigationStatusID)             // Status change
            {
                ActivityTypeValue = 2;                                                                                       // Status Type, table [ActivityType]
            }
            else if (investigationEntry.FunctionTypeID != targetinvestigationEntry.FunctionTypeID)                           // Category change
            {
                ActivityTypeValue = 7;                                                                                       // Category Type, table [ActivityType]
            }
            else if (investigationEntry.InvestigationDispositionsID != targetinvestigationEntry.InvestigationDispositionsID) // Disposition change
            {
                ActivityTypeValue = 6;                                                                                       // Disposition Type, table [ActivityType]
            }
            else
            {
                return(null);
            }

            InvestigationActivity newActivity = new InvestigationActivity
            {
                AppUserID      = Convert.ToInt32(investigationEntry.UpdatedBy),
                CreatedBy      = investigationEntry.UpdatedBy,
                DateCreatedUTC = DateTime.UtcNow,
                UpdatedBy      = investigationEntry.UpdatedBy,
                LastUpdatedUTC = DateTime.UtcNow,

                InvestigationID = targetinvestigationEntry.InvestigationID,
                FromValue       = investigationEntry.PriorityTypeID.ToString(),
                ToValue         = targetinvestigationEntry.PriorityTypeID.ToString(),

                ActivityTypeID = ActivityTypeValue
            };

            _context.InvestigationActivity.Add(newActivity);
            _context.SaveChanges();

            return(newActivity);
        }
示例#2
0
        public IActionResult Update([FromBody] InvestigationDataSave investigationdata)
        {
            var result = _repository.UpdateInvestigationEntity(investigationdata, _configuration);

            if (result == null)
            {
                return(Helper.CheckResult(result, false, true));
            }
            else
            {
                return(Helper.CheckResult(result));
            }
        }
示例#3
0
        private bool ValidateInvestigationEntity(InvestigationDataSave investigationdata, IConfiguration configuration)
        {
            JwtSecurityToken HRToken = new JwtSecurityToken(investigationdata.HRToken);

            if (Helper.TokenValid(HRToken) == false)
            {
                return(false);
            }
            if (investigationdata.Investigation == null)
            {
                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);
        }
示例#4
0
        public object UpdateInvestigationEntity(InvestigationDataSave investigationdata, IConfiguration configuration)
        {
            bool DataValid = ValidateInvestigationEntity(investigationdata, configuration);

            if (DataValid == false)
            {
                return(null);
            }

            var InvestigationDataUpdateEntry = investigationdata.Investigation;

            var InvestigationDataEntry = _context.Investigation.FirstOrDefault(t => t.InvestigationID == InvestigationDataUpdateEntry.InvestigationID);

            if (InvestigationDataEntry == null)
            {
                return(null);
            }

            /*
             * 3	Investigation
             * 4	Alerts
             * 5	News Queue
             * 6	BWQ
             */
            var Locks = _context.RecordLocks
                        .Where(v => v.WorkUnitTypeID == 3 && v.IDFromWorkUnitsDBTable == InvestigationDataUpdateEntry.InvestigationID);

            foreach (var lockeentry in Locks)
            {
                if (lockeentry.AppUserID != Convert.ToInt32(InvestigationDataUpdateEntry.UpdatedBy)) // record lock found for another user
                {
                    return(null);
                }

                if (lockeentry != null)
                {
                    _context.RecordLocks.Remove(lockeentry);
                }
            }

            // Update the Editorial data

            var InvestigationID = InvestigationDataUpdateEntry.InvestigationID;
            var MMMProfileID    = InvestigationDataUpdateEntry.EntityName;
            var WorkItemGuid    = InvestigationDataUpdateEntry.WorkItemID.ToString();

            _context.Entry(InvestigationDataEntry).CurrentValues.SetValues(InvestigationDataUpdateEntry);

            // Save Notes
            if (investigationdata.InvestigationNote != null)
            {
                _context.InvestigationNote.Add(investigationdata.InvestigationNote);
            }

            _context.SaveChanges();

            // Human Review routines

            var QueueGuid = (from module in _context.ApplicationModules
                             where module.ModuleName == EditorialModules.Investigations
                             select module.QueueGuid).FirstOrDefault();

            var QueueGuidString = QueueGuid.ToString();

            var JsonData = JsonConvert.SerializeObject(InvestigationDataUpdateEntry);

            var HRCreateRequest = Helper.BuildHRWorkItemRequest(EditorialModules.Investigations,
                                                                QueueGuidString, JsonData,
                                                                configuration, WorkItemGuid, HRRequestMode.Update);

            var GuidResult = Helper.PutHRWorkItem((WorkItemPutRequest)HRCreateRequest, investigationdata.HRToken, configuration);


            return(InvestigationDataUpdateEntry);
        }
示例#5
0
        public IActionResult AddActivity([FromBody] InvestigationDataSave objupdobj)
        {
            var objupd = objupdobj.Investigation;

            var targetObject = _context.Investigation.FirstOrDefault(t => t.InvestigationID == objupd.InvestigationID);

            if (targetObject == null)
            {
                return(NotFound());
            }

            List <InvestigationActivity> Activities = new List <InvestigationActivity>();

            bool hasChanges = false;

            if (objupd.PriorityTypeID != targetObject.PriorityTypeID) // Priority change
            {
                var newActivity = new InvestigationActivity();
                newActivity.AppUserID      = Convert.ToInt32(objupd.UpdatedBy);
                newActivity.CreatedBy      = objupd.UpdatedBy;
                newActivity.DateCreatedUTC = DateTime.UtcNow;
                newActivity.UpdatedBy      = objupd.UpdatedBy;
                newActivity.LastUpdatedUTC = DateTime.UtcNow;

                newActivity.InvestigationID = targetObject.InvestigationID;
                newActivity.FromValue       = objupd.PriorityTypeID.ToString();
                newActivity.ToValue         = targetObject.PriorityTypeID.ToString();
                newActivity.ActivityTypeID  = 5; // Priority Type
                //Activities.Add(newActivity);
                _context.InvestigationActivity.Add(newActivity);
                hasChanges = true;
            }
            if (objupd.CountryID != targetObject.CountryID) // Country change
            {
                var newActivity = new InvestigationActivity();
                newActivity.AppUserID      = Convert.ToInt32(objupd.UpdatedBy);
                newActivity.CreatedBy      = objupd.UpdatedBy;
                newActivity.DateCreatedUTC = DateTime.UtcNow;
                newActivity.UpdatedBy      = objupd.UpdatedBy;
                newActivity.LastUpdatedUTC = DateTime.UtcNow;

                newActivity.InvestigationID = targetObject.InvestigationID;
                newActivity.FromValue       = objupd.PriorityTypeID.ToString();
                newActivity.ToValue         = targetObject.PriorityTypeID.ToString();
                newActivity.ActivityTypeID  = 3; // Country Type
                //Activities.Add(newActivity);
                _context.InvestigationActivity.Add(newActivity);
                hasChanges = true;
            }
            if (objupd.InvestigationStatusID != targetObject.InvestigationStatusID) // Status change
            {
                var newActivity = new InvestigationActivity();
                newActivity.AppUserID      = Convert.ToInt32(objupd.UpdatedBy);
                newActivity.CreatedBy      = objupd.UpdatedBy;
                newActivity.DateCreatedUTC = DateTime.UtcNow;
                newActivity.UpdatedBy      = objupd.UpdatedBy;
                newActivity.LastUpdatedUTC = DateTime.UtcNow;

                newActivity.InvestigationID = targetObject.InvestigationID;
                newActivity.FromValue       = objupd.PriorityTypeID.ToString();
                newActivity.ToValue         = targetObject.PriorityTypeID.ToString();
                newActivity.ActivityTypeID  = 2; // Status Type
                //Activities.Add(newActivity);
                _context.InvestigationActivity.Add(newActivity);
                hasChanges = true;
            }
            if (objupd.FunctionTypeID != targetObject.FunctionTypeID) // Category change
            {
                var newActivity = new InvestigationActivity();
                newActivity.AppUserID      = Convert.ToInt32(objupd.UpdatedBy);
                newActivity.CreatedBy      = objupd.UpdatedBy;
                newActivity.DateCreatedUTC = DateTime.UtcNow;
                newActivity.UpdatedBy      = objupd.UpdatedBy;
                newActivity.LastUpdatedUTC = DateTime.UtcNow;

                newActivity.InvestigationID = targetObject.InvestigationID;
                newActivity.FromValue       = objupd.PriorityTypeID.ToString();
                newActivity.ToValue         = targetObject.PriorityTypeID.ToString();
                newActivity.ActivityTypeID  = 7; // Category Type
                //Activities.Add(newActivity);
                _context.InvestigationActivity.Add(newActivity);
                hasChanges = true;
            }
            if (objupd.InvestigationDispositionsID != targetObject.InvestigationDispositionsID) // Disposition change
            {
                var newActivity = new InvestigationActivity();
                newActivity.AppUserID      = Convert.ToInt32(objupd.UpdatedBy);
                newActivity.CreatedBy      = objupd.UpdatedBy;
                newActivity.DateCreatedUTC = DateTime.UtcNow;
                newActivity.UpdatedBy      = objupd.UpdatedBy;
                newActivity.LastUpdatedUTC = DateTime.UtcNow;

                newActivity.InvestigationID = targetObject.InvestigationID;
                newActivity.FromValue       = objupd.PriorityTypeID.ToString();
                newActivity.ToValue         = targetObject.PriorityTypeID.ToString();
                newActivity.ActivityTypeID  = 6; // Disposition Type
                //Activities.Add(newActivity);
                _context.InvestigationActivity.Add(newActivity);
                hasChanges = true;
            }
            if (hasChanges)
            {
                ReturnData ret;
                ret = _context.SaveData();

                if (ret.Message == "Success")
                {
                    return(Ok());
                }

                return(NotFound(ret));
            }

            return(NotFound());
        }
示例#6
0
        public IActionResult UpdateEntry([FromBody] InvestigationDataSave objupdobj)
        {
            var objupd = objupdobj.Investigation;

            // 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(NotFound("Error: Human Review Service unavailable")); }
            }

            var targetObject = _context.Investigation.FirstOrDefault(t => t.InvestigationID == objupd.InvestigationID);

            if (targetObject == null)
            {
                return(NotFound());
            }


            // TODO check the lock table if its still valid
            // WorkUnitTypeID == 6 is BWQ, 3 is Investigations, 4 Alerts

            var thislock = _context.RecordLocks
                           .Where(v => v.WorkUnitTypeID == 3 &&
                                  v.IDFromWorkUnitsDBTable == objupd.InvestigationID);

            foreach (var locks in thislock)
            {
                if (locks.AppUserID != Convert.ToInt32(objupd.UpdatedBy)) // record lock found for another user
                {
                    var lockedToUser = _context.AppUser.FirstOrDefault(u => u.AppUserID == Convert.ToInt32(locks.AppUserID));

                    return(BadRequest("Investigation locked to: " + lockedToUser.AppUserName));
                }

                if (locks != null) // no locks
                {
                    _context.RecordLocks.Remove(locks);
                }
            }

            var InvestigationID = targetObject.InvestigationID;
            var MMMProfileID    = targetObject.EntityName;
            var workItemGuid    = targetObject.WorkItemID.ToString();

            _context.Entry(targetObject).CurrentValues.SetValues(objupd);

            // Save Notes
            if (objupdobj.InvestigationNote != null)
            {
                _context.InvestigationNote.Add(objupdobj.InvestigationNote);
            }

            ReturnData ret;

            ret = _context.SaveData();

            if (ret.Message != "Success")
            {
                return(Json(ret));
            }

            #region Human Review
            try
            {
                var Modules   = _context.ApplicationModules;
                var QueueGuid = (from mods in Modules
                                 where mods.ModuleName == "Investigations"
                                 select mods.QueueGuid).FirstOrDefault();

                var JsonData = JsonConvert.SerializeObject(objupd); // Serialize the update to Json

                WorkItemPutRequest HRPutRequest = new WorkItemPutRequest();
                HRPutRequest.isActive             = true;
                HRPutRequest.name                 = "Updating Entries for Investigation Entry " + InvestigationID + " and Profile " + MMMProfileID;
                HRPutRequest.description          = "Updating Entries for Investigation Entry " + InvestigationID + " 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 = Common.putWorkItemForEntityAsync(HRPutRequest, objupdobj.HRToken, _configuration);
            }
            catch (Exception e)
            {
                // log error
                var logInfo = e.Message;
            }
            #endregion

            if (ret.Message == "Success")
            {
                return(Ok());
            }

            return(NotFound(ret));
        }
示例#7
0
        public IActionResult AddInvestigationActivity([FromBody] InvestigationDataSave investigationactivity)
        {
            var result = _repository.AddInvestigationActivity(investigationactivity);

            return(Helper.CheckResult(result));
        }