Esempio n. 1
0
        public async Task <IHttpActionResult> GetLeaderboards(
            Products products,
            Modes modes,
            Runs runs,
            Characters characters,
            bool?production  = null,
            bool?coOp        = null,
            bool?customMusic = null,
            CancellationToken cancellationToken = default)
        {
            var query = from l in db.Leaderboards.AsNoTracking()
                        where products.Contains(l.Product.Name)
                        where modes.Contains(l.Mode.Name)
                        where runs.Contains(l.Run.Name)
                        where characters.Contains(l.Character.Name)
                        select l;

            if (production != null)
            {
                query = query.Where(l => l.IsProduction == production);
            }
            if (coOp != null)
            {
                query = query.Where(l => l.IsCoOp == coOp);
            }
            if (customMusic != null)
            {
                query = query.Where(l => l.IsCustomMusic == customMusic);
            }
            query = from l in query
                    orderby l.Product.ProductId descending, l.Character.Name, l.RunId
            select l;

            var total = await query.CountAsync(cancellationToken);

            var leaderboards = await(from l in query
                                     select new LeaderboardDTO
            {
                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,
                },
                ModeName = l.Mode.Name,
                Mode     = new ModeDTO
                {
                    Id          = l.Mode.ModeId,
                    Name        = l.Mode.Name,
                    DisplayName = l.Mode.DisplayName,
                },
                RunName = l.Run.Name,
                Run     = new RunDTO
                {
                    Id          = l.Run.RunId,
                    Name        = l.Run.Name,
                    DisplayName = l.Run.DisplayName,
                },
                CharacterName = l.Character.Name,
                Character     = new CharacterDTO
                {
                    Id          = l.Character.CharacterId,
                    Name        = l.Character.Name,
                    DisplayName = l.Character.DisplayName,
                },
                IsCoOp        = l.IsCoOp,
                IsCustomMusic = l.IsCustomMusic,
                Total         = l.Entries.Count,
            })
                               .ToListAsync(cancellationToken);

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

            return(Ok(content));
        }