Example #1
0
        public async Task <IActionResult> RecalcTop(string key, int amt = 100, int offset = 0, bool force = false)
        {
            await using var db = new DatabaseContext();

            var players = await db.Players.AsNoTracking()
                          .OrderByDescending(x => x.LocalPp)
                          .Skip(offset)
                          .Take(amt)
                          .ToArrayAsync();

            foreach (var player in players)
            {
                if (updateService.IsOutdated(player.UpdateTime) || force)
                {
                    playerQueue.AddToQueueInternal(player.Id.ToString());
                }
            }

            return(new OkResult());
        }
Example #2
0
        public async Task <IActionResult> GetResults(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(new JsonResult(new { Username = "******" }));
            }

            await using var db = new DatabaseContext();

            if (int.TryParse(name, out var playerId))
            {
                var dbPlayer = await db.Players.AsNoTracking().FirstOrDefaultAsync(x => x.Id == playerId);

                if (dbPlayer != null)
                {
                    var model = mapper.Map <PlayerModel>(dbPlayer);
                    model.Scores = await db.Scores.AsNoTracking()
                                   .Where(x => x.PlayerId == playerId)
                                   .OrderByDescending(x => x.LocalPp)
                                   .Include(x => x.Map)
                                   .ToListAsync();

                    model.Outdated = updateService.IsOutdated(model.UpdateTime);
                    return(new JsonResult(model));
                }
            }
            else
            {
                var dbPlayerId = await db.Players.AsNoTracking()
                                 .Where(x => x.Name.ToUpper() == name.ToUpper())
                                 .Select(x => x.Id)
                                 .FirstOrDefaultAsync();

                if (dbPlayerId != default)
                {
                    return(RedirectPermanent($"/api/GetResults?player={dbPlayerId}"));
                }
            }

            return(new JsonResult(new { Username = "******" }));
        }