void GetMatches(PubgPlayer player) { var list = new List <PlayerMatch>(); using (var con = new PubgDbContext()) { foreach (var matchId in player.MatchIds) { var matchFound = con.Matches.Find(matchId); if (matchFound == null) { matchFound = PubgHelper.GetPubgMatch(matchId); } else { con.Matches.Attach(matchFound); } list.Add(new PlayerMatch() { Player = this, Match = matchFound }); } Matches = list; } }
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; } }