Ejemplo n.º 1
0
        public IActionResult Contact()
        {
            // Ensures that the user is logged in and if not redirects to the login page
            if (!LoginUtility.CheckAuthenticated(HttpContext.Session))
            {
                return(RedirectToAction("Index", "Login"));
            }

            ViewData["Message"] = "Address";

            return(View());
        }
Ejemplo n.º 2
0
        public IActionResult Index()
        {
            // Ensures that the user is logged in and if not redirects to the login page
            if (!LoginUtility.CheckAuthenticated(HttpContext.Session))
            {
                return(RedirectToAction("Index", "Login"));
            }

            var _stats = _context.Stats.ToList();
            var _teams = _context.Team.ToList();

            // Fetch the 3 players with the most goals
            var stats = _context.Stats.Include(s => s.Player.Team)
                        .GroupBy(i => i.Player)
                        .Select(g => new { Player = g.Key, Team = g.Key.Team, Total = g.Sum(j => j.Goals) })
                        .OrderByDescending(g => g.Total).Take(3);

            // Convert from a dynamic type to a tuple (because of errors)
            List <(Player, Team, int)> realStats = new List <(Player, Team, int)>();

            foreach (var stat in stats.ToList())
            {
                realStats.Add((stat.Player, stat.Team, (int)stat.Total));
            }
            // Add to view
            ViewBag.topPlayers = realStats.ToList();

            // Fetch the teams with the most goals
            var teamStats = _context.Stats.Include(s => s.Player).Include(s => s.Player.Team)
                            .GroupBy(i => i.Player.Team)
                            .Select(g => new { Team = g.Key, Total = g.Sum(j => j.Player.Stats.Sum(k => k.Goals)) })
                            .OrderByDescending(g => g.Total).Take(3);

            // Convert from a dynamic type to a tuple (because of errors)
            List <(Team, int)> realTeamStats = new List <(Team, int)>();

            foreach (var stat in teamStats.ToList())
            {
                realTeamStats.Add((stat.Team, (int)stat.Total));
            }
            // Add to view
            ViewBag.topTeams = realTeamStats.ToList();

            return(View());
        }