예제 #1
0
        public static void MapFromDB(DBEntity input, ThisEntity output, bool includingPathways = false)
        {
            output.Id             = input.Id;
            output.RowId          = input.RowId;
            output.CTID           = input.CTID;
            output.Name           = input.Name;
            output.Description    = input.Description;
            output.SubjectWebpage = input.SubjectWebpage;
            output.EntityStateId  = (int)(input.EntityStateId ?? 2);
            //TODO - get pathways
            if (includingPathways)
            {
                output.Pathways   = Entity_PathwayManager.GetAll(output.RowId, true);
                output.HasPathway = output.Pathways.Select(m => m.CTID).ToList();
            }
            else
            {
                //really only need the pathway ids for publishing - also ctid
                //might just get the lite versions of a pathway?
                output.Pathways = Entity_PathwayManager.GetAll(output.RowId, false);
                //always collect for now
                output.HasPathway = output.Pathways.Select(m => m.CTID).ToList();
            }

            if (IsGuidValid(input.OwningAgentUid))
            {
                output.OwningAgentUid     = ( Guid )input.OwningAgentUid;
                output.OwningOrganization = OrganizationManager.GetForSummary(output.OwningAgentUid);

                //get roles
                OrganizationRoleProfile orp = Entity_AgentRelationshipManager.AgentEntityRole_GetAsEnumerationFromCSV(output.RowId, output.OwningAgentUid);
                output.OwnerRoles = orp.AgentRole;
            }
            //
            output.OrganizationRole = Entity_AgentRelationshipManager.AgentEntityRole_GetAll_ToEnumeration(output.RowId, true);

            //confustion over OrganizationRole and OwnerRoles (enum)!!!
            //to.OrganizationRole = Entity_AgentRelationshipManager.AgentEntityRole_GetAll_ToEnumeration( to.RowId, true );
            output.CredentialRegistryId = input.CredentialRegistryId;

            if (IsValidDate(input.Created))
            {
                output.Created = ( DateTime )input.Created;
            }
            if (IsValidDate(input.LastUpdated))
            {
                output.LastUpdated = ( DateTime )input.LastUpdated;
            }

            var relatedEntity = EntityManager.GetEntity(output.RowId, false);

            if (relatedEntity != null && relatedEntity.Id > 0)
            {
                output.EntityLastUpdated = relatedEntity.LastUpdated;
            }
        }
예제 #2
0
        }         //

        public static void MapToDB(ThisEntity input, DBEntity output)
        {
            //want output ensure fields input create are not wiped
            if (output.Id == 0)
            {
                output.CTID = input.CTID;
            }
            if (!string.IsNullOrWhiteSpace(input.CredentialRegistryId))
            {
                output.CredentialRegistryId = input.CredentialRegistryId;
            }

            output.Id                  = input.Id;
            output.Name                = GetData(input.Name);
            output.Description         = GetData(input.Description);
            output.SubjectWebpage      = GetUrlData(input.SubjectWebpage);
            output.HasProgressionModel = input.ProgressionModelURI;

            if (IsGuidValid(input.OwningAgentUid))
            {
                if (output.Id > 0 && output.OwningAgentUid != input.OwningAgentUid)
                {
                    if (IsGuidValid(output.OwningAgentUid))
                    {
                        //need output remove the owner role, or could have been others
                        string statusMessage = "";
                        new Entity_AgentRelationshipManager().Delete(output.RowId, output.OwningAgentUid, Entity_AgentRelationshipManager.ROLE_TYPE_OWNER, ref statusMessage);
                    }
                }
                output.OwningAgentUid = input.OwningAgentUid;
                //get for use to add to elastic pending
                input.OwningOrganization = OrganizationManager.GetForSummary(input.OwningAgentUid);
                //input.OwningOrganizationId = org.Id;
            }
            else
            {
                //always have output have an owner
                //output.OwningAgentUid = null;
            }

            //if ( input.InLanguageId > 0 )
            //	output.InLanguageId = input.InLanguageId;
            //else if ( !string.IsNullOrWhiteSpace( input.InLanguage ) )
            //{
            //	output.InLanguageId = CodesManager.GetLanguageId( input.InLanguage );
            //}
            //else


            //======================================================================
        }
예제 #3
0
        /// <summary>
        /// Get absolute minimum for display as profile link
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static ThisEntity GetBasic(int id)
        {
            ThisEntity entity = new ThisEntity();

            using (var context = new EntityContext())
            {
                //want to get org, deal with others
                //context.Configuration.LazyLoadingEnabled = false;

                DBEntity item = context.ConditionManifest
                                .SingleOrDefault(s => s.Id == id);

                if (item != null && item.Id > 0)
                {
                    entity.Id             = item.Id;
                    entity.RowId          = item.RowId;
                    entity.Name           = item.Name;
                    entity.Description    = item.Description;
                    entity.SubjectWebpage = item.SubjectWebpage;

                    entity.OrganizationId     = ( int )(item.OrganizationId ?? 0);
                    entity.OwningOrganization = new Organization();
                    if (item.OrganizationId > 0)
                    {
                        //if ( item.Organization != null && item.Organization.Id > 0 )
                        //{
                        //	entity.OwningOrganization.Id = item.Organization.Id;
                        //	entity.OwningOrganization.Name = item.Organization.Name;
                        //	entity.OwningOrganization.RowId = item.Organization.RowId;
                        //	entity.OwningOrganization.SubjectWebpage = item.Organization.SubjectWebpage;

                        //	//OrganizationManager.ToMapCommon( item.Organization, entity.OwningOrganization, false, false, false, false, false );
                        //}
                        //else
                        {
                            entity.OwningOrganization = OrganizationManager.GetForSummary(entity.OrganizationId);
                            entity.OwningAgentUid     = entity.OwningOrganization.RowId;
                        }

                        entity.OrganizationName = entity.OwningOrganization.Name;
                        entity.OwningAgentUid   = entity.OwningOrganization.RowId;
                    }
                }
            }

            return(entity);
        }
예제 #4
0
        public static void CredentialMinimumMap(EM.Credential from, Credential to)
        {
            CredentialRequest cr = new CredentialRequest();

            //probably too much
            cr.IsDetailRequest();

            to.Id    = from.Id;
            to.RowId = from.RowId;

            to.Name        = from.Name;
            to.Description = from.Description;

            to.SubjectWebpage = from.SubjectWebpage;
            to.CTID           = from.CTID;
            to.EntityStateId  = (int)from.EntityStateId;
            // 16-06-15 mp - always include credential type
            //can be null for a pending record
            to.CredentialTypeId = ( int )(from.CredentialTypeId ?? 0);
            if (to.CredentialTypeId > 0)
            {
                CodeItem ct = CodesManager.Codes_PropertyValue_Get(to.CredentialTypeId);
                if (ct != null && ct.Id > 0)
                {
                    to.CredentialType       = ct.Title;
                    to.CredentialTypeSchema = ct.SchemaName;
                }

                to.CredentialTypeEnum = EntityPropertyManager.FillEnumeration(to.RowId, CodesManager.PROPERTY_CATEGORY_CREDENTIAL_TYPE);
                to.CredentialTypeEnum.Items.Add(new EnumeratedItem()
                {
                    Id = to.CredentialTypeId, Name = ct.Name, SchemaName = ct.SchemaName
                });
            }

            if (from.ImageUrl != null && from.ImageUrl.Trim().Length > 0)
            {
                to.Image = from.ImageUrl;
            }
            else
            {
                to.Image = null;
            }

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

            to.AudienceLevelType = EntityPropertyManager.FillEnumeration(to.RowId, CodesManager.PROPERTY_CATEGORY_AUDIENCE_LEVEL);

            //to.Occupation = Entity_FrameworkItemManager.FillEnumeration( to.RowId, CodesManager.PROPERTY_CATEGORY_SOC );
            to.Occupation       = Reference_FrameworksManager.FillEnumeration(to.RowId, CodesManager.PROPERTY_CATEGORY_SOC);
            to.OtherOccupations = Entity_ReferenceManager.GetAll(to.RowId, CodesManager.PROPERTY_CATEGORY_SOC);

            //to.Industry = Entity_FrameworkItemManager.FillEnumeration( to.RowId, CodesManager.PROPERTY_CATEGORY_NAICS );
            to.Industry        = Reference_FrameworksManager.FillEnumeration(to.RowId, CodesManager.PROPERTY_CATEGORY_NAICS);
            to.OtherIndustries = Entity_ReferenceManager.GetAll(to.RowId, CodesManager.PROPERTY_CATEGORY_NAICS);

            to.InstructionalProgramType = Reference_FrameworksManager.FillEnumeration(to.RowId, CodesManager.PROPERTY_CATEGORY_CIP);

            to.Subject = Entity_ReferenceManager.GetAllSubjects(to.RowId);

            to.Keyword = Entity_ReferenceManager.GetAll(to.RowId, CodesManager.PROPERTY_CATEGORY_KEYWORD);

            //Added these because they were needed on the detail page - NA 6/1/2017
            to.OwningAgentUid     = from.OwningAgentUid ?? Guid.Empty;
            to.OwningOrganization = OrganizationManager.GetForSummary(to.OwningAgentUid);
        }
예제 #5
0
        public static void MapFromDB(DBEntity from, ThisEntity to,
                                     bool includingProperties = false,
                                     bool includingProfiles   = true,
                                     bool forEditView         = true)
        {
            to.Id            = from.Id;
            to.RowId         = from.RowId;
            to.EntityStateId = ( int )(from.EntityStateId ?? 1);

            to.OrganizationId = (int)(from.OrganizationId ?? 0);

            if (to.OrganizationId > 0)
            {
                //if ( from.Organization != null && from.Organization.Id > 0 )
                //{
                //	//ensure there is no infinite loop
                //	//the following results in an infinite loop
                //	//OrganizationManager.ToMapCommon( from.Organization, to.OwningOrganization, false, false, false, false, false );
                //	//maybe: ToMapForSummary
                //	//OrganizationManager.ToMapForSummary( from.Organization, to.OwningOrganization );

                //	to.OwningOrganization = OrganizationManager.GetForSummary( to.OrganizationId );
                //	to.OwningAgentUid = to.OwningOrganization.RowId;
                //} else
                {
                    to.OwningOrganization = OrganizationManager.GetForSummary(to.OrganizationId);
                    to.OwningAgentUid     = to.OwningOrganization.RowId;
                }

                to.OrganizationName = to.OwningOrganization.Name;
                to.OwningAgentUid   = to.OwningOrganization.RowId;
            }

            to.Name        = from.Name;
            to.Description = from.Description == null ? "" : from.Description;

            to.CTID = from.CTID;
            to.CredentialRegistryId = from.CredentialRegistryId;

            to.SubjectWebpage = from.SubjectWebpage;

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

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

            //get common conditions
            //TODO - determine what to return for edit vs non-edit states
            //if ( forEditView )
            //	to.CommonConditions = Entity_CommonConditionManager.GetAll( to.RowId, forEditView );
            //else
            //	to.CommonConditions = Entity_CommonConditionManager.GetAll( to.RowId, forEditView );

            //get entry conditions
            List <ConditionProfile> list = Entity_ConditionProfileManager.GetAll(to.RowId, true);

            //??actions
            if (list != null && list.Count > 0)
            {
                foreach (ConditionProfile item in list)
                {
                    to.ConditionProfiles.Add(item);

                    if (item.ConnectionProfileTypeId == Entity_ConditionProfileManager.ConnectionProfileType_Requirement)
                    {
                        to.Requires.Add(item);
                    }
                    else if (item.ConnectionProfileTypeId == Entity_ConditionProfileManager.ConnectionProfileType_Recommendation)
                    {
                        to.Recommends.Add(item);
                    }
                    else if (item.ConnectionProfileTypeId == Entity_ConditionProfileManager.ConnectionProfileType_EntryCondition)
                    {
                        to.EntryCondition.Add(item);
                    }
                    else if (item.ConnectionProfileTypeId == Entity_ConditionProfileManager.ConnectionProfileType_Corequisite)
                    {
                        to.Corequisite.Add(item);
                    }
                    else if (item.ConnectionProfileTypeId == Entity_ConditionProfileManager.ConnectionProfileType_Renewal)
                    {
                        to.Renewal.Add(item);
                    }
                    else
                    {
                        EmailManager.NotifyAdmin("Unexpected Condition Profile for Condition Manifest", string.Format("conditionManifestId: {0}, ConditionProfileTypeId: {1}", to.Id, item.ConnectionProfileTypeId));
                    }
                }
                //LoggingHelper.DoTrace( 5, "Unexpected Condition Profiles found for Condition Manifest. " + string.Format( "conditionManifestId: {0}, Count: {1}", to.Id, list.Count ) );
            }
        }
        }         //

        public static void MapFromDB(DBEntity input, ThisEntity output, bool gettingAll = true)
        {
            output.Id            = input.Id;
            output.RowId         = input.RowId;
            output.EntityStateId = input.EntityStateId;
            output.Name          = input.Name;
            output.Description   = input.Description;
            output.CTID          = input.CTID;

            if (input.Created != null)
            {
                output.Created = ( DateTime )input.Created;
            }
            if (input.LastUpdated != null)
            {
                output.LastUpdated = ( DateTime )input.LastUpdated;
            }
            if (IsGuidValid(input.OwningAgentUid))
            {
                output.OwningAgentUid     = ( Guid )input.OwningAgentUid;
                output.OwningOrganization = OrganizationManager.GetForSummary(output.OwningAgentUid);

                //get roles
                OrganizationRoleProfile orp = Entity_AgentRelationshipManager.AgentEntityRole_GetAsEnumerationFromCSV(output.RowId, output.OwningAgentUid);
                output.OwnerRoles = orp.AgentRole;
            }
            //
            output.OrganizationRole = Entity_AgentRelationshipManager.AgentEntityRole_GetAll_ToEnumeration(output.RowId, true);
            //

            //get related ....
            var relatedEntity = EntityManager.GetEntity(output.RowId, false);

            if (relatedEntity != null && relatedEntity.Id > 0)
            {
                output.EntityLastUpdated = relatedEntity.LastUpdated;
            }

            //
            output.SubjectWebpage       = input.SubjectWebpage;
            output.CredentialRegistryId = input.CredentialRegistryId ?? "";

            output.LifecycleStatusType = string.IsNullOrWhiteSpace(input.LifecycleStatusType) ? "lifecycle:Active" : input.LifecycleStatusType;
            //output.CodedNotation = input.CodedNotation;
            //20-12-16 changed to a string as partial dates are possible
            if (!string.IsNullOrWhiteSpace(input.StartDate))
            {
                output.StartDate = input.StartDate;
            }
            else
            {
                output.StartDate = "";
            }
            //
            if (!string.IsNullOrWhiteSpace(input.EndDate))
            {
                output.EndDate = input.EndDate;
            }
            else
            {
                output.EndDate = "";
            }

            //derived from ....

            //get json and expand
            output.IdentifierJson        = input.IdentifierJson;
            output.TransferValueJson     = input.TransferValueJson;
            output.TransferValueFromJson = input.TransferValueFromJson;
            output.TransferValueForJson  = input.TransferValueForJson;
            //
            if (!string.IsNullOrWhiteSpace(output.IdentifierJson))
            {
                output.Identifier = JsonConvert.DeserializeObject <List <Entity_IdentifierValue> >(output.IdentifierJson);
            }
            if (!string.IsNullOrWhiteSpace(output.TransferValueJson))
            {
                output.TransferValue = JsonConvert.DeserializeObject <List <ValueProfile> >(output.TransferValueJson);
            }


            if (!gettingAll)
            {
                return;
            }

            //the top level object may not be enough. First need to confirm if reference lopps and asmts can have detail pages.
            if (!string.IsNullOrWhiteSpace(output.TransferValueFromJson))
            {
                output.TransferValueFrom = JsonConvert.DeserializeObject <List <TopLevelObject> >(output.TransferValueFromJson);
                var lopps = output.TransferValueFrom.Where(s => s.EntityTypeId == 7).ToList();
                foreach (var item in lopps)
                {
                    output.TransferValueFromLopp.Add(LearningOpportunityManager.GetForDetail(item.Id));
                }
                var assmts = output.TransferValueFrom.Where(s => s.EntityTypeId == 3).ToList();
                foreach (var item in assmts)
                {
                    output.TransferValueFromAsmt.Add(AssessmentManager.GetForDetail(item.Id));
                }

                var creds = output.TransferValueFrom.Where(s => s.EntityTypeId == 1).ToList();
                foreach (var item in creds)
                {
                    output.TransferValueFromCredential.Add(CredentialManager.GetForDetail(item.Id));
                }
            }
            //
            if (!string.IsNullOrWhiteSpace(output.TransferValueForJson))
            {
                output.TransferValueFor = JsonConvert.DeserializeObject <List <TopLevelObject> >(output.TransferValueForJson);
                var lopps = output.TransferValueFor.Where(s => s.EntityTypeId == 7).ToList();
                foreach (var item in lopps)
                {
                    output.TransferValueForLopp.Add(LearningOpportunityManager.GetForDetail(item.Id));
                }
                var assmts = output.TransferValueFor.Where(s => s.EntityTypeId == 3).ToList();
                foreach (var item in assmts)
                {
                    output.TransferValueForAsmt.Add(AssessmentManager.GetForDetail(item.Id));
                }

                var creds = output.TransferValueFor.Where(s => s.EntityTypeId == 1).ToList();
                foreach (var item in creds)
                {
                    output.TransferValueForCredential.Add(CredentialManager.GetForDetail(item.Id));
                }
            }


            //this should be a summary level, not the full TVP
            output.DerivedFrom = Entity_TransferValueProfileManager.GetAll(output.RowId);

            //
            List <ProcessProfile> processes = Entity_ProcessProfileManager.GetAll(output.RowId);

            foreach (ProcessProfile item in processes)
            {
                if (item.ProcessTypeId == Entity_ProcessProfileManager.DEV_PROCESS_TYPE)
                {
                    output.DevelopmentProcess.Add(item);
                }

                else
                {
                    //unexpected
                }
            }
        }
예제 #7
0
        public static void MapFromDB_Basic(DBEntity input, ThisEntity output, bool includingComponents)
        {
            output.Id            = input.Id;
            output.RowId         = input.RowId;
            output.EntityStateId = ( int )(input.EntityStateId ?? 1);
            output.Name          = input.Name;
            output.Description   = input.Description == null ? "" : input.Description;
            output.CTID          = input.CTID;
            if (IsGuidValid(input.OwningAgentUid))
            {
                output.OwningAgentUid     = ( Guid )input.OwningAgentUid;
                output.OwningOrganization = OrganizationManager.GetForSummary(output.OwningAgentUid);
                output.OrganizationId     = output.OwningOrganization.Id;
                //get roles
                OrganizationRoleProfile orp = Entity_AgentRelationshipManager.AgentEntityRole_GetAsEnumerationFromCSV(output.RowId, output.OwningAgentUid);
                output.OwnerRoles = orp.AgentRole;
            }
            //
            output.OrganizationRole = Entity_AgentRelationshipManager.AgentEntityRole_GetAll_ToEnumeration(output.RowId, true);
            //
            output.SubjectWebpage = input.SubjectWebpage;
            if (IsValidDate(input.Created))
            {
                output.Created = ( DateTime )input.Created;
            }
            if (IsValidDate(input.LastUpdated))
            {
                output.LastUpdated = ( DateTime )input.LastUpdated;
            }



            if (string.IsNullOrWhiteSpace(output.CTID) || output.EntityStateId < 3)
            {
                output.IsReferenceVersion = true;
                return;
            }
            //=====
            var relatedEntity = EntityManager.GetEntity(output.RowId, false);

            if (relatedEntity != null && relatedEntity.Id > 0)
            {
                output.EntityLastUpdated = relatedEntity.LastUpdated;
            }

            //components
            if (includingComponents)
            {
                //
                output.ProgressionModelURI = input.HasProgressionModel;
                if (!string.IsNullOrWhiteSpace(output.ProgressionModelURI) && includingComponents)
                {
                    //ensure this is not called always from ProgressionModel/CS or will get a stack overflow
                    output.HasProgressionModel = ConceptSchemeManager.GetByCtid(output.ProgressionModelURI);
                }

                //include conditions
                //to.HasPart = PathwayComponentManager.GetAllForPathway( to.CTID, PathwayComponentManager.componentActionOfDeep );
                //actual may be better to do through Entity_PathwayComponent
                //	but only destination component is under pathway
                //will there be an issue with recursion?
                //compare
                //one less that parts???
                //var parts1 = PathwayComponentManager.GetAllForPathway( to.CTID, PathwayComponentManager.componentActionOfDeep );
                //and
                var parts = Entity_PathwayComponentManager.GetAll(output.RowId, PathwayComponentManager.componentActionOfDeep);
                //may want to split out here, do in context

                foreach (var item in parts)
                {
                    if (item.ComponentRelationshipTypeId == PathwayComponent.PathwayComponentRelationship_HasDestinationComponent)
                    {
                        output.HasDestinationComponent.Add(item);
                    }
                    else if (item.ComponentRelationshipTypeId == PathwayComponent.PathwayComponentRelationship_HasChild)
                    {
                        output.HasChild.Add(item);
                    }
                }
                //now get a unique list
                //var parts = to.HasPart;
                output.HasPart = new List <PathwayComponent>();
                foreach (var item in parts)
                {
                    int index = output.HasPart.FindIndex(a => a.CTID == item.CTID);
                    if (index == -1)
                    {
                        output.HasPart.Add(item);
                    }
                }
            }
        }         //
예제 #8
0
        public static void MapFromDB(DBEntity from, ThisEntity to, bool includingComponents = true)
        {
            to.Id             = from.Id;
            to.RowId          = from.RowId;
            to.EntityStateId  = from.EntityStateId;
            to.OrganizationId = from.OrgId;
            to.Name           = from.Name;
            to.Description    = from.Description;

            to.IsProgressionModel = from.IsProgressionModel == null ? false : (bool)from.IsProgressionModel;
            to.CTID   = from.CTID.ToLower();
            to.Source = from.Source;

            to.PublicationStatusType = from.PublicationStatusType;
            to.CredentialRegistryId  = from.CredentialRegistryId;
            if (to.OrganizationId > 0)
            {
                to.OwningOrganization = OrganizationManager.GetForSummary(to.OrganizationId);

                to.OwningAgentUid = to.OwningOrganization.RowId;
                //get roles- not sure. Can have own and offer
                //OrganizationRoleProfile orp = Entity_AgentRelationshipManager.AgentEntityRole_GetAsEnumerationFromCSV( to.RowId, to.OwningAgentUid );
                //to.OwnerRoles = orp.AgentRole;
                //if ( to.OwnerRoles.HasItems() == false )
                //{
                //	EnumeratedItem ei = Entity_AgentRelationshipManager.GetAgentRole( "Owned By" );
                //	if ( ei == null || ei.Id == 0 )
                //	{
                //		//messages.Add( string.Format( "The organization role: {0} is not valid", "OwnedBy" ) );
                //	}
                //	else
                //	{
                //		to.OwnerRoles.Items.Add( ei );
                //	}
                //}
            }
            //
            to.OrganizationRole = Entity_AgentRelationshipManager.AgentEntityRole_GetAll_ToEnumeration(to.RowId, true);
            //
            if (from.ConceptScheme_Concept != null && from.ConceptScheme_Concept.Any())
            {
                foreach (var item in from.ConceptScheme_Concept)
                {
                    to.HasConcepts.Add(new Models.Common.Concept()
                    {
                        Id           = item.Id,
                        CTID         = item.CTID,
                        PrefLabel    = item.PrefLabel,
                        Definition   = item.Definition,
                        IsTopConcept = item.IsTopConcept ?? false
                    });
                }
            }
            //
            if (includingComponents)
            {
                //how to know if this is a progression model? Or just do get anyway
                to.Pathways   = PathwayManager.GetAllForProgressionModel(to.CTID);
                to.HasPathway = to.Pathways.Select(m => m.CTID).ToList();
            }
            //
            if (IsValidDate(from.Created))
            {
                to.Created = ( DateTime )from.Created;
            }
            if (IsValidDate(from.LastUpdated))
            {
                to.LastUpdated = ( DateTime )from.LastUpdated;
            }
        }
예제 #9
0
        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.ConceptScheme
                                        .FirstOrDefault(s => s.CredentialRegistryId == envelopeId ||
                                                        (s.CTID == ctid)
                                                        );

                    if (efEntity != null && efEntity.Id > 0)
                    {
                        Guid rowId = efEntity.RowId;
                        if (efEntity.OrgId > 0)
                        {
                            Organization org = OrganizationManager.GetForSummary(efEntity.OrgId);
                            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(" ConceptScheme. 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.ConceptScheme.Remove( efEntity );
                        efEntity.EntityStateId = 0;
                        efEntity.LastUpdated   = System.DateTime.Now;
                        int count = context.SaveChanges();
                        if (count > 0)
                        {
                            new ActivityManager().SiteActivityAdd(new SiteActivity()
                            {
                                ActivityType     = "ConceptSchemeProfile",
                                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_CONCEPT_SCHEME, 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 ConceptScheme cannot be deleted as it is being referenced by other items. These associations must be removed before this ConceptScheme can be deleted.";
                    }
                }
            }
            return(isValid);
        }
예제 #10
0
        public static void MapFromDB(DBEntity input, ThisEntity output,
                                     bool includingParts)
        {
            output.Id                    = input.Id;
            output.RowId                 = input.RowId;
            output.EntityStateId         = input.EntityStateId;
            output.Description           = input.Description == null ? "" : input.Description;
            output.CTID                  = input.CTID;
            output.DataSuppressionPolicy = input.DataSuppressionPolicy;
            output.SubjectIdentification = input.SubjectIdentification;
            output.Source                = GetUrlData(input.Source);
            //
            if (IsGuidValid(input.DataProviderUID))
            {
                output.DataProviderUID = ( Guid )input.DataProviderUID;
                output.DataProvider    = OrganizationManager.GetForSummary(output.DataProviderUID);
            }
            //
            output.InstructionalProgramType = Reference_FrameworksManager.FillEnumeration(output.RowId, CodesManager.PROPERTY_CATEGORY_CIP);
            //
            if (input.DistributionFile != null)
            {
                var list = input.DistributionFile.Split('|');
                foreach (var item in list)
                {
                    if (!string.IsNullOrWhiteSpace(item))
                    {
                        output.DistributionFile.Add(item);
                    }
                }
            }
            else
            {
                output.DistributionFile = new List <string>();
            }

            //
            if (IsValidDate(input.Created))
            {
                output.Created = ( DateTime )input.Created;
            }
            if (IsValidDate(input.LastUpdated))
            {
                output.LastUpdated = ( DateTime )input.LastUpdated;
            }


            if (string.IsNullOrWhiteSpace(output.CTID) || output.EntityStateId < 3)
            {
                output.IsReferenceVersion = true;
                return;
            }
            //=====
            var relatedEntity = EntityManager.GetEntity(output.RowId, false);

            if (relatedEntity != null && relatedEntity.Id > 0)
            {
                output.EntityLastUpdated = relatedEntity.LastUpdated;
            }

            //components
            if (includingParts)
            {
                var processProfiles = Entity_ProcessProfileManager.GetAll(input.RowId);
                foreach (ProcessProfile item in processProfiles)
                {
                    if (item.ProcessTypeId == Entity_ProcessProfileManager.ADMIN_PROCESS_TYPE)
                    {
                        output.AdministrationProcess.Add(item);
                    }
                }
                //
                output.Jurisdiction = Entity_JurisdictionProfileManager.Jurisdiction_GetAll(output.RowId);
                //get DataSetTimePeriod
                output.DataSetTimePeriod = DataSetTimeFrameManager.GetAll(output.Id);
            }
        }         //