private ThemeMediaResult GetThemeSongs(GetThemeSongs 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 (GetThemeSongIds(item).Count == 0 && request.InheritFromParent && item.GetParent() != null) { item = item.GetParent(); } var dtoOptions = GetDtoOptions(request); var dtos = GetThemeSongIds(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) }); }
private ThemeMediaResult GetThemeSongs(GetThemeSongs 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 (GetThemeSongIds(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 themeSongIds = GetThemeSongIds(item); if (themeSongIds.Count == 0 && request.InheritFromParent) { var album = originalItem as MusicAlbum; if (album != null) { var linkedItemWithThemes = album.SoundtrackIds .Select(i => _libraryManager.GetItemById(i)) .FirstOrDefault(i => GetThemeSongIds(i).Count > 0); if (linkedItemWithThemes != null) { themeSongIds = GetThemeSongIds(linkedItemWithThemes); item = linkedItemWithThemes; } } } var dtos = themeSongIds.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) }); }
private ThemeMediaResult GetThemeSongs(GetThemeSongs 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.GetThemeSongs().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 }); }
private ThemeMediaResult GetThemeSongs(GetThemeSongs 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.ThemeSongIds.Length == 0) { var parent = item.GetParent(); if (parent == null) { break; } item = parent; } } var dtoOptions = GetDtoOptions(_authContext, request); var dtos = item.ThemeSongIds.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) }); }
/// <summary> /// Gets the specified request. /// </summary> /// <param name="request">The request.</param> /// <returns>System.Object.</returns> public object Get(GetThemeSongs request) { var result = GetThemeSongs(request); return(ToOptimizedSerializedResultUsingCache(result)); }
/// <summary> /// Gets the specified request. /// </summary> /// <param name="request">The request.</param> /// <returns>System.Object.</returns> public object Get(GetThemeSongs request) { var result = GetThemeSongs(request); return(ToOptimizedResult(result)); }