public async Task <LeaderboardView> GetLeaderboard(ulong userId, List <SocketGuildUser> users) { IEnumerable <UserEntity> entities = await _repository.GetAllUsersAsync(); var rankedEntities = entities .OrderByDescending(e => e.Funds) .ToList(); var top5 = await Task.WhenAll( rankedEntities .Take(5) .Select((entity, index) => GetRankedUser(entity, index + 1, users))); UserEntity userEntity = rankedEntities.FirstOrDefault(e => e.UserId == userId); if (userEntity == null) { return(new LeaderboardView { TopUsers = top5, IssuerRanking = null, TotalUsers = rankedEntities.Count() }); } int rank = rankedEntities.IndexOf(userEntity) + 1; RankedUser rankedUser = await GetRankedUser(userEntity, rank, users); return(new LeaderboardView { TopUsers = top5, IssuerRanking = rankedUser, TotalUsers = rankedEntities.Count() }); }
private static string UserRankDescription(RankedUser u) { if (u == null) { return("Fella is off the books"); } return($"{u.Rank}. {u.User?.Username ?? "Unknown"} ({u.Points})"); }