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, 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;
            }
        }