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); while (item.ThemeVideoIds.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 dtos = item.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) }); }
public async Task <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) : DtoBuilder.GetItemByClientId(request.Id, _userManager, _libraryManager, request.UserId); while (item.ThemeVideoIds.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 dtoBuilder = new DtoBuilder(Logger, _libraryManager, _userDataRepository, _itemRepo); var tasks = item.ThemeVideoIds.Select(_itemRepo.RetrieveItem) .OrderBy(i => i.SortName) .Select(i => dtoBuilder.GetBaseItemDto(i, fields, user, item)); var items = await Task.WhenAll(tasks).ConfigureAwait(false); return(new ThemeMediaResult { Items = items, TotalRecordCount = items.Length, OwnerId = DtoBuilder.GetClientItemId(item) }); }
/// <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).Result; return(ToOptimizedResult(result)); }