Пример #1
0
    public ImportStat ImportGameTeams()
    {
      string table = "GameTeams";
      var iStat = new ImportStat(_logger, table);

            if (_seed && _context.GameTeams.Count() == 0)
            {
                _logger.Write("Importing " + table);

                dynamic parsedJson = _jsonFileService.ParseObjectFromJsonFile(_folderPath + "Games.json");
                int count = parsedJson.Count;

                _logger.Write("ImportGameTeams: Access records to process:" + count);

                int countSaveOrUpdated = 0;
                for (var d = 0; d < parsedJson.Count; d++)
                {
                    if (d % 100 == 0) { _logger.Write("ImportGameTeams: Access records processed:" + d); }
                    var json = parsedJson[d];

                    int gameId = json["GAME_ID"];
                    int seasonId = json["SEASON_ID"];

                    int homeTeamId, awayTeamId;


                    homeTeamId = json["HOME_TEAM_ID"];
                    awayTeamId = json["AWAY_TEAM_ID"];


                    // FK check
                    //_lo30ContextService.FindGame(gameId, errorIfNotFound: true, errorIfMoreThanOneFound: true, populateFully: false);
                    //_lo30ContextService.FindTeam(homeTeamId, errorIfNotFound: true, errorIfMoreThanOneFound: true, populateFully: false);
                    //_lo30ContextService.FindTeam(awayTeamId, errorIfNotFound: true, errorIfMoreThanOneFound: true, populateFully: false);

                    var gameTeam = new GameTeam(sid: seasonId, gid: gameId, ht: true, tid: homeTeamId, otid: awayTeamId);
                    countSaveOrUpdated = countSaveOrUpdated + _lo30ContextService.SaveOrUpdateGameTeam(gameTeam);

                    gameTeam = new GameTeam(sid: seasonId, gid: gameId, ht: false, tid: awayTeamId, otid: homeTeamId);

                    countSaveOrUpdated = countSaveOrUpdated + _lo30ContextService.SaveOrUpdateGameTeam(gameTeam);
                }

                iStat.Imported();
                ContextSaveChanges();
                iStat.Saved(_context.GameTeams.Count());
            }
            else
            {
                _logger.Write(table + " records exist in context; not importing");
                iStat.Imported();
                iStat.Saved(0);
            }

            iStat.Log();

            return iStat;
        }
Пример #2
0
    public GameTeam GetGameTeamByGameIdAndHomeTeam(int gameId, bool homeTeam)
    {
      var results = new GameTeam();

      using (var context = new LO30Context())
      {
        results = context.GameTeams
                          .Where(x => x.GameId == gameId && x.HomeTeam == homeTeam)
                          .IncludeAll()
                          .FirstOrDefault();
      }
      return results;
    }
Пример #3
0
    public GameTeam GetGameTeamByGameAndTeamId(int gameId, int teamId)
    {
      var results = new GameTeam();

      using (var context = new LO30Context())
      {
        results = context.GameTeams
                          .Where(x=>x.GameId == gameId && x.TeamId == teamId)
                          .IncludeAll()
                          .FirstOrDefault();
      }
      return results;
    }