Ejemplo n.º 1
0
        private bool UpdateParts(ThisEntity entity, ref SaveStatus status)
        {
            bool isAllValid = true;

            EntityPropertyManager mgr = new EntityPropertyManager();

            if (mgr.AddProperties(entity.ClaimType, entity.RowId, CodesManager.ENTITY_TYPE_PROCESS_PROFILE, CodesManager.PROPERTY_CATEGORY_CLAIM_TYPE, false, ref status) == false)
            {
                isAllValid = false;
            }

            //CostProfile
            CostProfileManager cpm = new Factories.CostProfileManager();

            cpm.SaveList(entity.EstimatedCost, entity.RowId, ref status);

            int newId = 0;

            if (entity.TargetCredentialIds != null && entity.TargetCredentialIds.Count > 0)
            {
                Entity_CredentialManager ecm = new Entity_CredentialManager();
                foreach (int id in entity.TargetCredentialIds)
                {
                    ecm.Add(entity.RowId, id, ref newId, ref status);
                }
            }

            return(isAllValid);
        }
Ejemplo n.º 2
0
        private bool HandleTargets(ThisEntity entity, ref SaveStatus status)
        {
            status.HasSectionErrors = false;
            int newId = 0;

            if (entity.TargetCredentialIds != null && entity.TargetCredentialIds.Count > 0)
            {
                Entity_CredentialManager ecm = new Entity_CredentialManager();
                foreach (int id in entity.TargetCredentialIds)
                {
                    ecm.Add(entity.RowId, id, ref newId, ref status);
                }
            }

            if (entity.TargetAssessmentIds != null && entity.TargetAssessmentIds.Count > 0)
            {
                Entity_AssessmentManager eam = new Entity_AssessmentManager();
                foreach (int id in entity.TargetAssessmentIds)
                {
                    newId = eam.Add(entity.RowId, id, true, ref status);
                }
            }

            if (entity.TargetLearningOpportunityIds != null && entity.TargetLearningOpportunityIds.Count > 0)
            {
                Entity_LearningOpportunityManager elm = new Entity_LearningOpportunityManager();
                foreach (int id in entity.TargetLearningOpportunityIds)
                {
                    newId = elm.Add(entity.RowId, id, true, ref status);
                }
            }

            return(!status.HasSectionErrors);
        }
        private bool HandleTargets(ThisEntity entity, Entity relatedEntity, ref SaveStatus status)
        {
            status.HasSectionErrors = false;
            int newId = 0;
            Entity_CredentialManager ecm = new Entity_CredentialManager();

            ecm.DeleteAll(relatedEntity, ref status);
            if (entity.TargetCredentialIds != null && entity.TargetCredentialIds.Count > 0)
            {
                foreach (int id in entity.TargetCredentialIds)
                {
                    ecm.Add(entity.RowId, id, BaseFactory.RELATIONSHIP_TYPE_HAS_PART, ref newId, ref status);
                }
            }

            Entity_AssessmentManager eam = new Entity_AssessmentManager();

            eam.DeleteAll(relatedEntity, ref status);
            if (entity.TargetAssessmentIds != null && entity.TargetAssessmentIds.Count > 0)
            {
                foreach (int id in entity.TargetAssessmentIds)
                {
                    newId = eam.Add(entity.RowId, id, BaseFactory.RELATIONSHIP_TYPE_HAS_PART, true, ref status);
                }
            }
            //
            Entity_LearningOpportunityManager elm = new Entity_LearningOpportunityManager();

            elm.DeleteAll(relatedEntity, ref status);
            if (entity.TargetLearningOpportunityIds != null && entity.TargetLearningOpportunityIds.Count > 0)
            {
                foreach (int id in entity.TargetLearningOpportunityIds)
                {
                    newId = elm.Add(entity.RowId, id, BaseFactory.RELATIONSHIP_TYPE_HAS_PART, true, ref status);
                }
            }
            //
            if (entity.TargetCompetencyFrameworkIds != null && entity.TargetCompetencyFrameworkIds.Count > 0)
            {
                //need a new table: Entity.CompetencyFramework!!
                var ecfm = new Entity_CompetencyFrameworkManager();
                //Need to do deleteall using this approach
                ecfm.DeleteAll(relatedEntity, ref status);
                foreach (int id in entity.TargetCompetencyFrameworkIds)
                {
                    ecfm.Add(entity.RowId, id, ref status);
                }
            }

            return(status.WasSectionValid);
        }
        public static void MapFromDB(DBEntity from, ThisEntity to, bool includingItems = true)
        {
            to.Id       = from.Id;
            to.RowId    = from.RowId;
            to.ParentId = from.EntityId;

            to.Description = from.Description;

            to.RevocationCriteriaDescription = from.RevocationCriteriaDescription;
            to.RevocationCriteriaUrl         = from.RevocationCriteriaUrl;

            if (IsValidDate(from.DateEffective))
            {
                to.DateEffective = (( DateTime )from.DateEffective).ToString("yyyy-MM-dd");
            }
            else
            {
                to.DateEffective = "";
            }

            to.RevocationCriteriaUrl = from.RevocationCriteriaUrl;
            if ((from.Entity.EntityBaseName ?? "").Length > 3)
            {
                to.ParentSummary = from.Entity.EntityBaseName;
            }
            //not used:
            to.ProfileSummary = SetEntitySummary(to);
            //no longer using name, but need for the editor list
            to.ProfileName = to.ProfileSummary;


            if (IsValidDate(from.Created))
            {
                to.Created = ( DateTime )from.Created;
            }
            if (IsValidDate(from.LastUpdated))
            {
                to.LastUpdated = ( DateTime )from.LastUpdated;
            }

            if (includingItems)
            {
                to.CredentialProfiled = Entity_CredentialManager.GetAll(to.RowId);
                //
                to.Jurisdiction = Entity_JurisdictionProfileManager.Jurisdiction_GetAll(to.RowId);
                to.Region       = Entity_JurisdictionProfileManager.Jurisdiction_GetAll(to.RowId, Entity_JurisdictionProfileManager.JURISDICTION_PURPOSE_RESIDENT);
            }
        }
        public bool UpdateParts(ThisEntity entity, ref SaveStatus status)
        {
            bool   isValid       = true;
            Entity relatedEntity = EntityManager.GetEntity(entity.RowId);

            if (relatedEntity == null || relatedEntity.Id == 0)
            {
                status.AddError("Error - the related Entity was not found.");
                return(false);
            }

            //21-01-07 mparsons - Identifier will now be saved in the Json properties, not in Entity_IdentifierValue
            //new Entity_IdentifierValueManager().SaveList( entity.Identifier, entity.RowId, Entity_IdentifierValueManager.CREDENTIAL_Identifier, ref status, false );
            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);
            int newId = 0;

            if (entity.JsonProperties != null)
            {
                if (entity.JsonProperties.SourceCredential != null && entity.JsonProperties.SourceCredential.Id > 0)
                {
                    ecm.Add(entity.RowId, entity.JsonProperties.SourceCredential.Id, BaseFactory.RELATIONSHIP_TYPE_IS_PART_OF, ref newId, ref status);
                }
                if (entity.JsonProperties.SourceAssessment != null && entity.JsonProperties.SourceAssessment.Id > 0)
                {
                    eam.Add(entity.RowId, entity.JsonProperties.SourceAssessment.Id, BaseFactory.RELATIONSHIP_TYPE_IS_PART_OF, false, ref status);
                }
                if (entity.JsonProperties.SourceLearningOpportunity != null && entity.JsonProperties.SourceLearningOpportunity.Id > 0)
                {
                    elom.Add(entity.RowId, entity.JsonProperties.SourceLearningOpportunity.Id, BaseFactory.RELATIONSHIP_TYPE_IS_PART_OF, false, ref status);
                }
            }
            return(isValid);
        }
        private 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);
            }
            EntityPropertyManager mgr = new EntityPropertyManager();

            //first clear all properties
            mgr.DeleteAll(relatedEntity, ref status);
            //
            if (mgr.AddProperties(entity.ClaimType, entity.RowId, CodesManager.ENTITY_TYPE_PROCESS_PROFILE, CodesManager.PROPERTY_CATEGORY_CLAIM_TYPE, false, ref status) == false)
            {
                isAllValid = false;
            }

            //CostProfile
            CostProfileManager cpm = new Factories.CostProfileManager();

            cpm.SaveList(entity.EstimatedCost, entity.RowId, ref status);

            int newId = 0;
            Entity_CredentialManager ecm = new Entity_CredentialManager();

            ecm.DeleteAll(relatedEntity, ref status);
            if (entity.TargetCredentialIds != null && entity.TargetCredentialIds.Count > 0)
            {
                foreach (int id in entity.TargetCredentialIds)
                {
                    ecm.Add(entity.RowId, id, BaseFactory.RELATIONSHIP_TYPE_HAS_PART, ref newId, ref status);
                }
            }

            return(isAllValid);
        }
Ejemplo n.º 7
0
        public static void MapFromDB(DBEntity from, ThisEntity to,
                                     bool includingItems
                                     )
        {
            //TODO - add option for get during import to get less data
            to.Id    = from.Id;
            to.RowId = from.RowId;

            to.Description = (from.Description ?? "");
            //ProfileName is for display purposes
            to.ProfileName = to.Description.Length < 80 ? to.Description : to.Description.Substring(0, 79) + " ...";

            if (from.HolderMustAuthorize != null)
            {
                to.HolderMustAuthorize = ( bool )from.HolderMustAuthorize;
            }

            if (IsValidDate(from.DateEffective))
            {
                to.DateEffective = (( DateTime )from.DateEffective).ToShortDateString();
            }
            else
            {
                to.DateEffective = "";
            }

            to.SubjectWebpage                = from.SubjectWebpage;
            to.VerificationServiceUrl        = from.VerificationService;
            to.VerificationDirectory         = from.VerificationDirectory;
            to.VerificationMethodDescription = from.VerificationMethodDescription;

            if (IsGuidValid(from.OfferedByAgentUid))
            {
                to.OfferedByAgentUid = ( Guid )from.OfferedByAgentUid;
                to.OfferedByAgent    = OrganizationManager.GetBasics(to.OfferedByAgentUid);
            }

            if (includingItems)
            {
                //TODO 170803- need to chg to a list
                //only get if:
                //edit - get profile list
                //detail - get basic
                bool isForDetailPageCredential = true;

                to.TargetCredential = Entity_CredentialManager.GetAll(to.RowId, isForDetailPageCredential);

                to.EstimatedCost = CostProfileManager.GetAll(to.RowId);

                to.ClaimType = EntityPropertyManager.FillEnumeration(to.RowId, CodesManager.PROPERTY_CATEGORY_CLAIM_TYPE);

                to.Jurisdiction = Entity_JurisdictionProfileManager.Jurisdiction_GetAll(to.RowId, Entity_JurisdictionProfileManager.JURISDICTION_PURPOSE_SCOPE);

                to.Region = Entity_JurisdictionProfileManager.Jurisdiction_GetAll(to.RowId, Entity_JurisdictionProfileManager.JURISDICTION_PURPOSE_RESIDENT);
                to.JurisdictionAssertions = Entity_JurisdictionProfileManager.Jurisdiction_GetAll(to.RowId, Entity_JurisdictionProfileManager.JURISDICTION_PURPOSE_OFFERREDIN);

                //to.VerificationStatus = Entity_VerificationStatusManager.GetAll( to.Id );
            }


            if (IsValidDate(from.Created))
            {
                to.Created = ( DateTime )from.Created;
            }
            if (IsValidDate(from.LastUpdated))
            {
                to.LastUpdated = ( DateTime )from.LastUpdated;
            }
        }
        public static void MapFromDB(DBEntity from, ThisEntity to, bool includingItems, bool getForList)
        {
            to.Id    = from.Id;
            to.RowId = from.RowId;
            //HANDLE PROCESS TYPES
            if (from.ProcessTypeId != null && ( int )from.ProcessTypeId > 0)
            {
                to.ProcessTypeId = ( int )from.ProcessTypeId;
            }
            else
            {
                to.ProcessTypeId = 1;
            }

            to.ProfileName = to.ProcessType;
            //need to distinguish if for detail
            to.ProcessProfileType = GetProfileType(to.ProcessTypeId);

            to.Description = from.Description;
            if ((to.Description ?? "").Length > 5)
            {
                //this should just be the type now
                to.ProfileName = GetProfileType(to.ProcessTypeId);

                //to.ProfileName = to.Description.Length > 100 ? to.Description.Substring(0,100) + " . . ." : to.Description;
            }

            if (from.Entity != null)
            {
                to.ParentId = from.Entity.Id;
            }

            to.ProfileSummary = SetEntitySummary(to);

            //- provide minimum option, for lists
            if (getForList)
            {
                return;
            }

            if (IsGuidValid(from.ProcessingAgentUid))
            {
                to.ProcessingAgentUid = ( Guid )from.ProcessingAgentUid;

                to.ProcessingAgent = OrganizationManager.GetBasics(to.ProcessingAgentUid);
            }

            if (IsValidDate(from.DateEffective))
            {
                to.DateEffective = (( DateTime )from.DateEffective).ToString("yyyy-MM-dd");
            }
            else
            {
                to.DateEffective = "";
            }
            to.SubjectWebpage = from.SubjectWebpage;

            to.ProcessFrequency = from.ProcessFrequency;
            //to.TargetCompetencyFramework = from.TargetCompetencyFramework;
            //to.RequiresCompetenciesFrameworks = Entity_CompetencyFrameworkManager.GetAll( to.RowId, "requires" );

            to.ProcessMethod            = from.ProcessMethod;
            to.ProcessMethodDescription = from.ProcessMethodDescription;

            to.ProcessStandards            = from.ProcessStandards;
            to.ProcessStandardsDescription = from.ProcessStandardsDescription;

            to.ScoringMethodDescription        = from.ScoringMethodDescription;
            to.ScoringMethodExample            = from.ScoringMethodExample;
            to.ScoringMethodExampleDescription = from.ScoringMethodExampleDescription;
            to.VerificationMethodDescription   = from.VerificationMethodDescription;

            if (IsValidDate(from.DateEffective))
            {
                to.DateEffective = (( DateTime )from.DateEffective).ToString("yyyy-MM-dd");
            }
            else
            {
                to.DateEffective = "";
            }

            //enumerations
            to.DataCollectionMethodType = EntityPropertyManager.FillEnumeration(to.RowId, CodesManager.PROPERTY_CATEGORY_DATA_COLLECTION_METHOD_TYPE);
            to.ExternalInputType        = EntityPropertyManager.FillEnumeration(to.RowId, CodesManager.PROPERTY_CATEGORY_EXTERNAL_INPUT_TYPE);



            if (includingItems)
            {
                to.Jurisdiction = Entity_JurisdictionProfileManager.Jurisdiction_GetAll(to.RowId);
                //will only be one, but could model with multiple
                to.TargetCredential = Entity_CredentialManager.GetAll(to.RowId, BaseFactory.RELATIONSHIP_TYPE_HAS_PART);
                to.TargetAssessment = Entity_AssessmentManager.GetAll(to.RowId, BaseFactory.RELATIONSHIP_TYPE_HAS_PART);

                to.TargetLearningOpportunity = Entity_LearningOpportunityManager.LearningOpps_GetAll(to.RowId, true);
                to.TargetCompetencyFramework = Entity_CompetencyFrameworkManager.GetAll(to.RowId);
            }


            if (IsValidDate(from.Created))
            {
                to.Created = ( DateTime )from.Created;
            }

            if (IsValidDate(from.LastUpdated))
            {
                to.LastUpdated = ( DateTime )from.LastUpdated;
            }
        }
        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);
        }