/// <summary> /// adds all the jam passes /// </summary> /// <param name="jam"></param> /// <param name="db"></param> /// <param name="g"></param> /// <param name="jamNew"></param> /// <returns></returns> private static int AddJamPasses(JamViewModel jam, ManagementContext db, DataModels.Game.Game g, GameJam jamNew) { int c = 0; try { foreach (var pass in jam.JamPasses) { try { GameJamPasses p = new GameJamPasses(); p.GameJam = jamNew; p.GamePassId = pass.PassId; p.JamTimeMilliseconds = pass.JamTimeMilliseconds; p.PassNumber = pass.PassNumber; p.PointsScoredForPass = pass.PointsScoredForPass; p.SkaterWhoPassed = GameMemberClass.getMemberOfTeamInGame(pass.SkaterWhoPassed.SkaterId, g); p.TeamNumberEnum = (byte)pass.Team; if (p.SkaterWhoPassed != null) jamNew.JamPasses.Add(p); //moved to down below because this was throwing an error... //Collection was modified; enumeration operation may not execute. //testing it out.. See if it will throw another. // c += db.SaveChanges(); } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } } c += db.SaveChanges(); } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } return c; }
public static int insertNewJamIntoDb(Guid gameId, Guid team1Id, Guid team2Id, JamViewModel jam, ManagementContext db, DataModels.Game.Game g) { int c = 0; GameJam jamNew = new GameJam(); if (jam.Blocker1T1 != null) { var m = GameMemberClass.getMemberOfTeamInGame(team1Id, jam.Blocker1T1.SkaterId, g); if (m != null) jamNew.Blocker1Team1 = m; } if (jam.Blocker1T2 != null) { var m = GameMemberClass.getMemberOfTeamInGame(team2Id, jam.Blocker1T2.SkaterId, g); if (m != null) jamNew.Blocker1Team2 = m; } if (jam.Blocker2T1 != null) { var m = GameMemberClass.getMemberOfTeamInGame(team1Id, jam.Blocker2T1.SkaterId, g); if (m != null) jamNew.Blocker2Team1 = m; } if (jam.Blocker2T2 != null) { var m = GameMemberClass.getMemberOfTeamInGame(team2Id, jam.Blocker2T2.SkaterId, g); if (m != null) jamNew.Blocker2Team2 = m; } if (jam.Blocker3T1 != null) { var m = GameMemberClass.getMemberOfTeamInGame(team1Id, jam.Blocker3T1.SkaterId, g); if (m != null) jamNew.Blocker3Team1 = m; } if (jam.Blocker3T2 != null) { var m = GameMemberClass.getMemberOfTeamInGame(team2Id, jam.Blocker3T2.SkaterId, g); if (m != null) jamNew.Blocker3Team2 = m; } if (jam.Blocker4T1 != null) { var m = GameMemberClass.getMemberOfTeamInGame(team1Id, jam.Blocker4T1.SkaterId, g); if (m != null) jamNew.Blocker4Team1 = m; } if (jam.Blocker4T2 != null) { var m = GameMemberClass.getMemberOfTeamInGame(team2Id, jam.Blocker4T2.SkaterId, g); if (m != null) jamNew.Blocker4Team2 = m; } if (jam.PivotT1 != null) { var m = GameMemberClass.getMemberOfTeamInGame(team1Id, jam.PivotT1.SkaterId, g); if (m != null) jamNew.PivotTeam1 = m; } if (jam.PivotT2 != null) { var m = GameMemberClass.getMemberOfTeamInGame(team2Id, jam.PivotT2.SkaterId, g); if (m != null) jamNew.PivotTeam2 = m; } if (jam.JammerT1 != null) { var m = GameMemberClass.getMemberOfTeamInGame(team1Id, jam.JammerT1.SkaterId, g); if (m != null) { jamNew.JammerTeam1 = m; jamNew.DidTeam1JammerLoseLeadEligibility = jam.JammerT1.LostLeadJammerEligibility; } } if (jam.JammerT2 != null) { var m = GameMemberClass.getMemberOfTeamInGame(team2Id, jam.JammerT2.SkaterId, g); if (m != null) { jamNew.JammerTeam2 = m; jamNew.DidTeam2JammerLoseLeadEligibility = jam.JammerT2.LostLeadJammerEligibility; } } jamNew.JamId = jam.JamId; jamNew.CurrentPeriod = jam.CurrentPeriod; jamNew.Created = DateTime.UtcNow; jamNew.GameTimeElapsedMillisecondsStart = jam.GameTimeElapsedMillisecondsStart; jamNew.GameTimeElapsedMillisecondsEnd = jam.GameTimeElapsedMillisecondsEnd; jamNew.JamNumber = jam.JamNumber; jamNew.TeamLeadingJam = (byte)jam.TeamLeadingJam; jamNew.TotalPointsForJamT1 = jam.TotalPointsForJamT1; jamNew.TotalPointsForJamT2 = jam.TotalPointsForJamT2; jamNew.DidJamEndWithInjury = jam.DidJamEndWithInjury; jamNew.DidJamGetCalledByJammerT1 = jam.DidJamGetCalledByJammerT1; jamNew.DidJamGetCalledByJammerT2 = jam.DidJamGetCalledByJammerT2; g.GameJams.Add(jamNew); c += db.SaveChanges(); foreach (var leadJammer in jam.LeadJammers) { try { GameLeadJammer lead = new GameLeadJammer(); lead.Created = DateTime.UtcNow; lead.GameMemberId = leadJammer.Jammer.SkaterId; lead.GameTimeInMilliseconds = leadJammer.GameTimeInMilliseconds; lead.GameJam = jamNew; lead.JamTimeInMilliseconds = lead.JamTimeInMilliseconds; jamNew.LeadJammers.Add(lead); } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } } db.SaveChanges(); if (jam.JamClock != null && jam.JamClock.StartTime != new DateTime()) { try { GameStopwatch stop = new GameStopwatch(); stop.Game = g; stop.Created = DateTime.UtcNow; stop.IsClockAtZero = jam.JamClock.IsClockAtZero == true ? 1 : 0; ; stop.IsRunning = jam.JamClock.IsRunning == true ? 1 : 0; stop.Length = jam.JamClock.TimerLength; stop.JamNumber = jam.JamNumber; stop.JamId = jam.JamId; stop.StartDateTime = jam.JamClock.StartTime; stop.StopwatchForId = gameId; stop.TimeElapsed = jam.JamClock.TimeElapsed; stop.TimeRemaining = jam.JamClock.TimeRemaining; stop.Type = (int)StopWatchTypeEnum.JamClock; db.GameStopWatch.Add(stop); } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } } g.GameJams.Add(jamNew); c += db.SaveChanges(); AddJamPasses(jam, db, g, jamNew); return c; }