Exemplo n.º 1
0
        public async Task GetMatches(PubgPlayer player = null)
        {
            if (Player.Matches == null)
            {
                Player.Matches = new List <PlayerMatch>();
            }

            if (Player.LastMatchUpdate == null || Player.LastMatchUpdate < DateTime.Now.AddMinutes(-Config.PlayerRefreshTime))
            {
                if (player == null)
                {
                    player = await PubgHelper.GetPubgPlayer(Player.Id);
                }

                foreach (var matchId in player.MatchIds.Take(Config.NumberOfRecentMatches))
                {
                    Match matchFound = null;

                    matchFound = await PubgDB.Matches.Where(m => m.Id == matchId).FirstOrDefaultAsync();

                    if (matchFound == null)
                    {
                        matchFound = await PubgHelper.GetPubgMatch(matchId);
                    }

                    if (!Player.Matches.Any(m => m.MatchId == matchFound.Id))
                    {
                        Player.Matches.Add(new PlayerMatch()
                        {
                            Player = Player, Match = matchFound
                        });
                        await PubgHelper.SavePubgMatch(matchFound);

                        PubgDB.Attach(matchFound);
                    }
                }
                Player.LastMatchUpdate = DateTime.Now;
            }
        }
Exemplo n.º 2
0
        public async Task GetPlayerByName(string name)
        {
            Player = await PubgDB.Players
                     .Where(p => p.Name == name)
                     .Include(p => p.DuoStats)
                     .Include(p => p.SoloStats)
                     .Include(p => p.SquadStats)
                     .Include(p => p.Matches)
                     .FirstOrDefaultAsync();


            if (Player == null)
            {
                var onlinePlayer = await PubgHelper.GetPubgPlayer(name : name);

                if (onlinePlayer != null)
                {
                    Player = new Player()
                    {
                        Name = name, Id = onlinePlayer.Id
                    };
                    await GetPlayerStats();
                    await GetMatches(onlinePlayer);

                    PubgDB.Players.Add(Player);
                }
            }
            else
            {
                await GetPlayerStats();
                await GetMatches();

                PubgDB.Players.Update(Player);
            }
            await PubgDB.SaveChangesAsync();
        }