public void SaveEventType(EventType eventType) { if (CurrentGameInning != null && CurrentGameInningTeam != null && CurrentGameInningTeamBatter != null) { //update the event for the current batter var currentBatter = GameInningTeamBatter.GetCurrentGameInningTeamBatter(GameId); if (currentBatter != null) { GameInningTeamBatterDto gameInningTeamBatter = new GameInningTeamBatterDto() { GameInningTeamBatterId = currentBatter.GameInningTeamBatterId, GameInningTeamId = currentBatter.GameInningTeamId, EventType = (int)eventType, PlayerId = currentBatter.PlayerId, Sequence = currentBatter.Sequence, RBIs = currentBatter.RBIs }; GameInningTeamBatter.Update(gameInningTeamBatter); //update outs, runs, and baserunners var halfInningActions = HalfInning.GetHalfInningActions(CurrentGameInningTeam.GameInningTeamId); Outs = halfInningActions.TotalOuts; Runs = halfInningActions.TotalRuns; IsRunnerOnFirst = halfInningActions.IsRunnerOnFirst; IsRunnerOnSecond = halfInningActions.IsRunnerOnSecond; IsRunnerOnThird = halfInningActions.IsRunnerOnThird; AdvanceToNextHalfInning = halfInningActions.AdvanceToNextHalfInning; //update total runs var currentInningTeam = GameInningTeam.GetCurrentGameInningTeam(GameId); if (currentInningTeam != null) { GameInningTeamDto gameInningTeam = new GameInningTeamDto() { GameTeamId = currentInningTeam.GameTeamId, GameInningTeamId = currentInningTeam.GameInningTeamId, GameInningId = currentInningTeam.GameInningId, IsRunnerOnFirst = IsRunnerOnFirst, IsRunnerOnSecond = IsRunnerOnSecond, IsRunnerOnThird = IsRunnerOnThird, Outs = Outs, Score = Runs }; GameInningTeam.Update(gameInningTeam); } } AdvanceToNextInningTeamBatter(); } }
public void AddUpdateGameInningTeamBatterTest() { Guid seedGameInningTeamId = SeedGameInningTeam(); Guid seedPlayerId = SeedPlayer(); GameInningTeamBatterDto dto = new GameInningTeamBatterDto() { GameInningTeamId = seedGameInningTeamId, PlayerId = seedPlayerId, Sequence = TEST_SEQUENCE, EventType = TEST_EVENT_TYPE, TargetEventType = TEST_TARGET_EVENT_TYPE, RBIs = TEST_RBIS }; var addResult = Service.AddNew(dto); Assert.IsTrue(addResult.IsSuccess); var item = Service.GetGameInningTeamBatter(seedGameInningTeamId, TEST_SEQUENCE); Assert.IsNotNull(item); Assert.AreEqual(item.GameInningTeamId, seedGameInningTeamId); Assert.AreEqual(item.PlayerId, seedPlayerId); Assert.AreEqual(item.Sequence, TEST_SEQUENCE); Assert.AreEqual(item.RBIs, TEST_RBIS); Assert.AreEqual(item.EventType, TEST_EVENT_TYPE); Assert.AreEqual(item.TargetEventType, TEST_TARGET_EVENT_TYPE); dto.GameInningTeamBatterId = item.GameInningTeamBatterId; dto.RBIs = TEST_RBIS_2; dto.EventType = TEST_EVENT_TYPE_2; dto.TargetEventType = TEST_TARGET_EVENT_TYPE_2; var updateResult = Service.Update(dto); Assert.IsTrue(updateResult.IsSuccess); var inningAtBats = Service.GetGameInningTeamBatters(seedGameInningTeamId); Assert.IsTrue(inningAtBats.Count > 0); item = inningAtBats.FirstOrDefault(x => x.Sequence == TEST_SEQUENCE); Assert.IsNotNull(item); Assert.AreEqual(item.GameInningTeamId, seedGameInningTeamId); Assert.AreEqual(item.PlayerId, seedPlayerId); Assert.AreEqual(item.Sequence, TEST_SEQUENCE); Assert.AreEqual(item.RBIs, TEST_RBIS_2); Assert.AreEqual(item.EventType, TEST_EVENT_TYPE_2); Assert.AreEqual(item.TargetEventType, TEST_TARGET_EVENT_TYPE_2); var removeResult = Service.Remove(seedGameInningTeamId, TEST_SEQUENCE); Assert.IsTrue(removeResult.IsSuccess); item = Service.GetGameInningTeamBatter(seedGameInningTeamId, TEST_SEQUENCE); Assert.IsNull(item); DeleteSeededGameInningTeam(seedGameInningTeamId); DeleteSeededPlayer(seedPlayerId); }