public async Task ProcessFixtures(List <Models.Fixture> fixtures, int season, Competition competition, IDbConnection connection) { _logger.LogInformation($"Processing {fixtures.Count} fixtures for season {season} and competition {competition.Name}"); // 1. Get the distinct home and away teams to insert into db var teams = fixtures.Select(t => t.HomeTeam) .Union(fixtures.Select(t => t.AwayTeam)) .GroupBy(k => k.Id) .Select(g => g.FirstOrDefault()) .Where(t => t != null) .Select(t => new Entities.Team { Id = t.Id, Name = t.Title, ShortName = t.ShortTitle }) .ToList(); // 2. Insert the pre-match info into the db. Any advanced stats will be requested by the orchestration project. var fixtureEntities = fixtures.Select(f => new Entities.Fixture { FixtureId = f.Id, HomeTeam = new Entities.Team { Id = f.HomeTeam.Id }, AwayTeam = new Entities.Team { Id = f.AwayTeam.Id }, Season = season, Competition = competition, IsResult = f.IsResult, DateTime = f.DateTime }).ToList(); await _teamRepository.InsertMultipleAsync(teams, connection); await _fixtureRepository.InsertMultipleAsync(fixtureEntities, connection); _logger.LogInformation($"Successfully processed {fixtures.Count} fixtures for season {season} and competition {competition.Name}"); }