Example #1
0
        public async Task GetPlayerById(string id)
        {
            Player = await PubgDB.Players
                     .Where(p => p.Id == id)
                     .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(id);

                if (onlinePlayer != null)
                {
                    Player = new Player()
                    {
                        Name = onlinePlayer.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();
        }