}//

        /// <summary>
        /// quick search for subjects
        /// </summary>
        /// <param name="entityTypeId"></param>
        /// <param name="keyword"></param>
        /// <param name="maxTerms"></param>
        /// <returns></returns>
        public static List <object> QuickSearch_Subjects(int entityTypeId, string keyword, int maxTerms = 0)
        {
            List <object> list = new List <object>();

            keyword = keyword.Trim();

            if (maxTerms == 0)
            {
                maxTerms = 50;
            }

            using (var context = new ViewContext())
            {
                list = context.Entity_Subjects.Where(s => s.EntityTypeId == entityTypeId && s.Subject.Contains(keyword)).OrderBy(s => s.Subject).Take(maxTerms).Select(x => x.Subject).Distinct().ToList().Cast <object>().ToList();

                //if ( results != null && results.Count > 0 )
                //{
                //    string prev = "";

                //    foreach ( Entity_Subjects item in results )
                //    {
                //        if ( prev != item.Subject )
                //        {
                //            list.Add( item.Subject );
                //            prev = item.Subject;
                //        }
                //    }
                //}
            }

            return(list);
        } //
        /// <summary>
        /// Get all learning opportunties where the source learning opportunity is a part
        /// Steps: 1 use the learning opportunity Id to get All the Entity_LearningOpp, use the entity Uses the parent Guid to retrieve the related Entity, then uses the EntityId to retrieve the child objects.
        /// </summary>
        /// <param name="parentUid"></param>
        /// <returns></returns>
        public static List <ThisEntity> LearningOpps_GetAll_IsPart(int learningOpportunityId, int parentTypeId)
        {
            List <ThisEntity> list   = new List <ThisEntity>();
            ThisEntity        entity = new ThisEntity();

            try
            {
                using (var context = new ViewContext())
                {
                    var results = context.Entity_LearningOpportunity_IsPartOfSummary
                                  .Where(s => s.LearningOpportunityId == learningOpportunityId &&
                                         s.EntityTypeId == parentTypeId)
                                  .OrderBy(s => s.EntityTypeId).ThenBy(s => s.ParentName)
                                  .ToList();

                    if (results != null && results.Count > 0)
                    {
                        foreach (Views.Entity_LearningOpportunity_IsPartOfSummary item in results)
                        {
                            entity = new ThisEntity();
                            //LearningOpportunityManager.Entity_ToMap( item.LearningOpportunity, entity, false, false );


                            list.Add(entity);
                        }
                    }
                    return(list);
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + string.Format(".LearningOpps_GetAll_IsPart. learningOpportunityId: {0}, parentTypeId: {1}. ", learningOpportunityId, parentTypeId));
            }
            return(list);
        }
        } //

        #endregion

        //

        public static CommonTotals SiteTotals_Get()
        {
            CommonTotals entity = new CommonTotals();

            using (var context = new ViewContext())
            {
                //21-01-05 mparsons - note that the view (SiteTotalsSummaries) states to no longer use it!!!!
                Views.SiteTotalsSummary item = context.SiteTotalsSummaries
                                               .SingleOrDefault(s => s.Id == 1);

                if (item != null && item.Id > 0)
                {
                    entity.TotalOrganizations        = GetField(item.TotalOrgs);
                    entity.TotalPartnerOrganizations = GetField(item.TotalDirectOrgs);
                    entity.TotalOtherOrganizations   = entity.TotalOrganizations - entity.TotalPartnerOrganizations;
                    entity.TotalQAOrganizations      = GetField(item.TotalQAOrgs);

                    entity.TotalEnteredCredentials = GetField(item.TotalEnteredCredentials);
                    entity.TotalPartnerCredentials = GetField(item.TotalPartnerCredentials);
                    entity.TotalPendingCredentials = GetField(item.TotalPendingCredentials);
                    entity.TotalDirectCredentials  = GetField(item.TotalDirectCredentials);
                    entity.TotalOtherOrganizations = entity.TotalPartnerCredentials - entity.TotalDirectCredentials;


                    entity.TotalCredentialsAtCurrentCtdl            = GetField(item.TotalCredentialsAtCurrentCtdl);
                    entity.TotalCredentialsToBeUpdatedToCurrentCtdl = GetField(item.TotalCredentialsToBeUpdatedToCurrentCtdl);
                }
            }

            return(entity);
        }
Beispiel #4
0
        public static Enumeration FillEnumeration(Guid parentUid, int categoryId)
        {
            Enumeration entity = new ThisEntity();

            entity = CodesManager.GetEnumeration(categoryId);

            entity.Items = new List <EnumeratedItem>();
            EnumeratedItem item = new EnumeratedItem();

            using (var context = new ViewContext())
            {
                List <EntityProperty_Summary> results = context.EntityProperty_Summary
                                                        .Where(s => s.EntityUid == parentUid &&
                                                               s.CategoryId == categoryId)
                                                        .OrderBy(s => s.CategoryId).ThenBy(s => s.SortOrder).ThenBy(s => s.Property)
                                                        .ToList();

                if (results != null && results.Count > 0)
                {
                    foreach (EntityProperty_Summary prop in results)
                    {
                        item          = new EnumeratedItem();
                        item.Id       = prop.PropertyValueId;
                        item.Value    = prop.PropertyValueId.ToString();
                        item.Selected = true;

                        item.Name       = prop.Property;
                        item.SchemaName = prop.PropertySchemaName;
                        entity.Items.Add(item);
                    }
                }
            }

            return(entity);
        }
Beispiel #5
0
        }        //

        public static Enumeration FillEnumeration(Guid parentUid, int categoryId)
        {
            Enumeration entity = new Enumeration();

            entity = CodesManager.GetEnumeration(categoryId);

            entity.Items = new List <EnumeratedItem>();
            EnumeratedItem item = new EnumeratedItem();

            using (var context = new ViewContext())
            {
                List <Views.Entity_ReferenceFramework_Summary> results = context.Entity_ReferenceFramework_Summary
                                                                         .Where(s => s.EntityUid == parentUid &&
                                                                                s.CategoryId == categoryId)
                                                                         .OrderBy(s => s.Name)
                                                                         .ToList();

                if (results != null && results.Count > 0)
                {
                    foreach (var prop in results)
                    {
                        item = new EnumeratedItem();
                        MapFromDB(prop, item);
                        entity.Items.Add(item);
                    }
                }

                return(entity);
            }
        }
        } //

        //public static List<string> QuickSearch_TextValue( int entityTypeId, int categoryId, string keyword, int maxTerms = 0 )
        //{
        //    List<string> list = new List<string>();

        //    keyword = keyword.Trim();

        //    if ( maxTerms == 0 )
        //        maxTerms = 50;

        //    using ( var context = new ViewContext() )
        //    {
        //        // will only return active credentials
        //        var results = context.Entity_Reference_Summary
        //            .Where( s => s.EntityTypeId == entityTypeId
        //                && s.CategoryId == categoryId
        //                && (
        //                    ( s.TextValue.Contains( keyword ) ||
        //                    ( s.Title.Contains( keyword ) )
        //                    )
        //                ) )
        //            .OrderBy( s => s.TextValue )
        //            .Select( m => m.TextValue ).Distinct()
        //            .Take( maxTerms )
        //            .ToList();

        //        if ( results != null && results.Count > 0 )
        //        {

        //            foreach ( string item in results )
        //            {
        //                list.Add( item );
        //            }

        //        }
        //    }

        //    return list;
        //}

        public static List <object> QuickSearch_ReferenceFrameworks(int entityTypeId, int categoryId, string headerId, string keyword, int maxTerms = 0)
        {
            var list = new List <object>();

            keyword = keyword.Trim();
            var coded = keyword.Replace("-", "").Replace(" ", "");

            if (maxTerms == 0)
            {
                maxTerms = 50;
            }

            if (headerId == "0")
            {
                headerId = "";
            }

            using (var context = new ViewContext())
            {
                var results = (from rf in context.Entity_ReferenceFramework_Totals
                               let cn = rf.CodedNotation.Replace("-", "").Replace(" ", "")
                                        where (headerId == "" || rf.CodeGroup == headerId) &&
                                        (rf.CategoryId == categoryId) &&
                                        (rf.EntityTypeId == entityTypeId) &&
                                        (keyword == "" ||
                                         rf.CodedNotation.Contains(keyword) ||
                                         cn.Contains(coded) ||
                                         rf.Name.Contains(keyword)) &&
                                        (rf.Totals > 0)
                                        orderby rf.Name
                                        select rf).Distinct().Take(maxTerms).ToList();

                results.ForEach(x => {
                    var cd = "";
                    if (!string.IsNullOrEmpty(x.CodedNotation))
                    {
                        cd = string.Format(" ({0})", x.CodedNotation);
                    }

                    list.Add(string.Format("{0}{1}", x.Name, cd));
                });
                //list = context.Entity_ReferenceFramework_Totals
                //        .Where( s => ( headerId == "" || s.CodeGroup == headerId )
                //        && ( s.CategoryId == categoryId )
                //        && ( s.EntityTypeId == entityTypeId )
                //        && ( keyword == ""
                //        || s.CodedNotation.Contains( keyword )
                //        || s.Name.Contains( keyword ) )
                //        && ( s.Totals > 0 ) )
                //    .OrderBy( s => s.Name )
                //    .Take( maxTerms )
                //    .Select( x => x.Name )
                //    .Distinct()
                //    .ToList();
            }

            return(list);
        } //
        /// <summary>
        /// Get all records for the parent
        /// Uses the parent Guid to retrieve the related ThisEntity, then uses the EntityId to retrieve the child objects.
        /// </summary>
        /// <param name="parentUid"></param>
        public static List <CredentialAlignmentObjectItem> GetAll(int entityTypeId, int entityBaseId, int maxRecords = 0)
        {
            CredentialAlignmentObjectItem        entity = new CredentialAlignmentObjectItem();
            List <CredentialAlignmentObjectItem> list   = new List <CredentialAlignmentObjectItem>();

            if (maxRecords == 0)
            {
                maxRecords = 10000;
            }

            //Entity parent = EntityManager.GetEntity( parentUid );
            //if ( parent == null || parent.Id == 0 )
            //{
            //	return list;
            //}
            try
            {
                using (var context = new ViewContext())
                {
                    List <Views.EntityCompetencyFramework_Items_Summary> results = context.EntityCompetencyFramework_Items_Summary
                                                                                   .Where(s => s.EntityTypeId == entityTypeId &&
                                                                                          s.EntityBaseId == entityBaseId
                                                                                          )
                                                                                   .OrderBy(s => s.FrameworkName)
                                                                                   .ThenBy(s => s.Competency)
                                                                                   .Take(maxRecords)
                                                                                   .ToList();

                    if (results != null && results.Count > 0)
                    {
                        foreach (var item in results)
                        {
                            entity = new CredentialAlignmentObjectItem();
                            MapFromDB(item, entity);
                            list.Add(entity);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + string.Format(".GetAll( entityTypeId: {0}, entityBaseId: {1} )", entityTypeId, entityBaseId));
            }
            return(list);
        }        //
        }//

        public static List <ThisEntity> GetAllSubjects(Guid parentUid)
        {
            ThisEntity        entity = new ThisEntity();
            List <ThisEntity> list   = new List <ThisEntity>();

            Entity parent = EntityManager.GetEntity(parentUid);

            if (parent == null || parent.Id == 0)
            {
                return(list);
            }
            try
            {
                string prevSubject = "";
                using (var context = new ViewContext())
                {
                    List <Entity_Subjects> results = context.Entity_Subjects
                                                     .Where(s => s.EntityUid == parentUid)
                                                     .OrderBy(s => s.Subject)
                                                     .ToList();

                    if (results != null && results.Count > 0)
                    {
                        foreach (Entity_Subjects item in results)
                        {
                            entity = new ThisEntity();
                            if (item.Subject != prevSubject)
                            {
                                entity.EntityId  = item.EntityId;
                                entity.TextValue = item.Subject;
                                list.Add(entity);
                            }
                            prevSubject = item.Subject;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".Entity_GetAllSubjects");
            }
            return(list);
        }//
Beispiel #9
0
        } //

        public static List <OrganizationRoleProfile> GetAllCombinedForTarget(int targetEntityTypeId, int recordId, int owningOrgId)
        {
            OrganizationRoleProfile        orp  = new OrganizationRoleProfile();
            List <OrganizationRoleProfile> list = new List <OrganizationRoleProfile>();

            //21-03-22 remove requirement for owningOrgId
            //|| owningOrgId == 0
            if (targetEntityTypeId == 0 || recordId == 0)
            {
                return(list);
            }

            EnumeratedItem eitem = new EnumeratedItem();

            Guid   prevOrgUid     = new Guid();
            string prevRoleSource = "";
            int    prevRoleTypeId = 0;

            using (var context = new ViewContext())
            {
                List <Views.Organization_CombinedConnections> agentRoles = context.Organization_CombinedConnections
                                                                           .Where(s => s.TargetEntityTypeId == targetEntityTypeId &&
                                                                                  s.TargetEntityBaseId == recordId
                                                                                  //&& s.IsQARole == true
                                                                                  && s.TargetEntityStateId > 1)
                                                                           .OrderBy(s => s.Organization)
                                                                           .ThenBy(s => s.RelationshipTypeId)
                                                                           .ThenBy(s => s.roleSource)
                                                                           .ToList();
                if (agentRoles != null && agentRoles.Any())
                {
                    //for this view, we want to retrieve the QA organization info, we already have the target (ie. that is the current context).
                    foreach (var entity in agentRoles)
                    {
                        //loop until change in entity type?
                        if (prevOrgUid != entity.OrgUid)
                        {
                            //handle previous fill
                            if (IsGuidValid(prevOrgUid) && prevRoleTypeId > 0)
                            {
                                orp.AgentRole.Items.Add(eitem);
                                list.Add(orp);
                            }

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

                            //not sure if pertinent
                            orp = new OrganizationRoleProfile
                            {
                                Id             = 0,
                                ParentId       = entity.OrgId,
                                ParentTypeId   = 2,
                                ProfileSummary = entity.Organization,

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

                            orp.ActingAgent = new Organization();

                            //or should it be TargetOrganization - check how currently used
                            //compare: Entity_AgentRelationshipManager.AgentEntityRole_GetAll_ToEnumeration
                            orp.ActingAgentUid = entity.OrgUid;
                            orp.ActingAgentId  = entity.OrgId;
                            orp.ActingAgent    = new Organization()
                            {
                                Id             = entity.OrgId,
                                RowId          = entity.OrgUid,
                                Name           = entity.Organization,
                                SubjectWebpage = entity.AgentSubjectWebpage,
                                Description    = entity.AgentDescription,
                                Image          = entity.AgentImageUrl,
                                EntityStateId  = entity.AgentEntityStateId ?? 1,
                                CTID           = entity.AgentCTID
                            };
                            orp.AgentRole.Items = new List <EnumeratedItem>();
                        }

                        /* either first one for new target
                         * or change in relationship
                         * or change in role source
                         * NOTE: skip the Direct checks if not QA, or at least if only owns/offers
                         */

                        if (prevRoleTypeId == entity.RelationshipTypeId)
                        {
                            if (prevRoleSource != entity.roleSource)
                            {
                                //TBD
                                if (entity.IsQARole ?? false)
                                {
                                    if (entity.roleSource == "QAOrganization" || entity.OrgId == owningOrgId)
                                    {
                                        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.SourceToAgentRelationship,
                            SchemaName = entity.SchemaTag,
                            IsQAValue  = (entity.IsQARole ?? false)
                        };
                        if ((entity.IsQARole ?? false) && entity.OrgId != owningOrgId)
                        {
                            //not sure this is correct. For QA received, it should be BYs
                            //eitem.Name = entity.AgentToSourceRelationship;
                            eitem.Name       = entity.SourceToAgentRelationship;
                            eitem.SchemaName = entity.SchemaTag;
                            //eitem.SchemaName = entity.ReverseSchemaTag;
                        }
                        else
                        {
                            if (entity.RelationshipTypeId != 6 && entity.RelationshipTypeId != 7)
                            {
                                eitem.Name       = entity.SourceToAgentRelationship;
                                eitem.SchemaName = entity.SchemaTag;
                            }
                            //eitem.Name = entity.SourceToAgentRelationship;
                            //eitem.SchemaName = entity.SchemaTag;
                        }
                        //eitem.CodeId = entity.RelationshipTypeId;

                        prevRoleTypeId = entity.RelationshipTypeId;
                        prevRoleSource = entity.roleSource;
                        //**need additional check if from the owning org!
                        if (entity.IsQARole ?? false)
                        {
                            if (entity.roleSource == "QAOrganization" || entity.OrgId == owningOrgId)
                            {
                                eitem.IsDirectAssertion = true;
                            }
                            else
                            {
                                eitem.IsIndirectAssertion = true;
                            }
                        }
                    }                     //

                    //check for remaining
                    if (IsGuidValid(prevOrgUid) && prevRoleTypeId > 0)
                    {
                        orp.AgentRole.Items.Add(eitem);
                        list.Add(orp);
                    }
                }
            }
            return(list);
        }         //
Beispiel #10
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);
        } //
Beispiel #11
0
        public static void FillCountsForOrganizationQAPerformed(Organization org, ref int totalRecords)
        {
            Entity agentEntity = EntityManager.GetEntity(org.RowId);

            using (var context = new ViewContext())
            {
                //first check how long this step takes
                DateTime start = DateTime.Now;
                LoggingHelper.DoTrace(7, "FillCountsForOrganizationQAPerformed start");
                //List<Views.Organization_CombinedQAPerformed> agentRoles = context.Organization_CombinedQAPerformed
                //	.Where( s => s.OrgUid == org.RowId
                //		 && 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();



                //if ( agentRoles != null && agentRoles.Count() > 0 )
                //{
                //	//
                //	totalRecords = agentRoles.Count();
                //	//may want a fudge factor?
                //	org.QAPerformedOnCredentialsCount = agentRoles.Where( s => s.TargetEntityTypeId == 1 ).Distinct().Count();
                //	org.QAPerformedOnOrganizationsCount = agentRoles.Where( s => s.TargetEntityTypeId == 2 ).Distinct().Count();
                //	org.QAPerformedOnAssessmentsCount = agentRoles.Where( s => s.TargetEntityTypeId == 3 ).Distinct().Count();
                //	org.QAPerformedOnLoppsCount = agentRoles.Where( s => s.TargetEntityTypeId == 7 ).Distinct().Count();

                //}



                var query = from qa in context.Organization_CombinedQAPerformed
                            .Where(s => s.OrgUid == org.RowId &&
                                   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)
                            select new
                {
                    qa.TargetEntityTypeId,
                    qa.TargetEntityBaseId,
                    qa.TargetOwningOrganizationId
                };
                DateTime end     = DateTime.Now;
                var      elasped = end.Subtract(start).TotalSeconds;
                LoggingHelper.DoTrace(7, string.Format("FillCountsForOrganizationQAPerformed retrieve seconds: {0}", elasped));

                var results = query.Distinct().ToList();
                if (results != null && results.Count() > 0)
                {
                    //
                    totalRecords = results.Count();
                    //may want a fudge factor?
                    org.QAPerformedOnCredentialsCount   = results.Where(s => s.TargetEntityTypeId == 1 && s.TargetOwningOrganizationId != org.Id).Distinct().Count();
                    org.QAPerformedOnOrganizationsCount = results.Where(s => s.TargetEntityTypeId == 2).Distinct().Count();
                    org.QAPerformedOnAssessmentsCount   = results.Where(s => s.TargetEntityTypeId == 3 && s.TargetOwningOrganizationId != org.Id).Distinct().Count();
                    org.QAPerformedOnLoppsCount         = results.Where(s => s.TargetEntityTypeId == 7 && s.TargetOwningOrganizationId != org.Id).Distinct().Count();

                    DateTime listEnd = DateTime.Now;
                    elasped = listEnd.Subtract(end).TotalSeconds;
                    LoggingHelper.DoTrace(7, string.Format("FillCountsForOrganizationQAPerformed loaded list seconds: {0}", elasped));
                }
            }
        }         //
Beispiel #12
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);
        }
Beispiel #13
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);
        }
        } //

        public static List <SiteActivity> SearchAll(BaseSearchModel parms)
        {
            string              connectionString = DBConnectionRO();
            SiteActivity        entity           = new SiteActivity();
            List <SiteActivity> list             = new List <SiteActivity>();

            if (parms.PageSize == 0)
            {
                parms.PageSize = 25;
            }
            int skip = 0;

            if (parms.PageNumber > 1)
            {
                skip = (parms.PageNumber - 1) * parms.PageSize;
            }
            if (string.IsNullOrWhiteSpace(parms.OrderBy))
            {
                parms.OrderBy      = "CreatedDate";
                parms.IsDescending = true;
            }
            if (parms.StartDate == null || parms.StartDate < new DateTime(2015, 1, 1))
            {
                parms.StartDate = new DateTime(2015, 1, 1);
            }
            if (parms.EndDate == null || parms.EndDate < new DateTime(2015, 1, 1))
            {
                parms.EndDate = DateTime.Now;
            }

            using (var context = new ViewContext())
            {
                var query = from Results in context.Activity_Summary
                            .Where(s => s.Activity != "Session")
                            select Results;
                if (!string.IsNullOrWhiteSpace(parms.Keyword))
                {
                    query = from Results in query
                            .Where(s => (s.Activity.Contains(parms.Keyword) ||
                                         (s.Event.Contains(parms.Keyword)) ||
                                         (s.Comment.Contains(parms.Keyword))
                                         ))
                            select Results;
                }
                parms.TotalRows = query.Count();
                if (parms.IsDescending)
                {
                    if (parms.OrderBy == "CreatedDate")
                    {
                        query = query.OrderByDescending(p => p.CreatedDate);
                    }
                    else if (parms.OrderBy == "Activity")
                    {
                        query = query.OrderByDescending(p => p.Activity);
                    }
                    else if (parms.OrderBy == "Event")
                    {
                        query = query.OrderByDescending(p => p.Event);
                    }
                    else if (parms.OrderBy == "ActionByUser")
                    {
                        query = query.OrderByDescending(p => p.ActionByUser);
                    }
                    else
                    {
                        query = query.OrderByDescending(p => p.CreatedDate);
                    }
                }
                else
                {
                    if (parms.OrderBy == "CreatedDate")
                    {
                        query = query.OrderBy(p => p.CreatedDate);
                    }
                    else if (parms.OrderBy == "Activity")
                    {
                        query = query.OrderBy(p => p.Activity);
                    }
                    else if (parms.OrderBy == "Event")
                    {
                        query = query.OrderBy(p => p.Event);
                    }
                    else if (parms.OrderBy == "ActionByUser")
                    {
                        query = query.OrderBy(p => p.ActionByUser);
                    }

                    else
                    {
                        query = query.OrderBy(p => p.CreatedDate);
                    }
                }

                var results = query.Skip(skip).Take(parms.PageSize)
                              .ToList();
                if (results != null && results.Count > 0)
                {
                    foreach (Views.Activity_Summary item in results)
                    {
                        entity              = new SiteActivity();
                        entity.Id           = item.Id;
                        entity.Activity     = item.Activity;
                        entity.Event        = item.Event;
                        entity.Comment      = item.Comment;
                        entity.Created      = ( DateTime )item.CreatedDate;
                        entity.ActionByUser = item.ActionByUser;
                        entity.Referrer     = entity.Referrer;
                        list.Add(entity);
                    }
                }
            }



            return(list);
        } //
Beispiel #15
0
        }               //

        /// <summary>
        /// May be workaround, may be permanent, getting combined
        /// </summary>
        /// <param name="parentUid"></param>
        /// <param name="alignmentType"></param>
        /// <returns></returns>
        public static List <CredentialAlignmentObjectProfile> GetAllAs_CredentialAlignmentObjectProfile(Guid parentUid, ref Dictionary <string, RegistryImport> frameworksList)
        {
            CredentialAlignmentObjectProfile        entity = new CredentialAlignmentObjectProfile();
            List <CredentialAlignmentObjectProfile> list   = new List <CredentialAlignmentObjectProfile>();
            //var frameworksList = new Dictionary<string, RegistryImport>();
            string prevFramework = "";
            Entity parent        = EntityManager.GetEntity(parentUid);

            if (parent == null || parent.Id == 0)
            {
                return(list);
            }
            try
            {
                using (var context = new ViewContext())
                {
                    /*
                     * List<DBEntity> results = context.Entity_Competency
                     *              .Where( s => s.EntityId == parent.Id
                     *              )
                     *              .OrderBy( s => s.CompetencyFramework )
                     *              .ThenBy( s => s.TargetNodeName )
                     *              .ToList();
                     * if ( results != null && results.Count > 0 )
                     * {
                     *      foreach ( DBEntity item in results )
                     *      {
                     *              entity = new CredentialAlignmentObjectProfile();
                     *              MapFromDB( item, entity );
                     *              list.Add( entity );
                     *      }
                     * }
                     */
                    List <Views.EntityCompetencyFramework_Items_Summary> results = context.EntityCompetencyFramework_Items_Summary
                                                                                   .Where(s => s.EntityId == parent.Id
                                                                                          )
                                                                                   .OrderBy(s => s.FrameworkName)
                                                                                   .ThenBy(s => s.Competency)
                                                                                   .ToList();
                    if (results != null && results.Count > 0)
                    {
                        foreach (var item in results)
                        {
                            entity = new CredentialAlignmentObjectProfile();
                            MapFromDB(item, entity);
                            if (prevFramework != entity.FrameworkName)
                            {
                                if (!string.IsNullOrWhiteSpace(entity.FrameworkCtid))
                                {
                                    //var fw = new Dictionary<string, RegistryImport>();
                                    RegistryImport ri = ImportManager.GetByCtid(entity.FrameworkCtid);
                                    if (frameworksList.ContainsKey(entity.FrameworkName) == false)
                                    {
                                        frameworksList.Add(entity.FrameworkName, ri);
                                    }
                                }
                                prevFramework = entity.FrameworkName;
                            }

                            list.Add(entity);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".GetAllAs_CredentialAlignmentObjectProfile");
            }
            return(list);
        }        //