//----------------------------------------------------------------------
        #region public functions
        //----------------------------------------------------------------------
        public override void execCmd(Connection db)
        {
            base.execCmd(db);

            ArrMatches = new List <Match>();

            ArrMatches = MatchDB.getAllTeams(db);
        }
Exemple #2
0
        //---------------------------------------------------------------------
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                using (MatchDB db = new MatchDB())
                {
                    db.Dispose();
                }
            }

            base.Dispose(disposing);
        }
Exemple #3
0
        public IActionResult ShowMore()
        {
            Summoner summ       = HttpContext.Session.GetSummoner();
            Summoner summoner   = _context.Summoners.Where(s => s.Id == summ.Id).FirstOrDefault();
            int?     matchIndex = HttpContext.Session.GetInt32("matchIndex");

            if (summoner == null)
            {
                return(RedirectToAction("Index"));
            }
            if (matchIndex == null)
            {
                matchIndex = 5;
            }


            // Get match list from DB
            MatchesResponse matches = _context.MatchesResponses.Where(r => r.SummonerID == summoner.Id).FirstOrDefault();

            matches.Matches = _context.Matches.Where(m => m.MatchesResponseID == matches.MatchesResponseID).OrderByDescending(m => m.Timestamp).ToList();

            // Setup new match list
            Match_V4        matchv4    = new Match_V4(summoner.Region);
            MatchesResponse newMatches = matchv4.GetMoreMatchesByAccountID(summoner.AccountId, (int)matchIndex);

            foreach (Matches match in newMatches.Matches)
            {
                MatchDTO matchDTO = matchv4.GetMatchByMatchID(match.GameID);
                MatchDB  matchDB  = matchDTO.ConvertMatchDTOToDBv2(_context);
                matchDB = _context.MatchesDB.Where(m => m.GameID == matchDB.GameID).FirstOrDefault();
                match.MatchesResponseID = matches.MatchesResponseID;
                match.MatchDB           = matchDB;
                matches.Matches.Add(match);
                foreach (PlayerInfoDB p in matchDB.PlayerInfos)
                {
                    if (p.SummonerID == summoner.Id)
                    {
                        summoner.Kills   += p.Kills;
                        summoner.Deaths  += p.Deaths;
                        summoner.Assists += p.Assists;
                    }
                }
            }
            summoner.KDA = ((summoner.Kills + summoner.Assists) / (float)Math.Max(summoner.Deaths, 1));
            _context.Summoners.Update(summoner);
            _context.SaveChanges();
            FindModel fm = new FindModel {
                Name = summoner.Name, Region = summoner.Region
            };

            return(RedirectToAction("Profile", fm));
        }
Exemple #4
0
        //---------------------------------------------------------------------
        // GET: Match
        public ActionResult Index()
        {
            CmdGetMatches cmd = new CmdGetMatches();

            using (MatchDB db = new MatchDB())
            {
                cmd.execCmd(db);
            }

            ViewBag.arrTeams = cmd.ArrTeams;

            return(View(cmd.ArrMatches));
        }
Exemple #5
0
        public JsonResult PlayMatchCheckWinner(int idTeamHome, int idTeamVisitor)
        {
            if (ModelState.IsValid)
            {
                CmdPlayMatchCheckWinner cmd = new CmdPlayMatchCheckWinner(idTeamHome, idTeamVisitor);

                using (MatchDB db = new MatchDB())
                {
                    cmd.execCmd(db);
                }

                return(Json(new { success = true, cmd.Match }));
            }
            return(Json(new { success = false, error = Mensagens.ERR_NO_MATCH_RESULT }));
        }
        // Find checkedPlayers and matchesList collections
        void CheckedPLayersToMatches(List <CheckBox> playersCheckList)
        {
            // send checked players from playersCheckList to checkedPLayers
            for (int i = 0; i < playersCheckList.Count; i++)
            {
                if (playersCheckList[i].IsChecked == true)
                {
                    checkedPlayers.Add(playersCheckList[i].Content.ToString());
                }
            }

            // load match lists of checkedPlayers to matchList
            for (int i = 0; i < checkedPlayers.Count; i++)
            {
                MatchDB.LoadMatches(ref matches, checkedPlayers[i], CurrentUserElements.Player.ID);
                matchesList.Add(matches);
            }
        }
Exemple #7
0
        public static MatchDB ConvertMatchDTOToDBv2(this MatchDTO dto, ApplicationDbContext context)
        {
            MatchDB match = new MatchDB
            {
                GameID       = dto.GameID,
                QueueID      = dto.QueueID,
                GameType     = dto.GameType,
                GameDuration = dto.GameDuration,
                GameMode     = dto.GameMode,
                PlatformID   = dto.PlatformID,
                SeasonID     = dto.SeasonID,
                MapID        = dto.MapID,
                Teams        = dto.Teams.Select(t => new TeamStatsDB
                {
                    GameID          = dto.GameID,
                    TowerKills      = t.TowerKills,
                    RiftHeraldKills = t.RiftHeraldKills,
                    FirstBlood      = t.FirstBlood,
                    InhibitorKills  = t.InhibitorKills,
                    DragonKills     = t.DragonKills,
                    BaronKills      = t.BaronKills,
                    TeamID          = t.TeamID,
                    Win             = t.Win
                }).ToList(),
            };

            for (int i = 0; i < 10; i++)
            {
                PlayerInfoDB player = new PlayerInfoDB
                {
                    GameID                      = dto.GameID,
                    ProfileIcon                 = dto.ParticipantIdentities[i].Player.ProfileIcon,
                    MatchHistoryURI             = dto.ParticipantIdentities[i].Player.MatchHistoryURI,
                    SummonerName                = dto.ParticipantIdentities[i].Player.SummonerName,
                    SummonerID                  = dto.ParticipantIdentities[i].Player.SummonerID,
                    PlatformID                  = dto.ParticipantIdentities[i].Player.PlatformID,
                    ParticipantID               = dto.Participants[i].ParticipantID,
                    ChampionID                  = dto.Participants[i].ChampionID,
                    TeamID                      = dto.Participants[i].TeamID,
                    Spell1ID                    = dto.Participants[i].Spell1ID,
                    Spell2ID                    = dto.Participants[i].Spell2ID,
                    HighestAchievedSeasonTier   = dto.Participants[i].HighestAchievedSeasonTier,
                    GoldEarned                  = dto.Participants[i].Stats.GoldEarned,
                    TotalPlayerScore            = dto.Participants[i].Stats.TotalPlayerScore,
                    ChampLevel                  = dto.Participants[i].Stats.ChampLevel,
                    Deaths                      = dto.Participants[i].Stats.Deaths,
                    TotalScoreRank              = dto.Participants[i].Stats.TotalScoreRank,
                    WardsPlaced                 = dto.Participants[i].Stats.WardsPlaced,
                    TotalDamageDealt            = dto.Participants[i].Stats.TotalDamageDealt,
                    LargestKillingSpree         = dto.Participants[i].Stats.LargestKillingSpree,
                    TotalDamageDealtToChampions = dto.Participants[i].Stats.TotalDamageDealtToChampions,
                    TotalMinionsKilled          = dto.Participants[i].Stats.TotalMinionsKilled,
                    ObjectivePlayerScore        = dto.Participants[i].Stats.ObjectivePlayerScore,
                    Kills             = dto.Participants[i].Stats.Kills,
                    CombatPlayerScore = dto.Participants[i].Stats.CombatPlayerScore,
                    Assists           = dto.Participants[i].Stats.Assists,
                    Win            = dto.Participants[i].Stats.Win,
                    VisionScore    = dto.Participants[i].Stats.VisionScore,
                    FirstBloodKill = dto.Participants[i].Stats.FirstBloodKill
                };
                match.PlayerInfos.Add(player);
            }
            context.MatchesDB.Add(match);


            context.SaveChanges();
            return(match);
        }
Exemple #8
0
        public static MatchDB ConvertMatchDTOToDB(this MatchDTO dto, ApplicationDbContext context)
        {
            MatchDB match = new MatchDB
            {
                GameID                = dto.GameID,
                QueueID               = dto.QueueID,
                GameType              = dto.GameType,
                GameDuration          = dto.GameDuration,
                GameMode              = dto.GameMode,
                PlatformID            = dto.PlatformID,
                SeasonID              = dto.SeasonID,
                MapID                 = dto.MapID,
                ParticipantIdentities = dto.ParticipantIdentities
                                        .Select(p => new ParticipantIdentityDB {
                    Player = new PlayerDB
                    {
                        ProfileIcon       = p.Player.ProfileIcon,
                        AccountID         = p.Player.AccountID,
                        MatchHistoryURI   = p.Player.MatchHistoryURI,
                        CurrentAccountID  = p.Player.CurrentAccountID,
                        CurrentPlatformID = p.Player.CurrentPlatformID,
                        SummonerName      = p.Player.SummonerName,
                        PlatformID        = p.Player.PlatformID
                    }
                }).ToList(),
                Teams = dto.Teams.Select(t => new TeamStatsDB {
                    TowerKills      = t.TowerKills,
                    RiftHeraldKills = t.RiftHeraldKills,
                    FirstBlood      = t.FirstBlood,
                    InhibitorKills  = t.InhibitorKills,
                    DragonKills     = t.DragonKills,
                    BaronKills      = t.BaronKills,
                    TeamID          = t.TeamID,
                    Win             = t.Win
                }).ToList(),
                Participants = dto.Participants
                               .Select(p => new ParticipantDB {
                    ParticipantID = p.ParticipantID,
                    ChampionID    = p.ChampionID,
                    Stats         = new ParticipantStatsDB
                    {
                        GoldEarned                  = p.Stats.GoldEarned,
                        TotalPlayerScore            = p.Stats.TotalPlayerScore,
                        ChampLevel                  = p.Stats.ChampLevel,
                        Deaths                      = p.Stats.Deaths,
                        TotalScoreRank              = p.Stats.TotalScoreRank,
                        WardsPlaced                 = p.Stats.WardsPlaced,
                        TotalDamageDealt            = p.Stats.TotalDamageDealt,
                        LargestKillingSpree         = p.Stats.LargestKillingSpree,
                        TotalDamageDealtToChampions = p.Stats.TotalDamageDealtToChampions,
                        TotalMinionsKilled          = p.Stats.TotalMinionsKilled,
                        ObjectivePlayerScore        = p.Stats.ObjectivePlayerScore,
                        Kills             = p.Stats.Kills,
                        CombatPlayerScore = p.Stats.CombatPlayerScore,
                        ParticipantID     = p.Stats.ParticipantID,
                        Assists           = p.Stats.Assists,
                        Win            = p.Stats.Win,
                        VisionScore    = p.Stats.VisionScore,
                        FirstBloodKill = p.Stats.FirstBloodKill
                    },
                    TeamID   = p.TeamID,
                    Spell1ID = p.Spell1ID,
                    Spell2ID = p.Spell2ID,
                    HighestAchievedSeasonTier = p.HighestAchievedSeasonTier
                }).ToList()
            };

            context.MatchesDB.Add(match);


            context.SaveChanges();
            return(match);
        }
Exemple #9
0
        public IActionResult Profile(FindModel fm)
        {
            // TODO: Add option to select region
            // Currently just using NA region, since that's what I am on.

            Champion_Mastery_V4 championMastery = new Champion_Mastery_V4("na1");
            Match_V4            matchv4         = new Match_V4("na1");


            // Get summoner info
            Summoner summoner = _context.Summoners.Where(s => s.Name == fm.Name).SingleOrDefault();

            if (summoner == null)
            {
                Summoner_V4 summonerv4 = new Summoner_V4("na1");
                summoner        = summonerv4.GetSummonerByName(fm.Name);
                summoner.Region = fm.Region;
                _context.Summoners.Add(summoner);
                _context.SaveChanges();
                summoner = _context.Summoners.Where(s => s.Name == fm.Name).SingleOrDefault();
            }
            // Get list of masteries by summoner id
            List <ChampionMastery> masteries = championMastery.GetChampionMasteryById(summoner.Id);
            // List will be top 3 champs by mastery
            ChampionInfo list = new ChampionInfo();

            // Get top 3 champs by mastery
            for (int i = 0; i < 3; i++)
            {
                foreach (KeyValuePair <string, Champion> champ in _allChamps.Data)
                {
                    if (champ.Value.Key == masteries[i].ChampionID.ToString())
                    {
                        champ.Value.Rank = i;
                        list.Champions.Add(champ.Key, champ.Value);
                        break;
                    }
                }
            }
            // Get matchlist by account id
            MatchesResponse matches = _context.MatchesResponses.Where(r => r.SummonerID == summoner.Id).FirstOrDefault();

            if (matches == null)
            {
                int k, d, a;
                k                  = d = a = 0;
                matches            = matchv4.GetMatchesByAccountID(summoner.AccountId);
                matches.SummonerID = summoner.Id;
                foreach (Matches match in matches.Matches)
                {
                    MatchDB matchDB = _context.MatchesDB.Where(m => m.GameID == long.Parse(match.GameID)).FirstOrDefault();
                    if (matchDB == null)
                    {
                        MatchDTO matchDTO = matchv4.GetMatchByMatchID(match.GameID);
                        matchDB = matchDTO.ConvertMatchDTOToDBv2(_context);
                    }
                    else
                    {
                        matchDB.PlayerInfos = _context.PlayerInfoDBs.Where(p => p.GameID == matchDB.GameID).OrderBy(p => p.ParticipantID).ToList();
                        matchDB.Teams       = _context.TeamStatsDBs.Where(t => t.GameID == matchDB.GameID).OrderBy(t => t.TeamID).ToList();
                    }

                    match.MatchDB = matchDB;
                    foreach (PlayerInfoDB p in matchDB.PlayerInfos)
                    {
                        if (p.SummonerID == summoner.Id)
                        {
                            k += p.Kills;
                            d += p.Deaths;
                            a += p.Assists;
                        }
                    }
                }
                summoner.Kills   = k;
                summoner.Deaths  = d;
                summoner.Assists = a;
                summoner.KDA     = ((k + a) / (float)d);
                _context.Summoners.Update(summoner);
                _context.MatchesResponses.Add(matches);
                _context.SaveChanges();
            }
            else
            {
                matches.Matches = _context.Matches.Where(m => m.MatchesResponseID == matches.MatchesResponseID).OrderByDescending(m => m.Timestamp).ToList();
                foreach (Matches match in matches.Matches)
                {
                    MatchDB matchDB = _context.MatchesDB.Where(m => m.GameID == long.Parse(match.GameID)).FirstOrDefault();
                    matchDB.Teams       = _context.TeamStatsDBs.Where(t => t.GameID == matchDB.GameID).OrderBy(t => t.TeamID).ToList();
                    matchDB.PlayerInfos = _context.PlayerInfoDBs.Where(p => p.GameID == matchDB.GameID).OrderBy(p => p.ParticipantID).ToList();

                    match.MatchDB = matchDB;
                }
            }

            Dictionary <int, string> championIDs = new Dictionary <int, string>();

            foreach (Champion c in _allChamps.Data.Values)
            {
                championIDs.Add(int.Parse(c.Key), c.Id);
            }
            ViewModelProfile viewModel = new ViewModelProfile {
                Summoner    = summoner,
                Masteries   = masteries,
                ChampionIDs = championIDs,
                Info        = list,
                Matchlist   = matches
            };

            HttpContext.Session.SetInt32("matchIndex", matches.Matches.Count);
            HttpContext.Session.SetSummoner(summoner);
            return(View(viewModel));
        }