示例#1
0
        public IQueryable<TreeViewItem> GetChildren( int id, int rootGroupId, bool limitToSecurityRoleGroups, string groupTypeIds )
        {
            var user = CurrentUser();
            if ( user != null )
            {
                var groupService = new GroupService();
                groupService.Repository.SetConfigurationValue( "ProxyCreationEnabled", "false" );
                var qry = groupService.GetNavigationChildren( id, rootGroupId, limitToSecurityRoleGroups, groupTypeIds );

                List<Group> groupList = new List<Group>();
                List<TreeViewItem> groupNameList = new List<TreeViewItem>();

                foreach ( var group in qry )
                {
                    if ( group.IsAuthorized( "View", user.Person ) )
                    {
                        groupList.Add( group );
                        var treeViewItem = new TreeViewItem();
                        treeViewItem.Id = group.Id.ToString();
                        treeViewItem.Name = System.Web.HttpUtility.HtmlEncode( group.Name );

                        // if there a IconCssClass is assigned, use that as the Icon.
                        var groupType = Rock.Web.Cache.GroupTypeCache.Read( group.GroupTypeId );
                        if ( groupType != null )
                        {
                            treeViewItem.IconCssClass = groupType.IconCssClass;
                        }

                        groupNameList.Add( treeViewItem );
                    }
                }

                // try to quickly figure out which items have Children
                List<int> resultIds = groupList.Select( a => a.Id ).ToList();

                var qryHasChildren = from x in Get().Select( a => a.ParentGroupId )
                                     where resultIds.Contains( x.Value )
                                     select x.Value;

                var qryHasChildrenList = qryHasChildren.ToList();

                foreach ( var g in groupNameList )
                {
                    int groupId = int.Parse( g.Id );
                    g.HasChildren = qryHasChildrenList.Any( a => a == groupId );
                }

                return groupNameList.AsQueryable();
            }
            else
            {
                throw new HttpResponseException( HttpStatusCode.Unauthorized );
            }
        }
        public IQueryable<TreeViewItem> GetChildren( string id )
        {
            var list = new List<TreeViewItem>();

            int? idAsInt = id.AsIntegerOrNull();

            if ( string.IsNullOrWhiteSpace( id ) || ( idAsInt.HasValue && idAsInt.Value == 0 ) )
            {
                // Root
                foreach( var category in ActionContainer.Instance.Categories )
                {
                    var item = new TreeViewItem();
                    item.Id = category.Key.ToString();
                    item.Name = category.Value;
                    item.HasChildren = true;
                    item.IconCssClass = "fa fa-folder";
                    list.Add( item );
                }
            }
            else
            {
                if ( idAsInt.HasValue && idAsInt.Value < 0 )
                {
                    // Category
                    if ( ActionContainer.Instance.Categories.ContainsKey( idAsInt.Value ) )
                    {
                        string categoryName = ActionContainer.Instance.Categories[idAsInt.Value];
                        var categorizedActions = GetCategorizedActions();
                        if ( categorizedActions.ContainsKey( categoryName ) )
                        {
                            foreach ( var entityType in categorizedActions[categoryName].OrderBy( e => e.FriendlyName ) )
                            {
                                var item = new TreeViewItem();
                                item.Id = entityType.Id.ToString();
                                item.Name = ActionContainer.GetComponentName(entityType.Name);
                                item.HasChildren = false;
                                item.IconCssClass = "fa fa-cube";
                                list.Add( item );
                            }
                        }
                    }
                }
            }

            return list.OrderBy( i => i.Name ).AsQueryable();
        }
        public IQueryable<TreeViewItem> GetChildren( int id, string hidePageIds = null)
        {
            IQueryable<Page> qry;
            if ( id == 0 )
            {
                qry = Get().Where( a => a.ParentPageId == null );
            }
            else
            {
                qry = Get().Where( a => a.ParentPageId == id );
            }

            List<int> hidePageIdList = ( hidePageIds ?? string.Empty ).Split( ',' ).Select( s => s.AsInteger()).ToList();

            List<Page> pageList = qry.Where( a => !hidePageIdList.Contains(a.Id) ).OrderBy( a => a.Order ).ThenBy( a => a.InternalName ).ToList();
            List<TreeViewItem> pageItemList = new List<TreeViewItem>();
            foreach ( var page in pageList )
            {
                var pageItem = new TreeViewItem();
                pageItem.Id = page.Id.ToString();
                pageItem.Name = page.InternalName;

                pageItemList.Add( pageItem );
            }

            // try to quickly figure out which items have Children
            List<int> resultIds = pageList.Select( a => a.Id ).ToList();

            var qryHasChildren = Get()
                .Where( p =>
                    p.ParentPageId.HasValue &&
                    resultIds.Contains( p.ParentPageId.Value ) )
                .Select( p => p.ParentPageId.Value )
                .Distinct()
                .ToList();

            foreach ( var g in pageItemList )
            {
                int pageId = int.Parse( g.Id );
                g.HasChildren = qryHasChildren.Any( a => a == pageId );
                g.IconCssClass = "fa fa-file-o";
            }

            return pageItemList.AsQueryable();
        }
示例#4
0
        /// <summary>
        /// Gets the children.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public IQueryable<TreeViewItem> GetChildren( int id)
        {
            IQueryable<Page> qry;
            if ( id == 0 )
            {
                qry = Get().Where( a => a.ParentPageId == null );
            }
            else
            {
                qry = Get().Where( a => a.ParentPageId == id );
            }

            List<Page> pageList = qry.OrderBy( a => a.Order ).ThenBy( a => a.InternalName ).ToList();
            List<TreeViewItem> pageItemList = new List<TreeViewItem>();
            foreach ( var page in pageList )
            {
                var pageItem = new TreeViewItem();
                pageItem.Id = page.Id.ToString();
                pageItem.Name = page.InternalName;

                pageItemList.Add( pageItem );
            }

            // try to quickly figure out which items have Children
            List<int> resultIds = pageList.Select( a => a.Id ).ToList();

            var qryHasChildren = from x in Get().Select( a => a.ParentPageId )
                                 where resultIds.Contains( x.Value )
                                 select x.Value;

            var qryHasChildrenList = qryHasChildren.ToList();

            foreach ( var g in pageItemList )
            {
                int pageId = int.Parse( g.Id );
                g.HasChildren = qryHasChildrenList.Any( a => a == pageId );
                g.IconCssClass = "fa fa-file-o";
            }

            return pageItemList.AsQueryable();
        }
示例#5
0
        public IQueryable<TreeViewItem> GetChildren( int id, int rootLocationId )
        {
            IQueryable<Location> qry;
            if ( id == 0 )
            {
                qry = Get().Where( a => a.ParentLocationId == null );
                if ( rootLocationId != 0 )
                {
                    qry = qry.Where( a => a.Id == rootLocationId );
                }
            }
            else
            {
                qry = Get().Where( a => a.ParentLocationId == id );
            }

            // limit to only Named Locations (don't show home addresses, etc)
            qry = qry.Where( a => a.Name != null && a.Name != string.Empty );

            List<Location> locationList = new List<Location>();
            List<TreeViewItem> locationNameList = new List<TreeViewItem>();

            var person = GetPerson();

            foreach ( var location in qry.OrderBy ( l => l.Name ) )
            {
                if ( location.IsAuthorized( Rock.Security.Authorization.VIEW, person ) )
                {
                    locationList.Add( location );
                    var treeViewItem = new TreeViewItem();
                    treeViewItem.Id = location.Id.ToString();
                    treeViewItem.Name = System.Web.HttpUtility.HtmlEncode( location.Name );
                    locationNameList.Add( treeViewItem );
                }
            }

            // try to quickly figure out which items have Children
            List<int> resultIds = locationList.Select( a => a.Id ).ToList();

            var qryHasChildren = Get()
                .Where( l =>
                    l.ParentLocationId.HasValue &&
                    resultIds.Contains( l.ParentLocationId.Value ) )
                .Select( l => l.ParentLocationId.Value )
                .Distinct()
                .ToList();

            var qryHasChildrenList = qryHasChildren.ToList();

            foreach ( var item in locationNameList )
            {
                int locationId = int.Parse( item.Id );
                item.HasChildren = qryHasChildrenList.Any( a => a == locationId );
            }

            return locationNameList.AsQueryable();
        }
示例#6
0
        public IQueryable<TreeViewItem> GetChildren( string id, string additionalFields )
        {
            List<TreeViewItem> items = new List<TreeViewItem>();

            switch ( id )
            {
                case "0":
                    
                    if (!string.IsNullOrWhiteSpace(additionalFields))
                    {
                        foreach ( string fieldName in additionalFields.Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries ) )
                        {
                            var entityType = EntityTypeCache.Read( fieldName, false );
                            if ( entityType != null )
                            {
                                items.Add( new TreeViewItem
                                {
                                    Id = fieldName,
                                    Name = entityType.FriendlyName,
                                    HasChildren = true
                                } );
                            }
                            else
                            {
                                items.Add( new TreeViewItem
                                {
                                    Id = fieldName,
                                    Name = fieldName.SplitCase(),
                                    HasChildren = fieldName == "GlobalAttribute"
                                } );
                            }
                        }
                    }

                    break;
                    
                case "GlobalAttribute":

                    var globalAttributes = Rock.Web.Cache.GlobalAttributesCache.Read();

                    foreach ( var attributeCache in globalAttributes.Attributes.OrderBy( a => a.Key ) )
                    {
                        if ( attributeCache.IsAuthorized( Authorization.VIEW, null ) )
                        {
                            items.Add( new TreeViewItem
                            {
                                Id = "GlobalAttribute|" + attributeCache.Key,
                                Name = attributeCache.Name,
                                HasChildren = false
                            } );
                        }
                    }

                    break;

                default:

                    // In this scenario, the id should be a concatonatioin of a root qualified entity name
                    // and then the property path
                    var idParts = id.SplitDelimitedValues().ToList();
                    if ( idParts.Count > 0 )
                    {
                        // Get the root type
                        var entityType = EntityTypeCache.Read( idParts[0], false );
                        if ( entityType != null )
                        {
                            Type type = entityType.GetEntityType();

                            // Traverse the Property path
                            int pathPointer = 1;
                            while ( idParts.Count > pathPointer )
                            {
                                var childProperty = type.GetProperty( idParts[pathPointer] );
                                if ( childProperty != null )
                                {
                                    type = childProperty.PropertyType;

                                    if ( type.IsGenericType &&
                                        type.GetGenericTypeDefinition() == typeof( ICollection<> ) &&
                                        type.GetGenericArguments().Length == 1 )
                                    {
                                        type = type.GetGenericArguments()[0];
                                    }
                                }
                                pathPointer++;
                            }

                            entityType = EntityTypeCache.Read( type );

                            // Add the tree view items
                            foreach ( var propInfo in type.GetProperties() )
                            {
                                if ( propInfo.GetCustomAttributes( typeof( System.Runtime.Serialization.DataMemberAttribute ) ).Count() > 0 )
                                {
                                    var treeViewItem = new TreeViewItem
                                    {
                                        Id = id + "|" + propInfo.Name,
                                        Name = propInfo.Name.SplitCase()
                                    };

                                    Type propertyType = propInfo.PropertyType;

                                    if ( propertyType.IsGenericType &&
                                        propertyType.GetGenericTypeDefinition() == typeof( ICollection<> ) &&
                                        propertyType.GetGenericArguments().Length == 1 )
                                    {
                                        treeViewItem.Name += " (Collection)";
                                        propertyType = propertyType.GetGenericArguments()[0];
                                    }

                                    bool hasChildren = false;
                                    if ( EntityTypeCache.Read( propertyType.FullName, false ) != null )
                                    {
                                        foreach ( var childPropInfo in propertyType.GetProperties() )
                                        {
                                            if ( childPropInfo.GetCustomAttributes( typeof( System.Runtime.Serialization.DataMemberAttribute ) ).Count() > 0 )
                                            {
                                                hasChildren = true;
                                                break;
                                            }
                                        }
                                    }
                                    treeViewItem.HasChildren = hasChildren;

                                    items.Add( treeViewItem );
                                }
                            }

                            if ( entityType.IsEntity )
                            {
                                foreach ( Rock.Model.Attribute attribute in new AttributeService( new Rock.Data.RockContext() ).GetByEntityTypeId( entityType.Id ) )
                                {
                                    // Only include attributes without a qualifier (since we don't have a specific instance of this entity type)
                                    if ( string.IsNullOrEmpty( attribute.EntityTypeQualifierColumn ) &&
                                        string.IsNullOrEmpty( attribute.EntityTypeQualifierValue ) &&
                                        attribute.IsAuthorized( Authorization.VIEW, null ) )
                                    {
                                        items.Add( new TreeViewItem
                                        {
                                            Id = id + "|" + attribute.Key,
                                            Name = attribute.Name
                                        } );
                                    }
                                }
                            }
                        }
                    }
                    break;
            }

            return items.OrderBy( i => i.Name).AsQueryable();

        }
        public IQueryable<TreeViewItem> GetChildren( string id )
        {
            // Enable proxy creation since child collections need to be navigated
            SetProxyCreation( true );

            var rockContext = (RockContext)Service.Context;
            var list = new List<TreeViewItem>();

            if ( id.StartsWith( "T" ) )
            {
                int connectionTypeId = id.Substring( 1 ).AsInteger();
                foreach ( var opportunity in new ConnectionOpportunityService( rockContext )
                    .Queryable().AsNoTracking()
                    .Where( o => o.ConnectionTypeId == connectionTypeId )
                    .OrderBy( o => o.Name ) )
                {
                    var item = new TreeViewItem();
                    item.Id = string.Format( "O{0}", opportunity.Id );
                    item.Name = opportunity.Name;
                    item.HasChildren = opportunity.ConnectionRequests
                        .Any( r =>
                            r.ConnectionState == ConnectionState.Active ||
                            r.ConnectionState == ConnectionState.FutureFollowUp );
                    item.IconCssClass = opportunity.IconCssClass;
                    list.Add( item );
                }
            }

            else if ( id.StartsWith( "O" ) )
            {
                int opportunityId = id.Substring( 1 ).AsInteger();
                foreach ( var request in Service
                    .Queryable().AsNoTracking()
                    .Where( r =>
                        r.ConnectionOpportunityId == opportunityId &&
                        r.PersonAlias != null &&
                        r.PersonAlias.Person != null )
                    .OrderBy( r => r.PersonAlias.Person.LastName )
                    .ThenBy( r => r.PersonAlias.Person.NickName ) )
                {
                    var item = new TreeViewItem();
                    item.Id = request.Id.ToString();
                    item.Name = request.PersonAlias.Person.FullName;
                    item.HasChildren = false;
                    item.IconCssClass = "fa fa-user";
                    list.Add( item );
                }
            }

            else
            {
                int? requestId = id.AsIntegerOrNull();
                if ( !requestId.HasValue || requestId.Value == 0 )
                {
                    foreach ( var connectionType in new ConnectionTypeService( rockContext )
                        .Queryable().AsNoTracking()
                        .OrderBy( t => t.Name ) )
                    {
                        var item = new TreeViewItem();
                        item.Id = string.Format( "T{0}", connectionType.Id );
                        item.Name = connectionType.Name;
                        item.HasChildren = connectionType.ConnectionOpportunities.Any();
                        item.IconCssClass = connectionType.IconCssClass;
                        list.Add( item );
                    }
                }
            }

            return list.AsQueryable();
        }
        public IQueryable<TreeViewItem> GetChildren(
            int id,
            int rootGroupId = 0,
            bool limitToSecurityRoleGroups = false,
            string includedGroupTypeIds = "",
            string excludedGroupTypeIds = "",
            bool includeInactiveGroups = false,
            TreeViewItem.GetCountsType countsType = TreeViewItem.GetCountsType.None )
        {
            // Enable proxy creation since security is being checked and need to navigate parent authorities
            SetProxyCreation( true );

            var includedGroupTypeIdList = includedGroupTypeIds.SplitDelimitedValues().AsIntegerList().Except( new List<int> { 0 } ).ToList();
            var excludedGroupTypeIdList = excludedGroupTypeIds.SplitDelimitedValues().AsIntegerList().Except( new List<int> { 0 } ).ToList();

            var groupService = (GroupService)Service;

            // if specific group types are specified, show the groups regardless of ShowInNavigation
            bool limitToShowInNavigation = !includedGroupTypeIdList.Any();

            var qry = groupService.GetChildren( id, rootGroupId, limitToSecurityRoleGroups, includedGroupTypeIdList, excludedGroupTypeIdList, includeInactiveGroups, limitToShowInNavigation );

            List<Group> groupList = new List<Group>();
            List<TreeViewItem> groupNameList = new List<TreeViewItem>();

            var person = GetPerson();

            foreach ( var group in qry.OrderBy( g => g.Name ) )
            {
                if ( group.IsAuthorized( Rock.Security.Authorization.VIEW, person ) )
                {
                    groupList.Add( group );
                    var treeViewItem = new TreeViewItem();
                    treeViewItem.Id = group.Id.ToString();
                    treeViewItem.Name = group.Name;
                    treeViewItem.IsActive = group.IsActive;

                    // if there a IconCssClass is assigned, use that as the Icon.
                    var groupType = Rock.Web.Cache.GroupTypeCache.Read( group.GroupTypeId );
                    if ( groupType != null )
                    {
                        treeViewItem.IconCssClass = groupType.IconCssClass;
                    }

                    if ( countsType == TreeViewItem.GetCountsType.GroupMembers )
                    {
                        int groupMemberCount = new GroupMemberService( this.Service.Context as RockContext ).Queryable().Where( a => a.GroupId == group.Id && a.GroupMemberStatus == GroupMemberStatus.Active).Count();
                        treeViewItem.CountInfo = groupMemberCount;
                    }
                    else if ( countsType == TreeViewItem.GetCountsType.ChildGroups )
                    {
                        treeViewItem.CountInfo = groupService.Queryable().Where( a => a.ParentGroupId.HasValue && a.ParentGroupId == group.Id ).Count();
                    }

                    groupNameList.Add( treeViewItem );
                }
            }

            // try to quickly figure out which items have Children
            List<int> resultIds = groupList.Select( a => a.Id ).ToList();
            var qryHasChildren = Get()
                .Where( g =>
                    g.ParentGroupId.HasValue &&
                    resultIds.Contains( g.ParentGroupId.Value ) );

            if ( includedGroupTypeIdList.Any() )
            {
                qryHasChildren = qryHasChildren.Where( a => includedGroupTypeIdList.Contains( a.GroupTypeId ) );
            }
            else if ( excludedGroupTypeIdList.Any() )
            {
                qryHasChildren = qryHasChildren.Where( a => !excludedGroupTypeIdList.Contains( a.GroupTypeId ) );
            }

            var qryHasChildrenList = qryHasChildren
                .Select( g => g.ParentGroupId.Value )
                .Distinct()
                .ToList();

            foreach ( var g in groupNameList )
            {
                int groupId = g.Id.AsInteger();
                g.HasChildren = qryHasChildrenList.Any( a => a == groupId );
            }

            return groupNameList.AsQueryable();
        }
示例#9
0
        public IQueryable<TreeViewItem> GetChildren( int id, int rootGroupId, bool limitToSecurityRoleGroups, string groupTypeIds )
        {
            var qry = ( (GroupService)Service ).GetNavigationChildren( id, rootGroupId, limitToSecurityRoleGroups, groupTypeIds );

            List<Group> groupList = new List<Group>();
            List<TreeViewItem> groupNameList = new List<TreeViewItem>();

            var person = GetPerson();

            foreach ( var group in qry.OrderBy( g => g.Name ) )
            {
                if ( group.IsAuthorized( Rock.Security.Authorization.VIEW, person ) )
                {
                    groupList.Add( group );
                    var treeViewItem = new TreeViewItem();
                    treeViewItem.Id = group.Id.ToString();
                    treeViewItem.Name = group.Name;

                    // if there a IconCssClass is assigned, use that as the Icon.
                    var groupType = Rock.Web.Cache.GroupTypeCache.Read( group.GroupTypeId );
                    if ( groupType != null )
                    {
                        treeViewItem.IconCssClass = groupType.IconCssClass;
                    }

                    groupNameList.Add( treeViewItem );
                }
            }

            // try to quickly figure out which items have Children
            List<int> resultIds = groupList.Select( a => a.Id ).ToList();

            var qryHasChildren = from x in Get().Select( a => a.ParentGroupId )
                                 where resultIds.Contains( x.Value )
                                 select x.Value;

            var qryHasChildrenList = qryHasChildren.ToList();

            foreach ( var g in groupNameList )
            {
                int groupId = int.Parse( g.Id );
                g.HasChildren = qryHasChildrenList.Any( a => a == groupId );
            }

            return groupNameList.AsQueryable();
        }
        public IQueryable<TreeViewItem> GetChildren( int id, int rootLocationId)
        {
            var user = CurrentUser();
            if ( user != null )
            {
                IQueryable<Location> qry;
                if ( id == 0 )
                {
                    qry = Get().Where( a => a.ParentLocationId == null );
                    if ( rootLocationId != 0 )
                    {
                        qry = qry.Where( a => a.Id == rootLocationId );
                    }
                }
                else
                {
                    qry = Get().Where( a => a.ParentLocationId == id );
                }

                // limit to only Named Locations (don't show home addresses, etc)
                qry = qry.Where( a => a.IsNamedLocation );

                List<Location> locationList = new List<Location>();
                List<TreeViewItem> locationNameList = new List<TreeViewItem>();

                foreach ( var location in qry )
                {
                    if ( location.IsAuthorized( "View", user.Person ) )
                    {
                        locationList.Add( location );
                        var treeViewItem = new TreeViewItem();
                        treeViewItem.Id = location.Id.ToString();
                        treeViewItem.Name = System.Web.HttpUtility.HtmlEncode( location.Name );
                        locationNameList.Add( treeViewItem );
                    }
                }

                // try to quickly figure out which items have Children
                List<int> resultIds = locationList.Select( a => a.Id ).ToList();

                var qryHasChildren = from x in Get().Select( a => a.ParentLocationId )
                                     where resultIds.Contains( x.Value )
                                     select x.Value;

                var qryHasChildrenList = qryHasChildren.ToList();

                foreach ( var item in locationNameList )
                {
                    int locationId = int.Parse( item.Id );
                    item.HasChildren = qryHasChildrenList.Any( a => a == locationId );
                }

                return locationNameList.AsQueryable();
            }
            else
            {
                throw new HttpResponseException( HttpStatusCode.Unauthorized );
            }
        }
        public IQueryable<TreeViewItem> GetChildren( int id, int rootGroupId = 0, bool limitToSecurityRoleGroups = false, string includedGroupTypeIds = "", string excludedGroupTypeIds = "" )
        {
            // Enable proxy creation since security is being checked and need to navigate parent authorities
            SetProxyCreation( true );

            var includedGroupTypeIdList = includedGroupTypeIds.SplitDelimitedValues().AsIntegerList().Except( new List<int> { 0 } ).ToList();
            var excludedGroupTypeIdList = excludedGroupTypeIds.SplitDelimitedValues().AsIntegerList().Except( new List<int> { 0 } ).ToList();

            var groupService = (GroupService)Service;
            var qry = groupService.GetNavigationChildren( id, rootGroupId, limitToSecurityRoleGroups, includedGroupTypeIdList, excludedGroupTypeIdList );

            List<Group> groupList = new List<Group>();
            List<TreeViewItem> groupNameList = new List<TreeViewItem>();

            var person = GetPerson();

            foreach ( var group in qry.OrderBy( g => g.Name ) )
            {
                if ( group.IsAuthorized( Rock.Security.Authorization.VIEW, person ) )
                {
                    groupList.Add( group );
                    var treeViewItem = new TreeViewItem();
                    treeViewItem.Id = group.Id.ToString();
                    treeViewItem.Name = group.Name;

                    // if there a IconCssClass is assigned, use that as the Icon.
                    var groupType = Rock.Web.Cache.GroupTypeCache.Read( group.GroupTypeId );
                    if ( groupType != null )
                    {
                        treeViewItem.IconCssClass = groupType.IconCssClass;
                    }

                    groupNameList.Add( treeViewItem );
                }
            }

            // try to quickly figure out which items have Children
            List<int> resultIds = groupList.Select( a => a.Id ).ToList();
            var qryHasChildren = Get()
                .Where( g =>
                    g.ParentGroupId.HasValue &&
                    resultIds.Contains( g.ParentGroupId.Value ) );

            if ( includedGroupTypeIdList.Any() )
            {
                qryHasChildren = qryHasChildren.Where( a => includedGroupTypeIdList.Contains( a.GroupTypeId ) );
            }
            else if ( excludedGroupTypeIdList.Any() )
            {
                qryHasChildren = qryHasChildren.Where( a => !excludedGroupTypeIdList.Contains( a.GroupTypeId ) );
            }

            var qryHasChildrenList = qryHasChildren
                .Select( g => g.ParentGroupId.Value )
                .Distinct()
                .ToList();

            foreach ( var g in groupNameList )
            {
                int groupId = int.Parse( g.Id );
                g.HasChildren = qryHasChildrenList.Any( a => a == groupId );
            }

            return groupNameList.AsQueryable();
        }
示例#12
0
        public IQueryable<TreeViewItem> GetSubFolders( string folderName = "", string fileFilter = "*.*" )
        {
            fileFilter = string.IsNullOrWhiteSpace( fileFilter ) ? "*.*" : fileFilter;

            string physicalRootFolder = HttpContext.Current.Request.MapPath( RootContentFolder );
            string contentFolderName = Path.Combine( physicalRootFolder, folderName.TrimStart( new char[] { '/', '\\' } ) );
            List<TreeViewItem> directoryFileList = new List<TreeViewItem>();

            if ( !Directory.Exists( contentFolderName ) )
            {
                // if a non-existent folder was specified, return an empty list
                return directoryFileList.AsQueryable();
            }

            // list the folders that are in the selected directory
            List<string> directoryList = Directory.GetDirectories( contentFolderName ).OrderBy( a => a ).ToList();
            foreach ( string directoryPath in directoryList )
            {
                DirectoryInfo directoryInfo = new DirectoryInfo( directoryPath );
                TreeViewItem directoryNode = new TreeViewItem
                {
                    HasChildren = directoryInfo.EnumerateFiles( fileFilter ).Any() || directoryInfo.EnumerateDirectories().Any(),
                    IconCssClass = "fa fa-folder",
                    Id = directoryInfo.FullName.Remove( 0, physicalRootFolder.Length ),
                    Name = directoryInfo.Name
                };

                directoryFileList.Add( directoryNode );
            }

            return directoryFileList.AsQueryable();
        }