예제 #1
0
        public object Get(GetGamesView request)
        {
            var user = _userManager.GetUserById(request.UserId);

            var items = GetAllLibraryItems(user.Id, _userManager, _libraryManager, request.ParentId).Where(i => i is Game || i is GameSystem)
                        .ToList();

            var gamesWithImages = items.OfType <Game>().Where(i => !string.IsNullOrEmpty(i.PrimaryImagePath)).ToList();

            var itemsWithBackdrops = FilterItemsForBackdropDisplay(items.Where(i => i.GetImages(ImageType.Backdrop).Any())).ToList();

            var gamesWithBackdrops = itemsWithBackdrops.OfType <Game>().ToList();

            var view = new GamesView();

            var fields = new List <ItemFields>();

            view.GameSystems = items
                               .OfType <GameSystem>()
                               .OrderBy(i => i.SortName)
                               .Select(i => _dtoService.GetBaseItemDto(i, fields, user))
                               .ToList();

            var currentUserId = user.Id;

            view.RecentlyPlayedGames = gamesWithImages
                                       .OrderByDescending(i => _userDataManager.GetUserData(currentUserId, i.GetUserDataKey()).LastPlayedDate ?? DateTime.MinValue)
                                       .Take(request.RecentlyPlayedGamesLimit)
                                       .Select(i => _dtoService.GetBaseItemDto(i, fields, user))
                                       .ToList();

            view.BackdropItems = gamesWithBackdrops
                                 .OrderBy(i => Guid.NewGuid())
                                 .Take(10)
                                 .Select(i => _dtoService.GetBaseItemDto(i, fields, user))
                                 .ToList();

            view.SpotlightItems = gamesWithBackdrops
                                  .OrderBy(i => Guid.NewGuid())
                                  .Take(10)
                                  .Select(i => _dtoService.GetBaseItemDto(i, fields, user))
                                  .ToList();

            view.MultiPlayerItems = gamesWithImages
                                    .Where(i => i.PlayersSupported.HasValue && i.PlayersSupported.Value > 1)
                                    .Randomize()
                                    .Select(i => GetItemStub(i, ImageType.Primary))
                                    .Where(i => i != null)
                                    .Take(1)
                                    .ToList();

            return(ToOptimizedSerializedResultUsingCache(view));
        }
예제 #2
0
        public object Get(GetGamesView request)
        {
            var user = _userManager.GetUserById(request.UserId);

            var items = user.RootFolder.GetRecursiveChildren(user, i => i is Game || i is GameSystem)
                        .ToList();

            var gamesWithImages = items.OfType <Game>().Where(i => !string.IsNullOrEmpty(i.PrimaryImagePath)).ToList();

            var itemsWithBackdrops = FilterItemsForBackdropDisplay(items.Where(i => i.BackdropImagePaths.Count > 0)).ToList();

            var gamesWithBackdrops = itemsWithBackdrops.OfType <Game>().ToList();

            var view = new GamesView();

            var fields = new List <ItemFields>();

            view.BackdropItems = gamesWithBackdrops
                                 .OrderBy(i => Guid.NewGuid())
                                 .Take(10)
                                 .Select(i => _dtoService.GetBaseItemDto(i, fields, user))
                                 .ToList();

            view.SpotlightItems = gamesWithBackdrops
                                  .OrderBy(i => Guid.NewGuid())
                                  .Take(10)
                                  .Select(i => _dtoService.GetBaseItemDto(i, fields, user))
                                  .ToList();

            view.MultiPlayerItems = gamesWithImages
                                    .Where(i => i.PlayersSupported.HasValue && i.PlayersSupported.Value > 1)
                                    .OrderBy(i => Guid.NewGuid())
                                    .Select(i => GetItemStub(i, ImageType.Primary))
                                    .Where(i => i != null)
                                    .Take(1)
                                    .ToList();

            view.MiniSpotlights = gamesWithBackdrops
                                  .OrderBy(i => Guid.NewGuid())
                                  .Take(5)
                                  .Select(i => _dtoService.GetBaseItemDto(i, fields, user))
                                  .ToList();

            return(ToOptimizedResult(view));
        }