protected override async Task ProcessAsync(EmptyArgs args, Result result) { var countries = (await GetAsync("component_data/2/3-0-0-0-0-0-0")) .OutStats .Countries .Select(c => { c.XCountryId = c.XCountryId; c.Id = BaseDto.CalculateHash(c.XCountryId); return(c); }) .ToList(); if (countries.Count > 0) { _db.CountriesRepository.AddOrUpdate_Countries( countries, out var countriesInserted, out var countriesUpdated); result.CountriesInserted = countriesInserted; result.CountriesUpdated = countriesUpdated; } var leagues = countries .SelectMany(c => c.Leagues.Select(l => { l.XCountryId = c.XCountryId; l.XLeagueId = l.XLeagueId; l.ParentId = BaseDto.CalculateHash(l.XCountryId); l.Id = BaseDto.CalculateHash(l.XCountryId, l.XLeagueId); return(l); })) .ToList(); if (leagues.Count > 0) { _db.LeaguesRepository.AddOrUpdate_Leagues( leagues, out var leaguesInserted, out var leaguesUpdated); result.LeaguesInserted = leaguesInserted; result.LeaguesUpdated = leaguesUpdated; } }
protected override async Task ProcessAsync(CountryIdLeagueIdArgs args, Result result) { var seasonsUri = $"component_data/3/3-{args.XLeagueId}-0-0-0-0-0"; var seasons = (await GetAsync(seasonsUri)).OutStats.Seasons.Select(s => { s.XCountryId = args.XCountryId; s.XLeagueId = args.XLeagueId; s.XSeasonId = s.XSeasonId; s.ParentId = BaseDto.CalculateHash(s.XCountryId, s.XLeagueId); s.Id = BaseDto.CalculateHash(s.XCountryId, s.XLeagueId, s.XSeasonId); return(s); }).ToList(); if (seasons.Count > 0) { _db.SeasonsRepository.AddOrUpdate_Seasons(seasons, out var seasonsInserted, out var seasonsUpdated); result.SeasonsInserted = seasonsInserted; result.SeasonsUpdated = seasonsUpdated; } }
protected override async Task ProcessAsync(LeagueIdSeasonIdArgs args, Result result) { var stagesTeamsUri = $"component_data/3/3-{args.XLeagueId}-{args.XSeasonId}-0-0-0-0"; var outStats = (await GetAsync(stagesTeamsUri)).OutStats; var stages = outStats.Stages.Select(s => { s.XLeagueId = args.XLeagueId; s.XSeasonId = args.XSeasonId; s.ParentId = BaseDto.CalculateHash(s.XCountryId, s.XLeagueId, s.XSeasonId); s.Id = BaseDto.CalculateHash(s.XCountryId, s.XLeagueId, s.XSeasonId, s.XStageId); return(s); }).ToList(); if (stages.Count > 0) { var stm = stages.Select(x => (StageDto)x).ToList(); _db.StagesRepository.AddOrUpdate_Stages(stm, out var stagesInserted, out var stagesUpdated); result.StagesInserted = stagesInserted; result.StagesUpdated = stagesUpdated; } #region Teams var a = stages.Where(s => s.A != null && s.A.C.Count > 0) .SelectMany(s => s.A.C) .Where(x => x?.R != null && x.R.Count > 0) .SelectMany(x => x.R) .Where(x => x.T != null) .Select(x => x.T); var d = stages.Where(s => s.D != null && s.D.C.Count > 0) .SelectMany(s => s.D.C) .Where(x => x != null && x.A != null && x.H != null) .SelectMany(x => new[] { x.A, x.H }); var teams = a.Union(d) .GroupBy(g => g.XTeamId) .Select(g => g.First()) .Select(x => { x.Id = BaseDto.CalculateHash(x.XTeamId); return(x); }) .ToList(); if (teams.Count > 0) { _db.TeamsRepository.AddOrUpdate_Teams(teams, out var teamsInserted, out var teamsUpdated); result.TeamsInserted = teamsInserted; result.TeamsUpdated = teamsUpdated; } #endregion //#region countries // // var countries = dto.Teams.Select(x => x.CountryId).Distinct().Select(x => new CountryDto(x)) // .ToList(); // // if (countries.Count > 0) // { // _db.CountryRepository.AddIfNotExists_Countries(countries, out var countriesInserted); // result.CountriesInserted = countriesInserted; // } // //#endregion // //#region stages // // var stages = dto.Stages; // // if (stages.Count > 0) // { // _db.StageRepository.AddOrUpdate_Stages(stages, out var stagesInserted, out var stagesUpdated); // result.StagesInserted = stagesInserted; // result.StagesUpdated = stagesUpdated; // } // //#endregion // // //#region Games // // var games = dto.Games; // // if (games.Count > 0) // { // _db.GameRepository.AddOrUpdate_Games(games, out var gamesInserted, out var gamesUpdated); // result.GamesInserted = gamesInserted; // result.GamesUpdated = gamesUpdated; // } // //#endregion }