public void DeleteSeededGame(Guid gameId) { var game = Game.GetGame(gameId); Guid leagueId = game.LeagueId; foreach (var gi in GameInning.GetGameInnings(gameId)) { foreach (var git in GameInningTeam.GetInningTeams(gi.GameInningId)) { foreach (var gitb in GameInningTeamBatter.GetGameInningTeamBatters(git.GameInningTeamId)) { GameInningTeamBatter.Remove(gitb.GameInningTeamId, gitb.Sequence); } GameInningTeam.Remove(git.GameInningId, git.GameTeamId); } GameInning.Remove(gi.GameId, gi.InningNumber); } foreach (var item in GameTeam.GetGameTeams(gameId)) { GameTeam.Remove(item.GameId, item.TeamId); } Game.Remove(gameId); League.RemoveLeague(leagueId); }
public void AddUpdateGameTeamTest() { Guid seedGameId = SeedGame(); Guid seedTeamId = SeedTeam(); GameTeamDto dto = new GameTeamDto() { GameId = seedGameId, TeamId = seedTeamId }; var addResult = GameTeam.AddNew(dto); Assert.IsTrue(addResult.IsSuccess); var item = GameTeam.GetGameTeam(seedGameId, seedTeamId); Assert.IsNotNull(item); Assert.AreEqual(seedTeamId, item.TeamId); Assert.AreEqual(seedGameId, item.GameId); dto.GameTeamId = item.GameTeamId; dto.DeleteDate = DateTime.UtcNow; var updateResult = GameTeam.Update(dto); Assert.IsTrue(updateResult.IsSuccess); item = GameTeam.GetGameTeam(seedGameId, seedTeamId); Assert.IsNotNull(item); Assert.IsNotNull(item.DeleteDate); dto.DeleteDate = null; updateResult = GameTeam.Update(dto); Assert.IsTrue(updateResult.IsSuccess); var items = GameTeam.GetGameTeams(seedGameId); Assert.IsTrue(items.Count >= 1); item = items.FirstOrDefault(x => x.TeamId == seedTeamId); Assert.IsNotNull(item); var removeResult = GameTeam.Remove(seedGameId, seedTeamId); Assert.IsTrue(removeResult.IsSuccess); item = GameTeam.GetGameTeam(seedGameId, seedTeamId); Assert.IsNull(item); DeleteSeededGame(seedGameId); DeleteSeededTeam(seedTeamId); }
void PreLoadGameData() { CurrentGame = new Models.Game(Game.GetGame(GameId)); GameTeams = GameTeam.GetGameTeams(GameId).Where(y => !y.DeleteDate.HasValue).OrderBy(y => y.TeamBattingSequence).ToList(); //Fill Teams Teams = Team.GetTeams(GameTeams.Select(y => y.TeamId).ToList()); //load all players in this game AllPlayers = new List <IPlayer>(); foreach (var gt in GameTeams) { foreach (var player in TeamPlayerLineup.GetTeamSortedBattingOrderPlayers(gt.TeamId)) { AllPlayers.Add(player); } } }
void FillTeamInformation() { var gameTeams = GameTeam.GetGameTeams(GameId).OrderBy(y => y.TeamBattingSequence).ToList(); if (gameTeams.Count >= 2) { var awayTeam = Team.GetTeam(gameTeams[0].TeamId); if (awayTeam != null) { AwayTeamName = awayTeam.Name; AwayTeamId = awayTeam.TeamId; } var homeTeam = Team.GetTeam(gameTeams[1].TeamId); if (homeTeam != null) { HomeTeamName = homeTeam.Name; HomeTeamId = homeTeam.TeamId; } } }
public IBoxScore GetBoxScore(Guid gameId) { BoxScoreDto boxScore = new BoxScoreDto(); var game = Game.GetGame(gameId); if (game != null && !game.DeleteDate.HasValue) { boxScore.GameDate = game.GameDate; var gameTeams = GameTeam.GetGameTeams(gameId).OrderBy(x => x.TeamBattingSequence).ToList(); var teams = GetTeams(gameTeams); var gameInnings = GameInning.GetGameInnings(gameId).OrderBy(x => x.InningNumber).ToList(); var gameInningTeams = GameInningTeam.GetTeamInningsForEntireGame(gameId); foreach (var team in teams) { boxScore.TeamNames.Add(team.Name); } //always add all 9 innings for a standard game for (int i = 1; i <= 9; i++) { var inning = gameInnings.FirstOrDefault(x => x.InningNumber == i); if (inning != null) { foreach (var gameTeam in gameTeams) { BoxScoreInningDto boxScoreInning = new BoxScoreInningDto() { InningNumber = inning.InningNumber, IsCurrentInning = gameInnings.IndexOf(inning) == (gameInnings.Count - 1) }; var team = teams.FirstOrDefault(x => x.TeamId == gameTeam.TeamId); if (team != null) { foreach (var item in gameInningTeams.Where(x => x.GameInningId == inning.GameInningId && x.GameTeamId == gameTeam.GameTeamId)) { BoxScoreHalfInningDto boxScoreHalfInning = new BoxScoreHalfInningDto() { TeamName = team.Name, Score = item.Score }; boxScoreInning.InningTeams.Add(boxScoreHalfInning); } } boxScore.Innings.Add(boxScoreInning); } } else { BoxScoreInningDto boxScoreInning = new BoxScoreInningDto() { InningNumber = i, IsCurrentInning = false }; foreach (var team in teams) { boxScoreInning.InningTeams.Add(new BoxScoreHalfInningDto() { TeamName = team.Name }); } boxScore.Innings.Add(boxScoreInning); } } //add any potentail extra innings var extraInnings = gameInnings.Where(x => x.InningNumber > 9).ToList(); foreach (var inning in extraInnings) { foreach (var gameTeam in gameTeams) { BoxScoreInningDto boxScoreInning = new BoxScoreInningDto() { InningNumber = inning.InningNumber, IsCurrentInning = extraInnings.IndexOf(inning) == (extraInnings.Count - 1) }; var team = teams.FirstOrDefault(x => x.TeamId == gameTeam.TeamId); if (team != null) { foreach (var item in gameInningTeams.Where(x => x.GameInningId == inning.GameInningId && x.GameTeamId == gameTeam.GameTeamId)) { BoxScoreHalfInningDto boxScoreHalfInning = new BoxScoreHalfInningDto() { TeamName = team.Name, Score = item.Score }; boxScoreInning.InningTeams.Add(boxScoreHalfInning); } } boxScore.Innings.Add(boxScoreInning); } } //add totals BoxScoreInningDto boxScoreTotalsInning = new BoxScoreInningDto() { InningNumber = int.MaxValue, IsCurrentInning = false, IsTotalsInning = true }; foreach (var team in teams) { BoxScoreHalfInningDto boxScoreHalfInning = new BoxScoreHalfInningDto() { TeamName = team.Name, Score = boxScore.Innings.Sum(x => x.InningTeams .Where(y => y.TeamName == team.Name && y.Score.HasValue) .Sum(t => t.Score.Value)) }; boxScoreTotalsInning.InningTeams.Add(boxScoreHalfInning); } boxScore.Innings.Add(boxScoreTotalsInning); } return(boxScore); }