public ActionResult Performances(Guid playerId)
        {
            PerformancesViewModelBuilder builder = new PerformancesViewModelBuilder();
            SoloQServices sq                  = new SoloQServices();
            var           dal                 = new DAL();
            var           player              = dal.getPlayerById(playerId);
            var           matches             = sq.GetSoloQHistories(player.AccountId, 70);
            List <PerformancesViewModel> lpvm = new List <PerformancesViewModel>();

            if (player != null)
            {
                lpvm = builder.BuildPerformanceViewModel(matches, player);
                var nickname = sq.GetNicknameByAccountId(player.AccountId);
                ViewBag.SummonerName = nickname;
                ViewBag.Role         = player.Role;
            }
            return(View(lpvm));
        }
Пример #2
0
        public WinratesViewModel BuildWinratesViewModel(int nbGames, Player player)
        {
            SoloQServices     sq  = new SoloQServices();
            WinratesViewModel wrm = null;
            var ps      = new PerformanceServices();
            var matches = sq.GetSoloQHistories(player.AccountId, nbGames).OrderByDescending(x => x.timestamp).ToList();

            if (matches != null)
            {
                if (player.Role != 0)
                {
                    matches = ps.GetListMatchByRole(matches, player);
                }
                wrm            = new WinratesViewModel();
                wrm.nickname   = player.Nickname;
                wrm.blueSide   = new WinratesViewModel.Side();
                wrm.redSide    = new WinratesViewModel.Side();
                wrm.totalGames = nbGames;
                wrm.role       = GlobalVar.getRoleById(player.Role);

                foreach (var match in matches)
                {
                    var matchInfos = sq.GetMatchInfo(match.gameId.ToString());
                    //savoir dans quel side il était et si il a win
                    var  team          = ps.GetPlayerTeam(matchInfos, player);
                    var  isWin         = matchInfos.teams.Where(x => x.teamId == team).FirstOrDefault()?.win;
                    bool isBlueSideWin = false;
                    if (team == 100)
                    {
                        if (isWin.ToLower() == "win")
                        {
                            wrm.blueSide.totalGames++;
                            wrm.blueSide.nbWin++;
                            wrm.totalGamesOnlyMainRole++;
                            isBlueSideWin = true;
                        }
                        else if (isWin.ToLower() == "fail")
                        {
                            wrm.blueSide.totalGames++;
                            wrm.blueSide.nbLoss++;
                            wrm.totalGamesOnlyMainRole++;
                        }
                    }
                    else if (team == 200)
                    {
                        if (isWin.ToLower() == "win")
                        {
                            wrm.redSide.totalGames++;
                            wrm.redSide.nbWin++;
                            wrm.totalGamesOnlyMainRole++;
                        }
                        else if (isWin.ToLower() == "fail")
                        {
                            wrm.redSide.totalGames++;
                            wrm.redSide.nbLoss++;
                            wrm.totalGamesOnlyMainRole++;
                            isBlueSideWin = true;
                        }
                    }
                    int participantId = ps.GetParticipantId(matchInfos, player);
                    if (participantId != 0)
                    {
                        CalculateDraftPosition(wrm, matchInfos, participantId, isBlueSideWin);
                    }
                }
            }

            return(wrm);
        }