예제 #1
0
        public async Task <IHttpActionResult> GetDailyLeaderboards(
            LeaderboardsPagination pagination,
            Products products,
            DateTime?date   = null,
            bool?production = null,
            CancellationToken cancellationToken = default)
        {
            var query = from l in db.DailyLeaderboards.AsNoTracking()
                        where products.Contains(l.Product.Name)
                        select l;

            if (date != null)
            {
                query = query.Where(l => l.Date == date);
            }
            if (production != null)
            {
                query = query.Where(l => l.IsProduction == production);
            }
            query = from l in query
                    orderby l.Date descending, l.ProductId descending, l.IsProduction descending
            select l;

            var total = await query.CountAsync(cancellationToken);

            var leaderboards = await(from l in query
                                     select new DailyLeaderboardDTO
            {
                Id           = l.LeaderboardId,
                UpdatedAt    = l.LastUpdate,
                Name         = l.Name,
                DisplayName  = l.DisplayName,
                IsProduction = l.IsProduction,
                ProductName  = l.Product.Name,
                Product      = new ProductDTO
                {
                    Id          = l.Product.ProductId,
                    Name        = l.Product.Name,
                    DisplayName = l.Product.DisplayName,
                },
                Date  = l.Date,
                Total = l.Entries.Count,
            })
                               .Page(pagination)
                               .ToListAsync(cancellationToken);

            var content = new DailyLeaderboardsEnvelope
            {
                Total        = total,
                Leaderboards = leaderboards,
            };

            return(Ok(content));
        }
예제 #2
0
        public async Task <IHttpActionResult> GetDailyLeaderboardEntries(
            LeaderboardsPagination pagination,
            int lbid,
            CancellationToken cancellationToken = default)
        {
            // Validate lbid
            var leaderboard = await(from l in db.DailyLeaderboards.AsNoTracking()
                                    where l.LeaderboardId == lbid
                                    select new DailyLeaderboardDTO
            {
                Id           = l.LeaderboardId,
                UpdatedAt    = l.LastUpdate,
                Name         = l.Name,
                DisplayName  = l.DisplayName,
                IsProduction = l.IsProduction,
                ProductName  = l.Product.Name,
                Product      = new ProductDTO
                {
                    Id          = l.Product.ProductId,
                    Name        = l.Product.Name,
                    DisplayName = l.Product.DisplayName,
                },
                Date  = l.Date,
                Total = l.Entries.Count,
            })
                              .FirstOrDefaultAsync(cancellationToken);

            if (leaderboard == null)
            {
                return(NotFound());
            }

            var query = from e in db.DailyEntries.AsNoTracking()
                        where e.LeaderboardId == lbid
                        orderby e.Rank
                        select e;

            var total = await query.CountAsync(cancellationToken);

            var entries = await(from e in query
                                let p                 = e.Player
                                                let r = e.Replay
                                                        select new EntryDTO
            {
                Player = new PlayerDTO
                {
                    Id          = p.SteamId.ToString(),
                    UpdatedAt   = p.LastUpdate,
                    DisplayName = p.Name,
                    Avatar      = p.Avatar,
                },
                Rank  = e.Rank,
                Score = e.Score,
                End   = new EndDTO
                {
                    Zone  = e.Zone,
                    Level = e.Level,
                },
                KilledBy = r.KilledBy,
                Version  = r.Version,
            })
                          .Page(pagination)
                          .ToListAsync(cancellationToken);

            var content = new DailyLeaderboardEntriesDTO
            {
                Leaderboard = leaderboard,
                Total       = total,
                Entries     = entries,
            };

            return(Ok(content));
        }