Ejemplo n.º 1
0
        public ChampionViewModel()
        {
            var dbContext = new ApplicationDbContext();
            var champions = RiotService.ChampionsService().Champions;

            Champions = FakeData.Get();
        }
Ejemplo n.º 2
0
        public ActionResult Index()
        {
            try
            {
                var model = new MatchesViewModel {
                    ChampionData = RiotService.ChampionsService()
                };

                using (var riotDb = new RiotDataContext())
                    model.Matches = riotDb.Matches.Select(x => x.MatchId).ToList();

                model.CurrentMatchData = RiotService.MatchService(model.Matches.First());
                model.CurrentMatchId   = model.Matches.First();
                CurrentMatchModel      = model;
                return(View(model));
            }
            catch (Exception e)
            {
                return(View("Error", new HandleErrorInfo(e, "Home", "Index")));
            }
        }
Ejemplo n.º 3
0
        public ActionResult Index()
        {
            try
            {
                using (var riotDb = new RiotDataContext())
                {
                    var championData = RiotService.ChampionsService();

                    var availableChampionIds = riotDb.Participants
                                               .Select(m => m.ChampionId ?? 0).ToList()
                                               .Where(m => m != 0).Distinct().ToList();

                    var availableChampions = championData.Champions
                                             .Where(x => availableChampionIds.Contains(x.Key))
                                             .Select(x => x.Value).OrderBy(x => x.Name).ToList();

                    var ids = new List <int?> {
                        availableChampions[0].Id, availableChampions[1].Id, availableChampions[2].Id
                    };

                    var championTotals = new TotalsStatistics(ids, riotDb);

                    var model = new ChampionsViewModel
                    {
                        AvailableChampions = availableChampions,
                        ChampionCount      = ids.Count,
                        ChampionTotals     = championTotals,
                        ChampionIds        = ids
                    };

                    CurrentChampionsModel = model;
                    return(View(model));
                }
            }
            catch (Exception e)
            {
                return(View("Error", new HandleErrorInfo(e, "Champions", "Index")));
            }
        }
Ejemplo n.º 4
0
        public ActionResult Index()
        {
            try
            {
                var model = new FunStatViewModel();

                using (var riotDb = new RiotDataContext())
                {
                    model.ChampionData = RiotService.ChampionsService();

                    model.MatchCount = riotDb.Matches.Count();
                    var funStats = riotDb.FunStats().ToList();

                    var wonMatches  = riotDb.Teams.Where(x => x.Winner == true);
                    var lostMatches = riotDb.Teams.Where(x => x.Winner == false);

                    var matchData = wonMatches.Join(lostMatches, a => a.MatchId, b => b.MatchId,
                                                    (a, b) => new MatchData(a, b))
                                    .ToList();

                    model.WinData.Add(new FunStatsResponse
                    {
                        Name = "Baron Kills",
                        Won  = matchData.Count(x => x.WinningTeam.BaronKills > x.LosingTeam.BaronKills),
                        Lost = matchData.Count(x => x.WinningTeam.BaronKills < x.LosingTeam.BaronKills),
                        Tied = matchData.Count(x => x.WinningTeam.BaronKills == x.LosingTeam.BaronKills)
                    });

                    model.WinData.Add(new FunStatsResponse
                    {
                        Name = "Dragon Kills",
                        Won  = matchData.Count(x => x.WinningTeam.DragonKills > x.LosingTeam.DragonKills),
                        Lost = matchData.Count(x => x.WinningTeam.DragonKills < x.LosingTeam.DragonKills),
                        Tied = matchData.Count(x => x.WinningTeam.DragonKills == x.LosingTeam.DragonKills)
                    });

                    model.WinData.Add(funStats.First(x => x.Name == "Minion Kills"));
                    model.WinData.Add(funStats.First(x => x.Name == "Kills"));
                    model.WinData.Add(funStats.First(x => x.Name == "Wards"));

                    model.GamesWithNoDragons = matchData.Count(x => x.WinningTeam.DragonKills == 0 && x.LosingTeam.DragonKills == 0);
                    model.GamesWithNoBarons  = matchData.Count(x => x.WinningTeam.BaronKills == 0 && x.LosingTeam.BaronKills == 0);

                    var playedChamps = riotDb.Participants.GroupBy(x => x.ChampionId)
                                       .Select(g => new PlayedChampionData {
                        ChampionId = g.Key ?? 0, PlayCount = g.Count()
                    })
                                       .OrderByDescending(x => x.PlayCount);

                    model.MostPlayedChampions  = playedChamps.Take(5).ToList();
                    model.LeastPlayedChampions =
                        playedChamps.OrderBy(x => x.PlayCount).Take(5).OrderByDescending(x => x.PlayCount).ToList();

                    var participantsAndStats = riotDb.Participants.Join(riotDb.ParticipantStats, p => p.Id, s => s.Id,
                                                                        (p, s) => new { Participant = p, ParticipantStats = s });

                    var participantsAndStatsWinners = participantsAndStats.Where(x => x.ParticipantStats.Winner == true).GroupBy(x => x.Participant.ChampionId).Select(x => new WinRateChampionData {
                        ChampionId = x.Key ?? 0, WinCount = x.Count()
                    });
                    var participantsAndStatsLosers = participantsAndStats.Where(x => x.ParticipantStats.Winner == false).GroupBy(x => x.Participant.ChampionId).Select(x => new WinRateChampionData {
                        ChampionId = x.Key ?? 0, LossCount = x.Count()
                    });

                    model.WinRateChampionData =
                        participantsAndStatsWinners.Join(participantsAndStatsLosers,
                                                         w => w.ChampionId,
                                                         l => l.ChampionId,
                                                         (w, l) => new WinRateChampionData
                    {
                        ChampionId = w.ChampionId,
                        WinCount   = w.WinCount,
                        LossCount  = l.LossCount
                    })
                        .ToList()
                        .OrderByDescending(x => x.WinRate)
                        .Take(5)
                        .ToList();


                    return(View(model));
                }
            }
            catch (Exception e)
            {
                return(View("Error", new HandleErrorInfo(e, "Home", "Index")));
            }
        }