Exemple #1
0
        public ThemeMediaResult GetThemeVideos(GetThemeVideos request)
        {
            var user = request.UserId.HasValue ? _userManager.GetUserById(request.UserId.Value) : null;

            var item = string.IsNullOrEmpty(request.Id)
                           ? (request.UserId.HasValue
                                  ? user.RootFolder
                                  : (Folder)_libraryManager.RootFolder)
                           : _dtoService.GetItemByDtoId(request.Id, request.UserId);

            var originalItem = item;

            while (GetThemeVideoIds(item).Count == 0 && request.InheritFromParent && item.Parent != null)
            {
                item = item.Parent;
            }

            // Get everything
            var fields = Enum.GetNames(typeof(ItemFields))
                         .Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true))
                         .ToList();

            var themeVideoIds = GetThemeVideoIds(item);

            if (themeVideoIds.Count == 0 && request.InheritFromParent)
            {
                var album = originalItem as MusicAlbum;

                if (album == null)
                {
                    album = originalItem.Parents.OfType <MusicAlbum>().FirstOrDefault();
                }

                if (album != null)
                {
                    var linkedItemWithThemes = album.SoundtrackIds
                                               .Select(i => _libraryManager.GetItemById(i))
                                               .FirstOrDefault(i => GetThemeVideoIds(i).Count > 0);

                    if (linkedItemWithThemes != null)
                    {
                        themeVideoIds = GetThemeVideoIds(linkedItemWithThemes);
                        item          = linkedItemWithThemes;
                    }
                }
            }

            var dtos = themeVideoIds.Select(_libraryManager.GetItemById)
                       .OrderBy(i => i.SortName)
                       .Select(i => _dtoService.GetBaseItemDto(i, fields, user, item));

            var items = dtos.ToArray();

            return(new ThemeMediaResult
            {
                Items = items,
                TotalRecordCount = items.Length,
                OwnerId = _dtoService.GetDtoId(item)
            });
        }
Exemple #2
0
        public ThemeMediaResult GetThemeVideos(GetThemeVideos request)
        {
            var user = !string.IsNullOrWhiteSpace(request.UserId) ? _userManager.GetUserById(request.UserId) : null;

            var item = string.IsNullOrEmpty(request.Id)
                           ? (!string.IsNullOrWhiteSpace(request.UserId)
                                  ? user.RootFolder
                                  : (Folder)_libraryManager.RootFolder)
                           : _libraryManager.GetItemById(request.Id);

            while (GetThemeVideoIds(item).Count == 0 && request.InheritFromParent && item.GetParent() != null)
            {
                item = item.GetParent();
            }

            var dtoOptions = GetDtoOptions(request);

            var dtos = GetThemeVideoIds(item).Select(_libraryManager.GetItemById)
                       .OrderBy(i => i.SortName)
                       .Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, item));

            var items = dtos.ToArray();

            return(new ThemeMediaResult
            {
                Items = items,
                TotalRecordCount = items.Length,
                OwnerId = _dtoService.GetDtoId(item)
            });
        }
        public ThemeMediaResult GetThemeVideos(GetThemeVideos request)
        {
            var user = !request.UserId.Equals(Guid.Empty) ? _userManager.GetUserById(request.UserId) : null;

            var item = string.IsNullOrEmpty(request.Id)
                           ? (!request.UserId.Equals(Guid.Empty)
                                  ? _libraryManager.GetUserRootFolder()
                                  : (Folder)_libraryManager.RootFolder)
                           : _libraryManager.GetItemById(request.Id);

            if (item == null)
            {
                throw new ResourceNotFoundException("Item not found.");
            }

            BaseItem[] themeItems = Array.Empty <BaseItem>();

            while (true)
            {
                themeItems = item.GetThemeVideos().ToArray();

                if (themeItems.Length > 0)
                {
                    break;
                }

                if (!request.InheritFromParent)
                {
                    break;
                }

                var parent = item.GetParent();
                if (parent == null)
                {
                    break;
                }
                item = parent;
            }

            var dtoOptions = GetDtoOptions(_authContext, request);

            var dtos = themeItems
                       .Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, item));

            var items = dtos.ToArray();

            return(new ThemeMediaResult
            {
                Items = items,
                TotalRecordCount = items.Length,
                OwnerId = item.Id
            });
        }
Exemple #4
0
        public ThemeMediaResult GetThemeVideos(GetThemeVideos request)
        {
            var user = !string.IsNullOrWhiteSpace(request.UserId) ? _userManager.GetUserById(request.UserId) : null;

            var item = string.IsNullOrEmpty(request.Id)
                           ? (!string.IsNullOrWhiteSpace(request.UserId)
                                  ? _libraryManager.GetUserRootFolder()
                                  : (Folder)_libraryManager.RootFolder)
                           : _libraryManager.GetItemById(request.Id);

            if (item == null)
            {
                throw new ResourceNotFoundException("Item not found.");
            }

            if (request.InheritFromParent)
            {
                while (item.ThemeVideoIds.Length == 0)
                {
                    var parent = item.GetParent();
                    if (parent == null)
                    {
                        break;
                    }
                    item = parent;
                }
            }

            var dtoOptions = GetDtoOptions(_authContext, request);

            var dtos = item.ThemeVideoIds.Select(_libraryManager.GetItemById)
                       .Where(i => i != null)
                       .OrderBy(i => i.SortName)
                       .Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, item));

            var items = dtos.ToArray();

            return(new ThemeMediaResult
            {
                Items = items,
                TotalRecordCount = items.Length,
                OwnerId = _dtoService.GetDtoId(item)
            });
        }
Exemple #5
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public object Get(GetThemeVideos request)
        {
            var result = GetThemeVideos(request);

            return(ToOptimizedSerializedResultUsingCache(result));
        }
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public object Get(GetThemeVideos request)
        {
            var result = GetThemeVideos(request);

            return(ToOptimizedResult(result));
        }