예제 #1
0
        public static TopLevelObject GetEntityAsTopLevelObject(Guid uid)
        {
            TopLevelObject tlo = new TopLevelObject();

            var entity = EntityManager.GetEntity(uid, false);

            if (entity == null || entity.Id == 0)
            {
                return(null);
            }
            //
            if (entity.EntityTypeId == CodesManager.ENTITY_TYPE_CREDENTIAL)
            {
                //actually should return some type info
                tlo = CredentialManager.GetBasic(entity.EntityBaseId);
                tlo.EntityTypeId = entity.EntityTypeId;
            }
            else if (entity.EntityTypeId == CodesManager.ENTITY_TYPE_ORGANIZATION)
            {
                tlo = OrganizationManager.GetBasics(entity.EntityUid);
                tlo.EntityTypeId = entity.EntityTypeId;
            }
            else if (entity.EntityTypeId == CodesManager.ENTITY_TYPE_ASSESSMENT_PROFILE)
            {
                tlo = AssessmentManager.GetBasic(entity.EntityBaseId);
                tlo.EntityTypeId = entity.EntityTypeId;
            }
            else if (entity.EntityTypeId == CodesManager.ENTITY_TYPE_LEARNING_OPP_PROFILE)
            {
                tlo = LearningOpportunityManager.GetBasic(entity.EntityBaseId);
                tlo.EntityTypeId = entity.EntityTypeId;
            }
            else if (entity.EntityTypeId == CodesManager.ENTITY_TYPE_PATHWAY)
            {
                tlo = PathwayManager.GetBasic(entity.EntityBaseId);
                tlo.EntityTypeId = entity.EntityTypeId;
            }
            else if (entity.EntityTypeId == CodesManager.ENTITY_TYPE_PATHWAY_COMPONENT)
            {
                tlo = PathwayComponentManager.Get(entity.EntityBaseId);
                tlo.EntityTypeId = entity.EntityTypeId;
            }
            else if (entity.EntityTypeId == CodesManager.ENTITY_TYPE_PATHWAY_SET)
            {
                tlo = PathwaySetManager.Get(entity.EntityBaseId);
                tlo.EntityTypeId = entity.EntityTypeId;
            }
            else if (entity.EntityTypeId == CodesManager.ENTITY_TYPE_TRANSFER_VALUE_PROFILE)
            {
                tlo = TransferValueProfileManager.Get(entity.EntityBaseId);
                tlo.EntityTypeId = entity.EntityTypeId;
            }
            return(tlo);
        }
예제 #2
0
        }         //

        public static List <OrganizationRoleProfile> GetAllCombinedForOrganization(Guid agentUid, ref int totalRecords, int maxRecords = 25)
        {
            OrganizationRoleProfile        orp  = new OrganizationRoleProfile();
            List <OrganizationRoleProfile> list = new List <OrganizationRoleProfile>();
            EnumeratedItem eitem = new EnumeratedItem();

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

            if (UtilityManager.GetAppKeyValue("envType") == "production")
            {
                //show all for now in production
                //maxRecords = 0;
            }
            using (var context = new ViewContext())
            {
                //first check how long this step takes
                DateTime start = DateTime.Now;
                LoggingHelper.DoTrace(4, "GetAllCombinedForOrganization start");
                List <Views.Organization_CombinedQAPerformed> agentRoles = context.Organization_CombinedQAPerformed
                                                                           .Where(s => s.OrgUid == agentUid &&
                                                                                  s.IsQARole == true &&
                                                                                  s.TargetEntityStateId > 1)
                                                                           .OrderBy(s => s.TargetEntityTypeId)
                                                                           .ThenBy(s => s.TargetOwningOrganizationName)
                                                                           .ThenBy(s => s.TargetEntityName)
                                                                           .ThenBy(s => s.AgentToSourceRelationship)
                                                                           .ThenBy(s => s.roleSource)
                                                                           .ToList();

                DateTime end     = DateTime.Now;
                var      elasped = end.Subtract(start).TotalSeconds;
                LoggingHelper.DoTrace(4, string.Format("GetAllCombinedForOrganization retrieve seconds: {0}", elasped));

                if (agentRoles != null && agentRoles.Count() > 0)
                {
                    //
                    totalRecords = agentRoles.Count();
                    //may want a fudge factor?
                }
                int cntr = 0;
                foreach (var entity in agentRoles)
                {
                    cntr++;
                    //loop until change in entity type?
                    if (prevTargetUid != entity.TargetEntityUid)
                    {
                        //handle previous fill
                        if (IsGuidValid(prevTargetUid) && prevRoleTypeId > 0)
                        {
                            orp.AgentRole.Items.Add(eitem);
                            list.Add(orp);
                            if (maxRecords > 0 && cntr >= maxRecords)
                            {
                                break;
                            }
                        }

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

                        orp = new OrganizationRoleProfile
                        {
                            Id             = 0,
                            ParentId       = agentEntity.EntityBaseId,
                            ParentTypeId   = agentEntity.EntityTypeId,
                            ProfileSummary = entity.TargetEntityName,

                            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 = 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.Image          = 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);
                        }
                    }

                    /* either first one for new target
                     * or change in relationship
                     * or change in role source
                     */

                    if (prevRoleTypeId == entity.RelationshipTypeId)
                    {
                        if (prevRoleSource != entity.roleSource)
                        {
                            if (entity.roleSource == "DirectAssertion")
                            {
                                eitem.IsDirectAssertion = true;
                            }
                            else
                            {
                                eitem.IsIndirectAssertion = true;
                            }

                            //add previous
                            //could get a dup if there is an immediate chg in target,
                            //orp.AgentRole.Items.Add( eitem );
                            prevRoleSource = entity.roleSource;

                            continue;
                        }
                    }
                    else
                    {
                        //if not equal, add previous, and initialize next one (fall thru)
                        orp.AgentRole.Items.Add(eitem);
                    }

                    //add relationship
                    eitem = new EnumeratedItem
                    {
                        Id         = entity.RelationshipTypeId,
                        Name       = entity.AgentToSourceRelationship,
                        SchemaName = entity.ReverseSchemaTag,
                        IsQAValue  = true
                    };
                    //eitem.CodeId = entity.RelationshipTypeId;

                    prevRoleTypeId = entity.RelationshipTypeId;
                    prevRoleSource = entity.roleSource;
                    if (entity.roleSource == "DirectAssertion")
                    {
                        eitem.IsDirectAssertion = true;
                    }
                    else
                    {
                        eitem.IsIndirectAssertion = true;
                    }

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

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

                DateTime listEnd = DateTime.Now;
                elasped = listEnd.Subtract(end).TotalSeconds;
                LoggingHelper.DoTrace(4, string.Format("GetAllCombinedForOrganization loaded list seconds: {0}", elasped));
            }
            return(list);
        } //