Exemple #1
0
        public IActionResult Player(string username)
        {
            username = WebUtility.UrlDecode(username);
            Player player = _db.UsersWithPlayer().FirstOrDefault(x => x.UserName == username)?.PlayerStats;

            if (player == null)
            {
                return(NotFound());
            }
            else
            {
                ProfileViewModel me = new ProfileViewModel();
                int gp = _stats.GetGamesPlayed(player);
                int w  = _stats.GetWins(player);
                int g  = _stats.GetGoals(player);
                int a  = _stats.GetAssists(player);
                me.PlayerStats = new PlayerStatsViewModel(player.Name, player.RatingString, g, a, gp, w);
                return(View(me));
            }
        }
Exemple #2
0
        public IEnumerable <PlayerStatsViewModel> GetLeaderboard()
        {
            List <PlayerStatsViewModel> entries;

            if (!_cache.TryGetValue(k_LeaderboardCacheKey, out entries))
            {
                entries = new List <PlayerStatsViewModel>();
                foreach (Player player in _db.Players())
                {
                    int gp = _statsService.GetGamesPlayed(player);
                    if (gp >= MIN_GAMES)
                    {
                        int w = _statsService.GetWins(player);
                        int g = _statsService.GetGoals(player);
                        int a = _statsService.GetAssists(player);
                        entries.Add(new PlayerStatsViewModel(player.Name, player.RatingString, g, a, gp, w));
                    }
                }
                _cache.Set(k_LeaderboardCacheKey, entries);
            }
            return(entries.OrderByDescending(o => o.Rating));
        }