示例#1
0
        private async Task<SearchResult<GameData>> FindGamesInternalAsync(GameSearchFilter filter, CancellationToken cancellationToken)
        {
            var query = _context.Game.AsQueryable();

            if (filter.GameId.HasValue)
            {
                query = query.Where(x => x.GamePk == filter.GameId.Value);
            }

            if (filter.Type.HasValue)
            {
                query = query.Where(x => x.GameTypeFk == (int)filter.Type.Value);
            }

            var totalCount = await query.CountAsync(cancellationToken: cancellationToken);

            query = query.OrderByDescending(x => x.GamePk);

            query = query.Skip(0).Take(DefaultPageSize);

            var results = query.Select(_gameMapper.Map).ToArray();

            var result = new SearchResult<GameData>
            {
                CurrentPage = 0,
                PageSize = DefaultPageSize,
                Results = results,
                TotalCount = totalCount,
            };

            return result;
        }
示例#2
0
        private async Task<GameData> GetGameByIdInternalAsync(int id, CancellationToken cancellationToken)
        {
            var filter = new GameSearchFilter
            {
                GameId = id,
            };
            var games = await FindGamesInternalAsync(filter, cancellationToken);

            return games.Results.FirstOrDefault();
        }
示例#3
0
        public void ExecuteGameSearchFilter_ShouldReturnNotNull_WhenSearch()
        {
            // Arrange
            var releaseDateFilter = new GameSearchFilter("Search");

            // Act
            var result = releaseDateFilter.Execute(_ => true);

            // Assert
            Assert.NotNull(result.Compile());
        }
示例#4
0
        public async Task <GameGroup[]> ListGrouped(GameSearchFilter model, bool sudo)
        {
            DateTimeOffset now = DateTimeOffset.Now;

            var q = Store.List(model.Term);

            if (!sudo)
            {
                q = q.Where(g => g.IsPublished);
            }

            if (model.WantsPresent)
            {
                q = q.Where(g => g.GameEnd > now && g.GameStart < now);
            }
            if (model.WantsFuture)
            {
                q = q.Where(g => g.GameStart > now);
            }
            if (model.WantsPast)
            {
                q = q.Where(g => g.GameEnd < now);
            }

            var games = await q.ToArrayAsync();

            var b = games
                    .GroupBy(g => new
            {
                g.GameStart.Year,
                g.GameStart.Month,
            })
                    .Select(g => new GameGroup
            {
                Year  = g.Key.Year,
                Month = g.Key.Month,
                Games = g
                        .OrderBy(c => c.GameStart)
                        .Select(c => Mapper.Map <Game>(c))
                        .ToArray()
            });

            if (model.WantsPast)
            {
                b = b.OrderByDescending(g => g.Year).ThenByDescending(g => g.Month);
            }
            else
            {
                b = b.OrderBy(g => g.Year).ThenBy(g => g.Month);
            }

            return(b.ToArray());
        }
示例#5
0
        public async Task <Game[]> List(GameSearchFilter model, bool sudo)
        {
            DateTimeOffset now = DateTimeOffset.Now;

            var q = Store.List(model.Term);

            if (!sudo)
            {
                q = q.Where(g => g.IsPublished);
            }

            if (model.WantsPresent)
            {
                q = q.Where(g => g.GameEnd > now && g.GameStart < now);
            }

            if (model.WantsFuture)
            {
                q = q.Where(g => g.GameStart > now);
            }

            if (model.WantsPast)
            {
                q = q.Where(g => g.GameEnd < now);
            }

            if (model.WantsPast)
            {
                q = q.OrderByDescending(g => g.GameStart).ThenBy(g => g.Name);
            }
            else
            {
                q = q.OrderBy(g => g.GameStart).ThenBy(g => g.Name);
            }

            q = q.Skip(model.Skip);

            if (model.Take > 0)
            {
                q = q.Take(model.Take);
            }

            // Use Map instead of 'Mapper.ProjectTo<Game>' to support YAML parsing in automapper
            return(Mapper.Map <Game[]>(await q.ToArrayAsync()));
        }
示例#6
0
 Task<SearchResult<GameData>> IGameRepository.FindGamesAsync(GameSearchFilter filter, CancellationToken cancellationToken)
 {
     return FindGamesInternalAsync(filter, cancellationToken);
 }
示例#7
0
 public async Task <GameGroup[]> ListGrouped([FromQuery] GameSearchFilter model)
 {
     return(await GameService.ListGrouped(model, Actor.IsDesigner || Actor.IsTester));
 }