コード例 #1
0
        /// <summary>
        /// Gets all media
        /// </summary>
        public Page <MediaMap> GetMediaPaged(long page = 1, int pageSize = 3, string name = null, int?id = null, int?mediaTypeId = null, string orderBy = "Id", string orderByDir = "ASC")
        {
            string tempExt;

            IQuery <IMedia> criteria = new Query <IMedia>(scopeProvider.SqlContext);

            if (!string.IsNullOrEmpty(name))
            {
                criteria = criteria.Where(m => m.Name.Contains(name));
            }

            if (id.HasValue)
            {
                criteria = criteria.Where(m => m.Id == id.Value);
            }

            if (mediaTypeId.HasValue)
            {
                criteria = criteria.Where(m => m.ContentTypeId == mediaTypeId);
            }

            var order = new Ordering(orderBy, orderByDir == "ASC" ? Umbraco.Core.Persistence.DatabaseModelDefinitions.Direction.Ascending : Umbraco.Core.Persistence.DatabaseModelDefinitions.Direction.Descending);

            var media = this.mediaService.GetPagedDescendants(-1, page - 1, pageSize, out long totalRecords, filter: criteria, ordering: order).
                        Select(x => new MediaMap()
            {
                Id         = x.Id,
                Name       = x.Name,
                Alias      = x.ContentType.Name,
                Ext        = tempExt = FileTypeHelper.GetExtensionFromMedia(x),
                Type       = FileTypeHelper.GetFileTypeName(tempExt),
                Size       = FileTypeHelper.GetFileSize(x),
                Udi        = x.Key,
                CreateDate = x.CreateDate,
            }
                               ).ToList();

            var paged = new Page <MediaMap>()
            {
                CurrentPage  = page,
                Items        = media,
                ItemsPerPage = pageSize,
                TotalItems   = totalRecords,
                TotalPages   = totalRecords / pageSize
            };


            return(paged);
        }
コード例 #2
0
        /// <summary>
        /// Gets all media (this can potentially return a lot - add pagination??)
        /// </summary>
        public IEnumerable <MediaMap> GetMedia()
        {
            var             ms        = services.MediaService;
            List <MediaMap> mediaMap  = new List <MediaMap>();
            var             rootMedia = ms.GetRootMedia();
            string          tempExt;

            foreach (var m in rootMedia)
            {
                mediaMap.AddRange(ms.GetDescendants(m).
                                  Select(x => new MediaMap()
                {
                    Id    = x.Id,
                    Name  = x.Name,
                    Alias = x.ContentType.Name,
                    Ext   = tempExt = FileTypeHelper.GetExtensionFromMedia(x),
                    Type  = FileTypeHelper.GetFileTypeName(tempExt),
                    Size  = FileTypeHelper.GetFileSize(x)
                }
                                         ));
            }

            return(mediaMap);
        }