/// <summary> /// Parts: /// - Jurisdiction /// - DataSetProfile /// </summary> /// <param name="entity"></param> /// <param name="status"></param> /// <returns></returns> public bool UpdateParts(ThisEntity entity, ref SaveStatus status) { bool isAllValid = true; Entity relatedEntity = EntityManager.GetEntity(entity.RowId); if (relatedEntity == null || relatedEntity.Id == 0) { status.AddError("Error - the related Entity was not found."); return(false); } //ProcessProfile Entity_ProcessProfileManager ppm = new Factories.Entity_ProcessProfileManager(); ppm.DeleteAll(relatedEntity, ref status); try { ppm.SaveList(entity.AdministrationProcess, Entity_ProcessProfileManager.ADMIN_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); } // Entity_ReferenceFrameworkManager erfm = new Entity_ReferenceFrameworkManager(); erfm.DeleteAll(relatedEntity, ref status); if (erfm.SaveList(relatedEntity.Id, CodesManager.PROPERTY_CATEGORY_CIP, entity.InstructionalProgramTypes, ref status) == false) { isAllValid = false; } //JurisdictionProfile Entity_JurisdictionProfileManager jpm = new Entity_JurisdictionProfileManager(); //do deletes - NOTE: other jurisdictions are added in: UpdateAssertedIns jpm.DeleteAll(relatedEntity, ref status); jpm.SaveList(entity.Jurisdiction, entity.RowId, Entity_JurisdictionProfileManager.JURISDICTION_PURPOSE_SCOPE, ref status); //datasetProfiles new DataSetTimeFrameManager().SaveList(entity.DataSetTimePeriod, entity.Id, 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); //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); }