public void AddUpdateGameInningTest() { Guid seedGameId = SeedGame(); GameInningDto dto = new GameInningDto() { GameId = seedGameId, InningNumber = TEST_INNING_NUMBER }; var addResult = GameInning.AddNew(dto); Assert.IsTrue(addResult.IsSuccess); var item = GameInning.GetGameInning(seedGameId, TEST_INNING_NUMBER); Assert.IsNotNull(item); Assert.AreEqual(seedGameId, item.GameId); Assert.AreEqual(TEST_INNING_NUMBER, item.InningNumber); dto.InningNumber = 4; addResult = GameInning.AddNew(dto); Assert.IsTrue(addResult.IsSuccess); item = GameInning.GetGameInning(seedGameId, inningNumber: 4); dto.GameInningId = item.GameInningId; dto.DeleteDate = DateTime.UtcNow; var updateResult = GameInning.Update(dto); Assert.IsTrue(updateResult.IsSuccess); item = GameInning.GetGameInning(seedGameId, inningNumber: 4); Assert.IsNotNull(item); Assert.IsNotNull(item.DeleteDate); dto.DeleteDate = null; updateResult = GameInning.Update(dto); Assert.IsTrue(updateResult.IsSuccess); item = GameInning.GetGameInning(seedGameId, inningNumber: 4); Assert.IsNotNull(item); Assert.IsNull(item.DeleteDate); var items = GameInning.GetGameInnings(seedGameId); Assert.IsTrue(items.Count >= 1); foreach (var i in items) { var removeResult = GameInning.Remove(i.GameId, i.InningNumber); Assert.IsTrue(removeResult.IsSuccess); } items = GameInning.GetGameInnings(seedGameId); Assert.IsTrue(items.Count == 0); DeleteSeededGame(seedGameId); }
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 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); }