Пример #1
0
        /// <summary>
        /// Sorts the items.
        /// </summary>
        /// <param name="folders">The full folder list</param>
        /// <param name="parentId">The current parent id</param>
        /// <returns>The structure</returns>
        private Models.MediaStructure Sort(IEnumerable <MediaFolder> folders, IList <FolderCount> count, Guid?parentId = null, int level = 0)
        {
            var rootCount  = count.FirstOrDefault(c => c.FolderId == null)?.Count;
            var totalCount = count.Sum(c => c.Count);
            var result     = new Models.MediaStructure
            {
                MediaCount = rootCount.HasValue ? rootCount.Value : 0,
                TotalCount = totalCount
            };

            var mediaFolders = folders as MediaFolder[] ?? folders.ToArray();

            foreach (var folder in mediaFolders.Where(f => f.ParentId == parentId).OrderBy(f => f.Name))
            {
                var item        = Module.Mapper.Map <MediaFolder, Models.MediaStructureItem>(folder);
                var folderCount = count.FirstOrDefault(c => c.FolderId == folder.Id)?.Count;

                item.Level       = level;
                item.Items       = Sort(mediaFolders, count, folder.Id, level + 1);
                item.FolderCount = folders.Count(f => f.ParentId == item.Id);
                item.MediaCount  = folderCount.HasValue ? folderCount.Value : 0;

                result.Add(item);
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// Gets the hierachical media structure.
        /// </summary>
        /// <returns>The media structure</returns>
        public Models.MediaStructure GetStructure()
        {
            Models.MediaStructure model = cache != null?cache.Get <Models.MediaStructure>(MEDIA_STRUCTURE) : null;

            if (model == null)
            {
                var folders = new List <MediaFolder>();
                var ids     = db.MediaFolders
                              .AsNoTracking()
                              .OrderBy(f => f.ParentId)
                              .ThenBy(f => f.Name)
                              .Select(f => f.Id)
                              .ToList();

                foreach (var id in ids)
                {
                    var folder = GetFolderById(id);
                    if (folder != null)
                    {
                        folders.Add(folder);
                    }
                }

                model = Sort(folders);

                if (cache != null && model != null)
                {
                    cache.Set(MEDIA_STRUCTURE, model);
                }
            }
            return(model);
        }
Пример #3
0
        /// <summary>
        /// Sorts the items.
        /// </summary>
        /// <param name="folders">The full folder list</param>
        /// <param name="parentId">The current parent id</param>
        /// <returns>The structure</returns>
        private Models.MediaStructure Sort(IEnumerable <MediaFolder> folders, string parentId = null, int level = 0)
        {
            var result = new Models.MediaStructure();

            foreach (var folder in folders.Where(f => f.ParentId == parentId).OrderBy(f => f.Name))
            {
                var item = App.Mapper.Map <MediaFolder, Models.MediaStructureItem>(folder);

                item.Level = level;
                item.Items = Sort(folders, folder.Id, level + 1);

                result.Add(item);
            }
            return(result);
        }
Пример #4
0
        /// <summary>
        /// Sorts the items.
        /// </summary>
        /// <param name="folders">The full folder list</param>
        /// <param name="parentId">The current parent id</param>
        /// <returns>The structure</returns>
        private Models.MediaStructure Sort(IEnumerable <MediaFolder> folders, Guid?parentId = null, int level = 0)
        {
            var result = new Models.MediaStructure();

            var mediaFolders = folders as MediaFolder[] ?? folders.ToArray();

            foreach (var folder in mediaFolders.Where(f => f.ParentId == parentId).OrderBy(f => f.Name))
            {
                var item = Module.Mapper.Map <MediaFolder, Models.MediaStructureItem>(folder);

                item.Level = level;
                item.Items = Sort(mediaFolders, folder.Id, level + 1);

                result.Add(item);
            }
            return(result);
        }
Пример #5
0
        /// <summary>
        /// Gets the hierachical media structure.
        /// </summary>
        /// <param name="transaction">The optional transaction</param>
        /// <returns>The media structure</returns>
        public Models.MediaStructure GetStructure(IDbTransaction transaction = null)
        {
            Models.MediaStructure model = cache != null?cache.Get <Models.MediaStructure>("MediaStructure") : null;

            if (model == null)
            {
                var folders = db.Query <MediaFolder>("SELECT [Id],[ParentId],[Name],[Created] FROM [Piranha_MediaFolders] ORDER BY [ParentId], [Name]",
                                                     transaction: transaction);

                model = Sort(folders);

                if (cache != null && model != null)
                {
                    cache.Set("MediaStructure", model);
                }
            }
            return(model);
        }
Пример #6
0
        /// <summary>
        /// Gets the hierachical media structure.
        /// </summary>
        /// <returns>The media structure</returns>
        public Models.MediaStructure GetStructure()
        {
            Models.MediaStructure model = cache != null?cache.Get <Models.MediaStructure>("MediaStructure") : null;

            if (model == null)
            {
                var folders = db.MediaFolders
                              .AsNoTracking()
                              .OrderBy(f => f.ParentId)
                              .ThenBy(f => f.Name)
                              .ToList();

                model = Sort(folders);

                if (cache != null && model != null)
                {
                    cache.Set("MediaStructure", model);
                }
            }
            return(model);
        }