Exemplo n.º 1
0
        public static List <OrganizationAssertion> GetAllCombined2(int orgId, int maxRecords = 10)
        {
            //Organization org = OrganizationManager.GetForSummary( orgId, true );
            //return GetAllCombined( org.RowId, maxRecords );
            OrganizationAssertion        orp  = new OrganizationAssertion();
            List <OrganizationAssertion> list = new List <OrganizationAssertion>();
            EnumeratedItem eitem = new EnumeratedItem();

            Guid   prevTargetUid  = new Guid();
            string prevRoleSource = "";
            int    prevRoleTypeId = 0;
            Entity agentEntity    = EntityManager.GetEntity(2, orgId);

            using (var context = new ViewContext())
            {
                List <Views.Organization_CombinedQAPerformed> agentRoles = context.Organization_CombinedQAPerformed
                                                                           .Where(s => s.OrgUid == agentEntity.EntityUid &&
                                                                                  s.IsQARole == true &&
                                                                                  s.TargetEntityStateId > 1)
                                                                           .OrderBy(s => s.TargetEntityTypeId)
                                                                           .ThenBy(s => s.TargetEntityBaseId)
                                                                           .ThenBy(s => s.TargetEntityName)
                                                                           .ThenBy(s => s.AgentToSourceRelationship)
                                                                           .ThenBy(s => s.roleSource)
                                                                           .Take(maxRecords)
                                                                           .ToList();

                foreach (var entity in agentRoles)
                {
                    //loop until change in entity type?
                    if (prevTargetUid != entity.TargetEntityUid)
                    {
                        //handle previous fill
                        if (IsGuidValid(prevTargetUid) && orp.AgentAssertion.Items.Count > 0)
                        {
                            list.Add(orp);
                        }

                        prevTargetUid  = entity.TargetEntityUid;
                        prevRoleSource = entity.roleSource;
                        prevRoleTypeId = entity.RelationshipTypeId;

                        orp          = new OrganizationAssertion();
                        orp.Id       = 0;
                        orp.ParentId = agentEntity.EntityBaseId;


                        orp.AgentAssertion          = CodesManager.GetEnumeration(CodesManager.PROPERTY_CATEGORY_ENTITY_AGENT_ROLE);
                        orp.AgentAssertion.ParentId = entity.OrgId;

                        orp.AgentAssertion.Items       = new List <EnumeratedItem>();
                        orp.TargetEntityType           = entity.TargetEntityType;
                        orp.TargetEntityBaseId         = ( int )entity.TargetEntityBaseId;
                        orp.TargetEntityName           = entity.TargetEntityName;
                        orp.TargetEntitySubjectWebpage = entity.TargetEntitySubjectWebpage;
                        orp.TargetEntityStateId        = ( int )entity.TargetEntityStateId;
                        orp.AgentToSourceRelationship  = entity.AgentToSourceRelationship;
                        //if ( entity.TargetEntityTypeId == CodesManager.ENTITY_TYPE_CREDENTIAL )
                        //{
                        //	//17-08-27 mp - just get the basic for each entity!
                        //	orp.TargetCredential = CredentialManager.GetBasic( entity.TargetEntityBaseId ?? 0 );

                        //}
                        //else if ( entity.TargetEntityTypeId == CodesManager.ENTITY_TYPE_ORGANIZATION )
                        //{
                        //	//orp.TargetOrganization = OrganizationManager.GetBasics( entity.TargetEntityUid );
                        //	orp.TargetOrganization.Id = entity.TargetEntityBaseId ?? 0;
                        //	orp.TargetOrganization.RowId = entity.TargetEntityUid;
                        //	orp.TargetOrganization.Name = entity.TargetEntityName;

                        //	orp.TargetOrganization.Description = entity.TargetEntityDescription;
                        //	orp.TargetOrganization.EntityStateId = entity.TargetEntityStateId ?? 2;
                        //	orp.TargetOrganization.SubjectWebpage = entity.TargetEntitySubjectWebpage;
                        //	orp.TargetOrganization.ImageUrl = entity.TargetEntityImageUrl;
                        //}
                        //else if ( entity.TargetEntityTypeId == CodesManager.ENTITY_TYPE_ASSESSMENT_PROFILE )
                        //{
                        //	orp.TargetAssessment = AssessmentManager.GetBasic( entity.TargetEntityBaseId ?? 0 );
                        //}
                        //else if ( entity.TargetEntityTypeId == CodesManager.ENTITY_TYPE_LEARNING_OPP_PROFILE )
                        //{
                        //	orp.TargetLearningOpportunity = LearningOpportunityManager.GetBasic( entity.TargetEntityBaseId ?? 0 );
                        //}
                    }

                    //check for a change in roleSource
                    if (prevRoleSource != entity.roleSource)
                    {
                        if (prevRoleTypeId == entity.RelationshipTypeId)
                        {
                            //add as matched assertion
                            //may want to delay addding enumeration item
                            continue;
                        }
                    }
                    //add relationship
                    eitem = new EnumeratedItem();
                    //??
                    eitem.Id = entity.RelationshipTypeId;

                    //eitem.RowId = entity.RowId.ToString();
                    //not used here
                    eitem.RecordId = entity.RelationshipTypeId;
                    //eitem.CodeId = entity.RelationshipTypeId;

                    prevRoleTypeId = entity.RelationshipTypeId;
                    prevRoleSource = entity.roleSource;

                    eitem.Name       = entity.AgentToSourceRelationship;
                    eitem.SchemaName = entity.ReverseSchemaTag;

                    orp.AgentAssertion.Items.Add(eitem);
                }
                //check for remaining
                if (IsGuidValid(prevTargetUid) && orp.AgentAssertion.Items.Count > 0)
                {
                    list.Add(orp);
                }
            }
            return(list);
        }
Exemplo n.º 2
0
        //public static List<OrganizationRoleProfile> GetAll( Guid agentUid )
        //{
        //    OrganizationRoleProfile orp = new OrganizationRoleProfile();
        //    List<OrganizationRoleProfile> list = new List<OrganizationRoleProfile>();
        //    EnumeratedItem eitem = new EnumeratedItem();

        //    Guid prevTargetUid = new Guid();
        //    Entity agentEntity = EntityManager.GetEntity( agentUid );

        //    using ( var context = new ViewContext() )
        //    {
        //        List<DBEntitySummary> agentRoles = context.Entity_Assertion_Summary
        //            .Where( s => s.AgentUid == agentUid
        //                 && s.IsQARole == true
        //                 && s.TargetEntityStateId > 1 )
        //                 .OrderBy( s => s.TargetEntityTypeId )
        //                 .ThenBy( s => s.TargetEntityName )
        //                 .ThenBy( s => s.AgentToSourceRelationship )
        //            .ToList();

        //        foreach ( DBEntitySummary entity in agentRoles )
        //        {
        //            //loop until change in entity type?
        //            if ( prevTargetUid != entity.TargetEntityUid )
        //            {
        //                //handle previous fill
        //                if ( IsGuidValid( prevTargetUid ) && orp.AgentRole.Items.Count > 0 )
        //                    list.Add( orp );

        //                prevTargetUid = entity.TargetEntityUid;

        //                orp = new OrganizationRoleProfile();
        //                orp.Id = 0;
        //                orp.ParentId = agentEntity.EntityBaseId;
        //                orp.ParentTypeId = agentEntity.EntityTypeId;

        //                orp.ProfileSummary = entity.TargetEntityName;

        //                orp.AgentRole = CodesManager.GetEnumeration( CodesManager.PROPERTY_CATEGORY_ENTITY_AGENT_ROLE );
        //                orp.AgentRole.ParentId = entity.OrgId;

        //                orp.AgentRole.Items = new List<EnumeratedItem>();
        //                orp.SourceEntityType = entity.TargetEntityType;

        //                if ( entity.TargetEntityTypeId == CodesManager.ENTITY_TYPE_CREDENTIAL )
        //                {
        //                    //17-08-27 mp - just get the basic for each entity!
        //                    orp.TargetCredential = CredentialManager.GetBasic( entity.TargetEntityBaseId ?? 0 );

        //                }
        //                else if ( entity.TargetEntityTypeId == CodesManager.ENTITY_TYPE_ORGANIZATION )
        //                {
        //                    orp.TargetOrganization.Id = entity.TargetEntityBaseId ?? 0;
        //                    orp.TargetOrganization.RowId = entity.TargetEntityUid;
        //                    orp.TargetOrganization.Name = entity.TargetEntityName;

        //                    orp.TargetOrganization.Description = entity.TargetEntityDescription;
        //                    orp.TargetOrganization.SubjectWebpage = entity.TargetEntitySubjectWebpage;
        //                    orp.TargetOrganization.ImageUrl = entity.TargetEntityImageUrl;
        //                }
        //                else if ( entity.TargetEntityTypeId == CodesManager.ENTITY_TYPE_ASSESSMENT_PROFILE )
        //                {
        //                    orp.TargetAssessment = AssessmentManager.GetBasic( entity.TargetEntityBaseId ?? 0 );
        //                }
        //                else if ( entity.TargetEntityTypeId == CodesManager.ENTITY_TYPE_LEARNING_OPP_PROFILE )
        //                {
        //                    orp.TargetLearningOpportunity = LearningOpportunityManager.GetBasic( entity.TargetEntityBaseId ?? 0 );
        //                }
        //            }

        //            //add relationship
        //            eitem = new EnumeratedItem();
        //            //??
        //            eitem.Id = entity.AssertionTypeId;
        //            //eitem.RowId = entity.RowId.ToString();
        //            //not used here
        //            eitem.RecordId = entity.AssertionTypeId;
        //            eitem.CodeId = entity.AssertionTypeId;

        //            eitem.Name = entity.AgentToSourceRelationship;
        //            eitem.SchemaName = entity.ReverseSchemaTag;
        //            //eitem.Selected = true;
        //            //if ( ( bool )entity.IsQARole )
        //            //{
        //            //    eitem.IsSpecialValue = true;
        //            //    if ( IsDevEnv() )
        //            //        eitem.Name += " (QA)";
        //            //}

        //            orp.AgentRole.Items.Add( eitem );

        //        }
        //        //check for remaining
        //        if ( IsGuidValid( prevTargetUid ) && orp.AgentRole.Items.Count > 0 )
        //            list.Add( orp );

        //    }
        //    return list;

        //} //

        //
        public static List <OrganizationAssertion> GetAllCombined(int orgId, int maxRecords = 10)
        {
            //Organization org = OrganizationManager.GetForSummary( orgId, true );
            //return GetAllCombined( org.RowId, maxRecords );
            OrganizationAssertion        orp  = new OrganizationAssertion();
            List <OrganizationAssertion> list = new List <OrganizationAssertion>();
            EnumeratedItem eitem         = new EnumeratedItem();
            int            records       = maxRecords * 2;
            Guid           prevTargetUid = new Guid();

            string prevRoleSource = "";
            //string currRoleSource = "";
            int    prevRoleTypeId = 0;
            Entity agentEntity    = EntityManager.GetEntity(2, orgId);

            using (var context = new ViewContext())
            {
                List <Views.Organization_CombinedQAPerformed> agentRoles = context.Organization_CombinedQAPerformed
                                                                           .Where(s => s.OrgUid == agentEntity.EntityUid &&
                                                                                  s.IsQARole == true &&
                                                                                  s.TargetEntityStateId > 1)
                                                                           .OrderBy(s => s.TargetEntityTypeId)
                                                                           .ThenBy(s => s.TargetEntityBaseId)
                                                                           .ThenBy(s => s.TargetEntityName)
                                                                           .ThenBy(s => s.AgentToSourceRelationship)
                                                                           .ThenBy(s => s.roleSource)
                                                                           .Take(records)
                                                                           .ToList();

                foreach (var entity in agentRoles)
                {
                    if (entity.TargetEntityUid == prevTargetUid && entity.RelationshipTypeId == prevRoleTypeId)
                    {
                        continue;
                    }
                    //loop until change in entity type?
                    //if ( prevTargetUid != entity.TargetEntityUid )

                    //handle previous fill
                    //if ( IsGuidValid( prevTargetUid ) && orp.AgentAssertion.Items.Count > 0 )
                    //	list.Add( orp );

                    prevTargetUid  = entity.TargetEntityUid;
                    prevRoleSource = entity.roleSource;
                    prevRoleTypeId = entity.RelationshipTypeId;

                    orp          = new OrganizationAssertion();
                    orp.Id       = 0;
                    orp.ParentId = agentEntity.EntityBaseId;


                    orp.AgentAssertion          = CodesManager.GetEnumeration(CodesManager.PROPERTY_CATEGORY_ENTITY_AGENT_ROLE);
                    orp.AgentAssertion.ParentId = entity.OrgId;

                    orp.AgentAssertion.Items       = new List <EnumeratedItem>();
                    orp.TargetEntityType           = entity.TargetEntityType;
                    orp.TargetEntityBaseId         = ( int )entity.TargetEntityBaseId;
                    orp.TargetEntityName           = entity.TargetEntityName;
                    orp.TargetEntitySubjectWebpage = entity.TargetEntitySubjectWebpage;
                    orp.TargetEntityStateId        = ( int )entity.TargetEntityStateId;
                    orp.AgentToSourceRelationship  = entity.AgentToSourceRelationship;
                    //20-10-10 - targetCTID was not being populated
                    orp.TargetCTID = entity.AgentCTID;
                    if (list.Count() < maxRecords)
                    {
                        list.Add(orp);
                    }


                    //check for a change in roleSource
                    //if ( prevRoleSource != entity.roleSource )
                    //{
                    //    if ( prevRoleTypeId == entity.RelationshipTypeId )
                    //    {
                    //        //add as matched assertion
                    //        //may want to delay addding enumeration item
                    //        continue;
                    //    }
                    //}
                }
                //check for remaining
                //if ( IsGuidValid( prevTargetUid ) && orp.AgentAssertion.Items.Count > 0 )
                //    list.Add( orp );
            }
            return(list);
        }