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; } }