public bool UpdateParts(ThisEntity entity, ref SaveStatus status) { bool isAllValid = true; Entity_AgentRelationshipManager mgr = new Entity_AgentRelationshipManager(); Entity relatedEntity = EntityManager.GetEntity(entity.RowId); if (relatedEntity == null || relatedEntity.Id == 0) { status.AddError("Error - the related Entity was not found."); return(false); } mgr.DeleteAll(relatedEntity, ref status); mgr.SaveList(relatedEntity.Id, Entity_AgentRelationshipManager.ROLE_TYPE_OWNER, entity.OwnedBy, ref status); return(isAllValid); }
public bool UpdateParts(ThisEntity entity, ref SaveStatus status) { bool isAllValid = true; Entity_AgentRelationshipManager mgr = new Entity_AgentRelationshipManager(); Entity relatedEntity = EntityManager.GetEntity(entity.RowId); if (relatedEntity == null || relatedEntity.Id == 0) { status.AddError("Error - the related Entity was not found."); return(false); } mgr.DeleteAll(relatedEntity, ref status); mgr.SaveList(relatedEntity.Id, Entity_AgentRelationshipManager.ROLE_TYPE_OWNER, entity.OwnedBy, ref status); //initial plan is store whole payload as json Entity_ReferenceFrameworkManager erfm = new Entity_ReferenceFrameworkManager(); erfm.DeleteAll(relatedEntity, ref status); if (erfm.SaveList(relatedEntity.Id, CodesManager.PROPERTY_CATEGORY_SOC, entity.Occupations, ref status) == false) { isAllValid = false; } if (erfm.SaveList(relatedEntity.Id, CodesManager.PROPERTY_CATEGORY_NAICS, entity.Industries, ref status) == false) { isAllValid = false; } // Entity_ReferenceManager erm = new Entity_ReferenceManager(); erm.DeleteAll(relatedEntity, ref status); if (erm.Add(entity.Subject, entity.RowId, CodesManager.ENTITY_TYPE_PATHWAY, ref status, CodesManager.PROPERTY_CATEGORY_SUBJECT, false) == false) { isAllValid = false; } if (erm.Add(entity.Keyword, entity.RowId, CodesManager.ENTITY_TYPE_PATHWAY, ref status, CodesManager.PROPERTY_CATEGORY_KEYWORD, false) == false) { isAllValid = false; } return(isAllValid); }
public bool UpdateParts(ThisEntity entity, ref SaveStatus status) { bool isAllValid = true; Entity_AgentRelationshipManager mgr = new Entity_AgentRelationshipManager(); Entity relatedEntity = EntityManager.GetEntity(entity.RowId); if (relatedEntity == null || relatedEntity.Id == 0) { status.AddError(thisClassName + " - Error - the parent entity was not found."); return(false); } mgr.DeleteAll(relatedEntity, ref status); mgr.SaveList(relatedEntity.Id, Entity_AgentRelationshipManager.ROLE_TYPE_OFFERED_BY, entity.OfferedBy, ref status); mgr.SaveList(relatedEntity.Id, Entity_AgentRelationshipManager.ROLE_TYPE_OWNER, entity.OwnedBy, ref status); var epmgr = new Entity_PathwayManager(); //handle pathways - using replace //actually just use typical pattern of delete all and then add //could be extreme //epmgr.DeleteAll( parent.EntityUid, ref status ); var list = new List <int>(); //check if we should get the list of ids easier foreach (var item in entity.HasPathwayList) { var p = PathwayManager.GetBasic(item); if (p != null && p.Id > 0) { list.Add(p.Id); } else { //?? status.AddError(thisClassName + string.Format(" - Error - the pathway using Guid: {0} entity was not found.", item.ToString())); } } if (!new Entity_PathwayManager().Replace(entity.RowId, 1, list, ref status)) { isAllValid = false; } return(isAllValid); }
/// <summary> /// Do delete based on import of deleted documents /// </summary> /// <param name="credentialRegistryId">NOT CURRENTLY HANDLED</param> /// <param name="ctid"></param> /// <param name="statusMessage"></param> /// <returns></returns> public bool Delete(string ctid, ref string statusMessage) { bool isValid = true; if (string.IsNullOrWhiteSpace(ctid)) { statusMessage = thisClassName + ".Delete() Error - a valid CTID must be provided"; return(false); } using (var context = new EntityContext()) { try { context.Configuration.LazyLoadingEnabled = false; var efEntity = context.CompetencyFramework .FirstOrDefault(s => s.CTID == ctid); if (efEntity != null && efEntity.Id > 0) { //TODO - may need a check for existing alignments Guid rowId = efEntity.RowId; var orgCtid = efEntity.OrganizationCTID ?? ""; //need to remove from Entity. //-using before delete trigger - verify won't have RI issues string msg = string.Format(" CompetencyFramework Id: {0}, Name: {1}, Ctid: {2}", efEntity.Id, efEntity.Name, efEntity.CTID); //leaving as virtual? //need to check for in use. //context.CompetencyFramework.Remove( efEntity ); efEntity.EntityStateId = 0; efEntity.LastUpdated = System.DateTime.Now; int count = context.SaveChanges(); if (count >= 0) { new ActivityManager().SiteActivityAdd(new SiteActivity() { ActivityType = "CompetencyFramework", Activity = "Import", Event = "Delete", Comment = msg }); isValid = true; //add pending request List <String> messages = new List <string>(); new SearchPendingReindexManager().AddDeleteRequest(CodesManager.ENTITY_TYPE_COMPETENCY_FRAMEWORK, efEntity.Id, ref messages); //delete all relationships workIT.Models.SaveStatus status = new SaveStatus(); Entity_AgentRelationshipManager earmgr = new Entity_AgentRelationshipManager(); earmgr.DeleteAll(rowId, ref status); //also check for any relationships //There could be other orgs from relationships to be reindexed as well! } if (!string.IsNullOrWhiteSpace(orgCtid)) { List <String> messages = new List <string>(); //mark owning org for updates // - nothing yet from frameworks var org = OrganizationManager.GetSummaryByCtid(orgCtid); if (org != null && org.Id > 0) { new SearchPendingReindexManager().Add(CodesManager.ENTITY_TYPE_ORGANIZATION, org.Id, 1, ref messages); //also check for any relationships new Entity_AgentRelationshipManager().ReindexAgentForDeletedArtifact(org.RowId); } else { //issue with org ctid not found } } } else { statusMessage = thisClassName + ".Delete() Warning No action taken, as the record was not found."; } } catch (Exception ex) { LoggingHelper.LogError(ex, thisClassName + ".Delete(envelopeId)"); statusMessage = FormatExceptions(ex); isValid = false; if (statusMessage.ToLower().IndexOf("the delete statement conflicted with the reference constraint") > -1) { statusMessage = thisClassName + "Error: this record cannot be deleted as it is being referenced by other items, such as roles or credentials. These associations must be removed before this assessment can be deleted."; } } } return(isValid); }
public bool Delete(string envelopeId, string ctid, ref string statusMessage) { bool isValid = true; if ((string.IsNullOrWhiteSpace(envelopeId) || !IsValidGuid(envelopeId)) && string.IsNullOrWhiteSpace(ctid)) { statusMessage = thisClassName + ".Delete() Error - a valid envelope identifier must be provided - OR valid CTID"; return(false); } if (string.IsNullOrWhiteSpace(envelopeId)) { envelopeId = "SKIP ME"; } if (string.IsNullOrWhiteSpace(ctid)) { ctid = "SKIP ME"; } int orgId = 0; Guid orgUid = new Guid(); using (var context = new EntityContext()) { try { context.Configuration.LazyLoadingEnabled = false; DBEntity efEntity = context.PathwaySet .FirstOrDefault(s => s.CredentialRegistryId == envelopeId || (s.CTID == ctid) ); if (efEntity != null && efEntity.Id > 0) { Guid rowId = efEntity.RowId; if (IsValidGuid(efEntity.OwningAgentUid)) { Organization org = OrganizationManager.GetBasics(( Guid )efEntity.OwningAgentUid); orgId = org.Id; orgUid = org.RowId; } //need to remove from Entity. //-using before delete trigger - verify won't have RI issues string msg = string.Format(" PathwaySet. Id: {0}, Name: {1}, Ctid: {2}.", efEntity.Id, efEntity.Name, efEntity.CTID); //18-04-05 mparsons - change to set inactive, and notify - seems to have been some incorrect deletes //context.Pathway.Remove( efEntity ); efEntity.EntityStateId = 0; efEntity.LastUpdated = System.DateTime.Now; int count = context.SaveChanges(); if (count > 0) { new ActivityManager().SiteActivityAdd(new SiteActivity() { ActivityType = "PathwaySet", Activity = "Import", Event = "Delete", Comment = msg, ActivityObjectId = efEntity.Id }); isValid = true; //add pending request List <String> messages = new List <string>(); new SearchPendingReindexManager().AddDeleteRequest(CodesManager.ENTITY_TYPE_PATHWAY_SET, efEntity.Id, ref messages); //mark owning org for updates (actually should be covered by ReindexAgentForDeletedArtifact new SearchPendingReindexManager().Add(CodesManager.ENTITY_TYPE_ORGANIZATION, orgId, 1, ref messages); //delete all relationships workIT.Models.SaveStatus status = new SaveStatus(); Entity_AgentRelationshipManager earmgr = new Entity_AgentRelationshipManager(); earmgr.DeleteAll(rowId, ref status); //also check for any relationships //There could be other orgs from relationships to be reindexed as well! //also check for any relationships new Entity_AgentRelationshipManager().ReindexAgentForDeletedArtifact(orgUid); } } else { statusMessage = thisClassName + ".Delete() Warning No action taken, as the record was not found."; } } catch (Exception ex) { LoggingHelper.LogError(ex, thisClassName + ".Delete(envelopeId)"); isValid = false; statusMessage = FormatExceptions(ex); if (statusMessage.ToLower().IndexOf("the delete statement conflicted with the reference constraint") > -1) { statusMessage = "Error: this PathwaySet cannot be deleted as it is being referenced by other items, such as roles or credentials. These associations must be removed before this PathwaySet can be deleted."; } } } return(isValid); }
public bool UpdateParts(ThisEntity entity, ref SaveStatus status) { bool isAllValid = true; Entity_AgentRelationshipManager mgr = new Entity_AgentRelationshipManager(); Entity relatedEntity = EntityManager.GetEntity(entity.RowId); if (relatedEntity == null || relatedEntity.Id == 0) { status.AddError("Error - the related Entity was not found."); return(false); } mgr.DeleteAll(relatedEntity, ref status); mgr.SaveList(relatedEntity.Id, Entity_AgentRelationshipManager.ROLE_TYPE_OWNER, entity.OwnedBy, ref status); //consider storing the class properties as Json! //derived from //where to store this? It commonly require Entity.TransferValueProfile var etvlMgr = new Entity_TransferValueProfileManager(); etvlMgr.SaveList(entity.DerivedFromForImport, entity.RowId, ref status); //delete all Entity.Lopp, .Cred, and .Assessment relationships, and then add? //would be convenient if a delete wasn't necessary //NOTE: this will leave orphan reference objects. Will need to clean up. //could check if target is a reference. If so delete, or check if there are other references //NOTE: this should have been done in TransferValueServices.HandlingExistingEntity - is done corrently, remove this Entity_CredentialManager ecm = new Entity_CredentialManager(); ecm.DeleteAll(relatedEntity, ref status); // var eam = new Entity_AssessmentManager(); eam.DeleteAll(relatedEntity, ref status); // var elom = new Entity_LearningOpportunityManager(); elom.DeleteAll(relatedEntity, ref status); // var etvp = new Entity_TransferValueProfileManager(); etvp.DeleteAll(relatedEntity, ref status); // foreach (var item in entity.TransferValueFromImport) { int newId = 0; var from = EntityManager.GetEntity(item, false); if (from == null || from.Id == 0) { status.AddError(string.Format("{0}.UpdateParts - TransferValueFromImport. TVP: {1}. An entity was not found for GUID: {2}", thisClassName, entity.Id, item)); continue; } if (from.EntityTypeId == 1) { ecm.Add(entity.RowId, from.EntityBaseId, BaseFactory.RELATIONSHIP_TYPE_IS_PART_OF, ref newId, ref status); } else if (from.EntityTypeId == 3) { eam.Add(entity.RowId, from.EntityBaseId, BaseFactory.RELATIONSHIP_TYPE_IS_PART_OF, false, ref status); } else if (from.EntityTypeId == 7) { elom.Add(entity.RowId, from.EntityBaseId, BaseFactory.RELATIONSHIP_TYPE_IS_PART_OF, false, ref status); } } foreach (var item in entity.TransferValueForImport) { int newId = 0; var from = EntityManager.GetEntity(item, false); if (from == null || from.Id == 0) { //?? status.AddError(string.Format("{0}.UpdateParts - TransferValueForImport. TVP: {1}. An entity was not found for GUID: {2}", thisClassName, entity.Id, item)); continue; } if (from.EntityTypeId == 1) { ecm.Add(entity.RowId, from.EntityBaseId, BaseFactory.RELATIONSHIP_TYPE_HAS_PART, ref newId, ref status); } else if (from.EntityTypeId == 3) { eam.Add(entity.RowId, from.EntityBaseId, BaseFactory.RELATIONSHIP_TYPE_HAS_PART, false, ref status); } else if (from.EntityTypeId == 7) { elom.Add(entity.RowId, from.EntityBaseId, BaseFactory.RELATIONSHIP_TYPE_HAS_PART, false, ref status); } } foreach (var item in entity.DerivedFromForImport) { var from = Get(item); if (from == null || from.Id == 0) { //?? status.AddError(string.Format("{0}.UpdateParts - DerivedFromForImport. TVP: {1}. A TVP was not found for ID: {2}", thisClassName, entity.Id, item)); continue; } //check that not the same as current TVP if (from.Id == entity.Id) { status.AddError(string.Format("{0}.UpdateParts - DerivedFromForImport. TVP: {1}. The DerivedFrom TVP Id ({2}) is the same as the current TVP ID", thisClassName, entity.Id, item)); continue; } etvp.Add(entity.RowId, item, ref status); } //ProcessProfile Entity_ProcessProfileManager ppm = new Factories.Entity_ProcessProfileManager(); ppm.DeleteAll(relatedEntity, ref status); try { ppm.SaveList(entity.DevelopmentProcess, Entity_ProcessProfileManager.DEV_PROCESS_TYPE, entity.RowId, ref status); } catch (Exception ex) { string message = FormatExceptions(ex); LoggingHelper.LogError(ex, thisClassName + string.Format(".AddProfiles() - ProcessProfiles. id: {0}", entity.Id)); status.AddWarning(thisClassName + ".AddProfiles(). Exceptions encountered handling ProcessProfiles. " + message); } return(isAllValid); }