private void UpdateTeam(IState state) { using (var context = new Cm93Context()) { var stateRow = context.States.Single(s => s.StateGuid == state.Key.ToString()); stateRow.LastSaved = DateTime.Now; stateRow.Week = Configuration.GlobalWeek(); stateRow.Season = Configuration.Season; var playerTeam = ((ITeamModule)state.Modules[ModuleType.Team]).Teams[Configuration.PlayerTeamName]; foreach (var player in playerTeam.Players) { var playerRow = context.Players.Single(p => p.StateId == stateRow.StateId && p.PlayerStatId == player.Id); playerRow.LocationX = (float)player.Location.X; playerRow.LocationY = (float)player.Location.Y; playerRow.Number = player.Number; playerRow.Formation = player.Formation; } context.SaveChangesAsync(); } }
private void UpdateBalances(IState state) { using (var context = new Cm93Context()) { var stateRow = context.States.Single(s => s.StateGuid == state.Key.ToString()); var teams = ((ITeamModule)state.Modules[ModuleType.Team]).Teams; foreach (var teamKeyValue in teams) { var teamId = context.Teams.Single(t => t.TeamName == teamKeyValue.Key).TeamId; var teamBalance = context.TeamStates.SingleOrDefault(tb => tb.StateId == stateRow.StateId && tb.TeamId == teamId); if (teamBalance == null) { context.TeamStates.Add( new TeamStateRow { Balance = teamKeyValue.Value.Balance, StateId = stateRow.StateId, TeamId = teamId }); } else { teamBalance.Balance = (long)teamKeyValue.Value.Balance; } } context.SaveChangesAsync(); } }
private void UpdateCompetitions(IState state) { using (var context = new Cm93Context()) { var stateRow = context.States.Single(s => s.StateGuid == state.Key.ToString()); stateRow.LastSaved = DateTime.Now; stateRow.Week = Configuration.GlobalWeek(); stateRow.Season = Configuration.Season; context.SaveChangesAsync(); } }
private void UpdateFixtures(IState state) { using (var context = new Cm93Context()) { var stateRow = context.States.Single(s => s.StateGuid == state.Key.ToString()); stateRow.LastSaved = DateTime.Now; stateRow.Week = Configuration.GlobalWeek(); stateRow.Season = Configuration.Season; var fixtures = ((IFixturesModule)state.Modules[ModuleType.Fixtures]).Fixtures; foreach (var fixture in fixtures.Where(f => f.Week == stateRow.Week)) { context.Fixtures.Add( new FixtureRow { Week = stateRow.Week, StateId = stateRow.StateId, HomeTeamId = context.Teams.Single(t => t.TeamName == fixture.TeamHome.TeamName).TeamId, AwayTeamId = context.Teams.Single(t => t.TeamName == fixture.TeamAway.TeamName).TeamId, HomeGoals = fixture.GoalsHome, AwayGoals = fixture.GoalsAway, CompetitionId = context.Competitions.Single(c => c.CompetitionName == fixture.CompetitionName).CompetitionId } ); } // Intensive operations so only update when matches have been played var players = ((IPlayersModule)state.Modules[ModuleType.Players]).Players; foreach (var player in players) { var playerRow = context.Players.Single(p => p.StateId == stateRow.StateId && p.PlayerStatId == player.Id); playerRow.Goals = player.Goals; playerRow.TeamId = context.Teams.Single(t => t.TeamName == player.TeamName).TeamId; } context.SaveChangesAsync(); } }
private void UpdatePlayers(IState state) { using (var context = new Cm93Context()) { var stateRow = context.States.Single(s => s.StateGuid == state.Key.ToString()); stateRow.LastSaved = DateTime.Now; stateRow.Week = Configuration.GlobalWeek(); stateRow.Season = Configuration.Season; var players = ((IPlayersModule)state.Modules[ModuleType.Players]).Players; foreach (var player in players.Where(p => p.TeamName == Configuration.PlayerTeamName)) { var playerRow = context.Players.Single(p => p.StateId == stateRow.StateId && p.PlayerStatId == player.Id); playerRow.ReleaseValue = player.ReleaseValue; playerRow.Goals = player.Goals; } context.SaveChangesAsync(); } }
private void UpdateMatch(IState state) { using (var context = new Cm93Context()) { var stateRow = context.States.Single(s => s.StateGuid == state.Key.ToString()); stateRow.LastSaved = DateTime.Now; stateRow.Week = Configuration.GlobalWeek(); stateRow.Season = Configuration.Season; var competitions = ((IMatchModule)state.Modules[ModuleType.Match]).Competitions; foreach (var competition in competitions.OfType <Division>()) { var competitionId = context.Competitions.Single(c => c.CompetitionName == competition.CompetitionName).CompetitionId; foreach (var place in competition.Places) { var teamId = context.Teams.Single(t => t.TeamName == place.Value.Team.TeamName).TeamId; var divisionRow = context.Divisions. Single(d => d.StateId == stateRow.StateId && d.CompetitionId == competitionId && d.TeamId == teamId); divisionRow.Draws = place.Value.Draws; divisionRow.GoalDifference = place.Value.GoalDifference; divisionRow.GoalsAgainst = place.Value.Against; divisionRow.GoalsFor = place.Value.For; divisionRow.Losses = place.Value.Losses; divisionRow.Points = place.Value.Points; divisionRow.Wins = place.Value.Wins; } } context.SaveChangesAsync(); } }
private void UpdateSelectedTeam(IState state) { using (var context = new Cm93Context()) { var stateRow = new StateRow { LastSaved = DateTime.Now, Name = state.Name, Created = state.Created, StateGuid = state.Key.ToString(), Season = Configuration.Season, TeamId = context.Teams. Single(t => t.TeamName == Configuration.PlayerTeamName). TeamId }; context.States.Add(stateRow); var players = ((IPlayersModule)state.Modules[ModuleType.Players]).Players; context.Players.AddRange(players. Select(p => new PlayerRow { Goals = 0, LocationX = (float)p.Location.X, LocationY = (float)p.Location.Y, Number = p.Number, NumericValue = p.NumericValue, PlayerStatId = p.Id, ReleaseValue = p.ReleaseValue, StateId = stateRow.StateId, TeamId = context.Teams.Single(t => t.TeamName == p.TeamName).TeamId, Formation = p.Formation } ) ); var competitions = ((IMatchModule)state.Modules[ModuleType.Match]).Competitions; foreach (var competition in competitions.OfType <Division>()) { context.Divisions.AddRange(competition.Places. Select(p => new DivisionRow { StateId = stateRow.StateId, CompetitionId = context.Competitions.Single(c => c.CompetitionName == competition.CompetitionName).CompetitionId, TeamId = context.Teams.Single(t => t.TeamName == p.Key.TeamName).TeamId, Draws = p.Value.Draws, GoalDifference = p.Value.GoalDifference, GoalsAgainst = p.Value.Against, GoalsFor = p.Value.For, Losses = p.Value.Losses, Points = p.Value.Points, Wins = p.Value.Wins })); } context.SaveChangesAsync(); } }