private IEnumerable <Kit> UpdateMatches(Profile profile) { if (DateTime.Now - profile.LastUpdated < TimeSpan.FromDays(1)) { _logger.LogInfo("All matches are already up to date"); return(Enumerable.Empty <Kit>()); } Task <IEnumerable <Match> > matchTask; if (profile.MatchCount == 0) { _logger.LogInfo("Fetching all matches..."); matchTask = _service.ListAllMatches(); } else { _logger.LogInfo($"Fetching new matches since {profile.LastUpdated.ToShortDateString()}"); matchTask = _service.ListNewMatches(profile.LastUpdated); } var matches = matchTask.Result; var kits = matches.Select(m => ModelBuilder.BuildKit(m, DateTime.Now)).ToArray(); profile.AddMatches(kits); profile.LastUpdated = DateTime.Now; _logger.LogInfo($"Done fetching {matches.Count()} matches"); return(kits); }
public async Task <IEnumerable <Match> > ListNewMatches(DateTime startDate) { string dateString = startDate.ToString("yyyyMMdd"); if (TryGetStoredResult("ListNewMatches", out IEnumerable <Match> cached, dateString)) { return(cached); } var result = await _service.ListNewMatches(startDate); StoreResult("ListNewMatches", result, dateString); return(result); }