private static void PopulateLineUpJam(ExcelWorksheet reportSheet, int row, JamViewModel jam)
        {
            try
            {
                //team1
                reportSheet.Cells[row, 1].Value = jam.JamNumber;
                if (jam.PivotT1 == null)
                {
                    reportSheet.Cells[row, 2].Value = "X";
                    if (jam.Blocker4T1 != null)
                        reportSheet.Cells[row, 3].Value = jam.Blocker4T1.SkaterNumber;
                }
                else
                    reportSheet.Cells[row, 3].Value = jam.PivotT1.SkaterNumber;
                if (jam.Blocker1T1 != null)
                    reportSheet.Cells[row, 4].Value = jam.Blocker1T1.SkaterNumber;
                if (jam.Blocker2T1 != null)
                    reportSheet.Cells[row, 5].Value = jam.Blocker2T1.SkaterNumber;
                if (jam.Blocker3T1 != null)
                    reportSheet.Cells[row, 6].Value = jam.Blocker3T1.SkaterNumber;
                if (jam.JammerT1 != null)
                    reportSheet.Cells[row, 7].Value = jam.JammerT1.SkaterNumber;

                reportSheet.Cells[row, 8].Value = jam.TotalPointsForJamT1;
                reportSheet.Cells[row, 10].Value = jam.TotalPointsForJamT1 - jam.TotalPointsForJamT2;

                //team2
                reportSheet.Cells[row, 12].Value = jam.JamNumber;
                if (jam.PivotT2 == null)
                {
                    reportSheet.Cells[row, 13].Value = "X";
                    if (jam.Blocker4T2 != null)
                        reportSheet.Cells[row, 14].Value = jam.Blocker4T2.SkaterNumber;
                }
                else
                    reportSheet.Cells[row, 14].Value = jam.PivotT2.SkaterNumber;

                if (jam.Blocker1T2 != null)
                    reportSheet.Cells[row, 15].Value = jam.Blocker1T2.SkaterNumber;
                if (jam.Blocker2T2 != null)
                    reportSheet.Cells[row, 16].Value = jam.Blocker2T2.SkaterNumber;
                if (jam.Blocker3T2 != null)
                    reportSheet.Cells[row, 17].Value = jam.Blocker3T2.SkaterNumber;
                if (jam.JammerT2 != null)
                    reportSheet.Cells[row, 18].Value = jam.JammerT2.SkaterNumber;

                reportSheet.Cells[row, 19].Value = jam.TotalPointsForJamT2;
                reportSheet.Cells[row, 21].Value = jam.TotalPointsForJamT1 - jam.TotalPointsForJamT2;

            }
            catch (Exception exception)
            {
                ErrorViewModel.Save(exception, exception.GetType());
            }
        }
        private static void PopulateLineUpJam(ExcelWorksheet reportSheet, int row, JamViewModel jam)
        {
            try
            {
                //team1
                if (jam.PivotT1 == null)
                {
                    reportSheet.Cells[row, 2].Value = "X";
                    if (jam.Blocker4T1 != null)
                        reportSheet.Cells[row, 6].Value = jam.Blocker4T1.SkaterNumber;
                }
                else
                    reportSheet.Cells[row, 6].Value = jam.PivotT1.SkaterNumber;
                if (jam.Blocker1T1 != null)
                    reportSheet.Cells[row, 9].Value = jam.Blocker1T1.SkaterNumber;
                if (jam.Blocker2T1 != null)
                    reportSheet.Cells[row, 12].Value = jam.Blocker2T1.SkaterNumber;
                if (jam.Blocker3T1 != null)
                    reportSheet.Cells[row, 15].Value = jam.Blocker3T1.SkaterNumber;
                //team2
                if (jam.PivotT2 == null)
                {
                    reportSheet.Cells[row, 24].Value = "X";
                    if (jam.Blocker4T2 != null)
                        reportSheet.Cells[row, 28].Value = jam.Blocker4T2.SkaterNumber;
                }
                else
                    reportSheet.Cells[row, 28].Value = jam.PivotT2.SkaterNumber;

                if (jam.Blocker1T2 != null)
                    reportSheet.Cells[row, 31].Value = jam.Blocker1T2.SkaterNumber;
                if (jam.Blocker2T2 != null)
                    reportSheet.Cells[row, 34].Value = jam.Blocker2T2.SkaterNumber;
                if (jam.Blocker3T2 != null)
                    reportSheet.Cells[row, 37].Value = jam.Blocker3T2.SkaterNumber;

                string passNumbers = String.Empty;
                string passNumbersSecondRow = String.Empty;
                int allPasses = 10;
                int passCount = jam.JamPasses.Where(x => x.Team == TeamNumberEnum.Team1).Count();
                int p = allPasses - passCount;

                for (int i = 1; i < 11; i++)
                {
                    if (passCount < i)
                        if (i < 6)
                            passNumbers += i + "  ";
                        else
                            passNumbersSecondRow += i + "  ";
                }
                reportSheet.Cells[row, 18].Value = passNumbers;
                reportSheet.Cells[row + 1, 18].Value = passNumbersSecondRow;

                passNumbers = String.Empty;
                passNumbersSecondRow = String.Empty;
                allPasses = 10;
                passCount = jam.JamPasses.Where(x => x.Team == TeamNumberEnum.Team2).Count();
                p = allPasses - passCount;
                for (int i = 1; i < 11; i++)
                {
                    if (passCount < i)
                        if (i < 6)
                            passNumbers += i + "  ";
                        else
                            passNumbersSecondRow += i + "  ";
                }
                reportSheet.Cells[row, 40].Value = passNumbers;
                reportSheet.Cells[row + 1, 40].Value = passNumbersSecondRow;

            }
            catch (Exception exception)
            {
                ErrorViewModel.Save(exception, exception.GetType());
            }
        }
Exemplo n.º 3
0
        public static int updateJamToDb(GameViewModel game, ManagementContext db, JamViewModel jam, DataModels.Game.Game gDb)
        {
            int c = 0;
            try
            {


                var findJam = gDb.GameJams.Where(x => x.JamId == jam.JamId).FirstOrDefault();

                if (findJam == null)
                    GameJamClass.insertNewJamIntoDb(game.GameId, game.Team1.TeamId, game.Team2.TeamId, jam, db, gDb);
                else
                {
                    findJam.Game = findJam.Game;
                    findJam.CurrentPeriod = jam.CurrentPeriod;
                    findJam.DidJamEndWithInjury = jam.DidJamEndWithInjury;
                    findJam.DidJamGetCalledByJammerT1 = jam.DidJamGetCalledByJammerT1;
                    findJam.DidJamGetCalledByJammerT2 = jam.DidJamGetCalledByJammerT2;
                    findJam.TotalPointsForJamT1 = jam.TotalPointsForJamT1;
                    findJam.TotalPointsForJamT2 = jam.TotalPointsForJamT2;
                    findJam.GameTimeElapsedMillisecondsEnd = jam.GameTimeElapsedMillisecondsEnd;
                    findJam.GameTimeElapsedMillisecondsStart = jam.GameTimeElapsedMillisecondsStart;
                    c += db.SaveChanges();
                    try
                    {
                        for (int i = 0; i < jam.LeadJammers.Count; i++)
                        {
                            try
                            {
                                var j = findJam.LeadJammers.Where(x => x.GameJamLeadId == jam.LeadJammers[i].GameLeadJamId).FirstOrDefault();
                                if (j == null)
                                {
                                    GameLeadJammer l = new GameLeadJammer();
                                    l.GameJam = findJam;
                                    l.GameMemberId = jam.LeadJammers[i].Jammer.SkaterId;
                                    l.GameTimeInMilliseconds = jam.LeadJammers[i].GameTimeInMilliseconds;
                                    l.JamTimeInMilliseconds = jam.LeadJammers[i].JamTimeInMilliseconds;
                                    l.GameJamLeadId = jam.LeadJammers[i].GameLeadJamId;
                                    findJam.LeadJammers.Add(l);
                                }
                            }
                            catch (Exception exception)
                            {
                                ErrorDatabaseManager.AddException(exception, exception.GetType());
                            }
                        }
                        c += db.SaveChanges();
                    }
                    catch (Exception exception)
                    {
                        ErrorDatabaseManager.AddException(exception, exception.GetType());
                    }
                    try
                    {
                        for (int i = 0; i < jam.JamPasses.Count; i++)
                        {
                            try
                            {
                                var pass = findJam.JamPasses.Where(x => x.GamePassId == jam.JamPasses[i].PassId).FirstOrDefault();
                                if (pass == null)
                                {
                                    GameJamPasses p = new GameJamPasses();
                                    p.GameJam = findJam;
                                    p.GamePassId = jam.JamPasses[i].PassId;
                                    p.JamTimeMilliseconds = jam.JamPasses[i].JamTimeMilliseconds;
                                    p.PassNumber = jam.JamPasses[i].PassNumber;
                                    p.PointsScoredForPass = jam.JamPasses[i].PointsScoredForPass;
                                    p.SkaterWhoPassed = GameMemberClass.getMemberOfTeamInGame(jam.JamPasses[i].SkaterWhoPassed.SkaterId, gDb);
                                    p.TeamNumberEnum = (byte)jam.JamPasses[i].Team;
                                    findJam.JamPasses.Add(p);
                                }
                                else
                                {
                                    pass.PointsScoredForPass = jam.JamPasses[i].PointsScoredForPass;
                                }
                            }
                            catch (Exception exception)
                            {
                                ErrorDatabaseManager.AddException(exception, exception.GetType());
                            }
                        }
                        c += db.SaveChanges();
                    }
                    catch (Exception exception)
                    {
                        ErrorDatabaseManager.AddException(exception, exception.GetType());
                    }
                    if ((jam.Blocker1T1 != null && findJam.Blocker1Team1 == null) || (jam.Blocker1T1 != null && findJam.Blocker1Team1.GameMemberId != jam.Blocker1T1.SkaterId))
                    {
                        var m = GameMemberClass.getMemberOfTeamInGame(game.Team1.TeamId, jam.Blocker1T1.SkaterId, gDb);
                        if (m != null)
                            findJam.Blocker1Team1 = m;
                    }
                    if ((jam.Blocker1T2 != null && findJam.Blocker1Team2 == null) || (jam.Blocker1T2 != null && findJam.Blocker1Team2.GameMemberId != jam.Blocker1T2.SkaterId))
                    {
                        var m = GameMemberClass.getMemberOfTeamInGame(game.Team2.TeamId, jam.Blocker1T2.SkaterId, gDb);
                        if (m != null)
                            findJam.Blocker1Team2 = m;
                    }
                    if ((jam.Blocker2T1 != null && findJam.Blocker2Team1 == null) || (jam.Blocker2T1 != null && findJam.Blocker2Team1.GameMemberId != jam.Blocker2T1.SkaterId))
                    {
                        var m = GameMemberClass.getMemberOfTeamInGame(game.Team1.TeamId, jam.Blocker2T1.SkaterId, gDb);
                        if (m != null)
                            findJam.Blocker2Team1 = m;
                    }
                    if ((jam.Blocker2T2 != null && findJam.Blocker2Team2 == null) || (jam.Blocker2T2 != null && findJam.Blocker2Team2.GameMemberId != jam.Blocker2T2.SkaterId))
                    {
                        var m = GameMemberClass.getMemberOfTeamInGame(game.Team2.TeamId, jam.Blocker2T2.SkaterId, gDb);
                        if (m != null)
                            findJam.Blocker2Team2 = m;
                    }
                    if ((jam.Blocker3T1 != null && findJam.Blocker3Team1 == null) || (jam.Blocker3T1 != null && findJam.Blocker3Team1.GameMemberId != jam.Blocker3T1.SkaterId))
                    {
                        var m = GameMemberClass.getMemberOfTeamInGame(game.Team1.TeamId, jam.Blocker3T1.SkaterId, gDb);
                        if (m != null)
                            findJam.Blocker3Team1 = m;
                    }
                    if ((jam.Blocker3T2 != null && findJam.Blocker3Team2 == null) || (jam.Blocker3T2 != null && findJam.Blocker3Team2.GameMemberId != jam.Blocker3T2.SkaterId))
                    {
                        var m = GameMemberClass.getMemberOfTeamInGame(game.Team2.TeamId, jam.Blocker3T2.SkaterId, gDb);
                        if (m != null)
                            findJam.Blocker3Team2 = m;
                    }
                    if ((jam.Blocker4T1 != null && findJam.Blocker4Team1 == null) || (jam.Blocker4T1 != null && findJam.Blocker4Team1.GameMemberId != jam.Blocker4T1.SkaterId))
                    {
                        var m = GameMemberClass.getMemberOfTeamInGame(game.Team1.TeamId, jam.Blocker4T1.SkaterId, gDb);
                        if (m != null)
                            findJam.Blocker4Team1 = m;
                    }
                    if ((jam.Blocker4T2 != null && findJam.Blocker4Team2 == null) || (jam.Blocker4T2 != null && findJam.Blocker4Team2.GameMemberId != jam.Blocker4T2.SkaterId))
                    {
                        var m = GameMemberClass.getMemberOfTeamInGame(game.Team2.TeamId, jam.Blocker4T2.SkaterId, gDb);
                        if (m != null)
                            findJam.Blocker4Team2 = m;
                    }
                    if ((jam.PivotT1 != null && findJam.PivotTeam1 == null) || (jam.PivotT1 != null && findJam.PivotTeam1.GameMemberId != jam.PivotT1.SkaterId))
                    {
                        var m = GameMemberClass.getMemberOfTeamInGame(game.Team1.TeamId, jam.PivotT1.SkaterId, gDb);
                        if (m != null)
                            findJam.PivotTeam1 = m;
                    }
                    if ((jam.PivotT2 != null && findJam.PivotTeam2 == null) || (jam.PivotT2 != null && findJam.PivotTeam2.GameMemberId != jam.PivotT2.SkaterId))
                    {
                        var m = GameMemberClass.getMemberOfTeamInGame(game.Team2.TeamId, jam.PivotT2.SkaterId, gDb);
                        if (m != null)
                            findJam.PivotTeam2 = m;
                    }
                    if ((jam.JammerT1 != null && findJam.JammerTeam1 == null) || (jam.JammerT1 != null && findJam.JammerTeam1.GameMemberId != jam.JammerT1.SkaterId))
                    {
                        var m = GameMemberClass.getMemberOfTeamInGame(game.Team1.TeamId, jam.JammerT1.SkaterId, gDb);
                        if (m != null)
                        {
                                                        findJam.JammerTeam1 = m;
                            findJam.DidTeam1JammerLoseLeadEligibility = jam.JammerT1.LostLeadJammerEligibility;
                        }
                    }
                    if ((jam.JammerT2 != null && findJam.JammerTeam2 == null) || (jam.JammerT2 != null && findJam.JammerTeam2.GameMemberId != jam.JammerT2.SkaterId))
                    {
                        var m = GameMemberClass.getMemberOfTeamInGame(game.Team2.TeamId, jam.JammerT2.SkaterId, gDb);
                        if (m != null)
                        {
                            findJam.JammerTeam2 = m;
                            findJam.DidTeam2JammerLoseLeadEligibility = jam.JammerT2.LostLeadJammerEligibility;
                        }
                    }

                    c += db.SaveChanges();
                }
                var findClock = (from xx in db.GameStopWatch
                                 where xx.StopwatchForId == game.GameId
                                 where xx.JamId == jam.JamId
                                 select xx).FirstOrDefault();
                if (findClock != null && jam.JamClock != null)
                {
                    findClock.IsClockAtZero = jam.JamClock.IsClockAtZero == true ? 1 : 0;
                    findClock.IsRunning = jam.JamClock.IsRunning == true ? 1 : 0;
                    findClock.Length = jam.JamClock.TimerLength;
                    if (jam.JamClock.StartTime != new DateTime())
                        findClock.StartDateTime = jam.JamClock.StartTime;
                    findClock.TimeElapsed = jam.JamClock.TimeElapsed;
                    findClock.TimeRemaining = jam.JamClock.TimeRemaining;
                    findClock.LastModified = DateTime.UtcNow;
                    findClock.Game = gDb;
                    db.SaveChanges();
                }
                else if (jam.JamClock != null && jam.JamClock.StartTime != new DateTime())
                {
                    GameStopwatch stop = new GameStopwatch();
                    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;
                    if (jam.JamClock.StartTime != new DateTime())
                        stop.StartDateTime = jam.JamClock.StartTime;
                    stop.StopwatchForId = game.GameId;
                    stop.TimeElapsed = jam.JamClock.TimeElapsed;
                    stop.TimeRemaining = jam.JamClock.TimeRemaining;
                    stop.JamNumber = jam.JamNumber;
                    stop.JamId = jam.JamId;
                    stop.Type = (int)StopWatchTypeEnum.JamClock;
                    stop.Game = gDb;
                    db.GameStopWatch.Add(stop);
                    db.SaveChanges();
                }
                c += db.SaveChanges();
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return c;
        }
Exemplo n.º 4
0
        /// <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;
        }
Exemplo n.º 5
0
        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;
        }
        public static GameViewModel getGameFromDb(Guid id)
        {
            try
            {
                ManagementContext db = new ManagementContext();
                var getGame = (from xx in db.Games.Include("GameLinks").Include("GameMemberPenalties").Include("GameMemberAssists").Include("GameMemberBlocks").Include("GameTeams").Include("GameJams").Include("GamePolicy").Include("GameScores").Include("GameTimeouts").Include("GameTeams.Logo")
                               where xx.GameId == id
                               //game must be published to be used.

                               //where xx.IsGamePublishedOnline == true
                               select xx).FirstOrDefault();

                if (getGame == null)
                    return null;
                GameViewModel game = new GameViewModel();

                if (getGame.GameTournament != null)
                {
                    game.TournamentId = getGame.GameTournament.TournamentId;
                    game.TournamentName = getGame.GameTournament.TournamentName;
                }
                if (getGame.FederationOwners.Count > 0)
                {
                    game.FederationId = getGame.FederationOwners.FirstOrDefault().Federation.FederationId;
                    game.FederationName = getGame.FederationOwners.FirstOrDefault().Federation.Name;
                }
                if (getGame.SelectedShop != null)
                    game.SelectedShop = getGame.SelectedShop.MerchantId.ToString();
                game.IsThereVideoOfGame = (GameVideoTypeEnum)Enum.Parse(typeof(GameVideoTypeEnum), getGame.IsThereVideoOfGame.ToString());
                game.StreamingUrlOfVideo = getGame.StreamingUrlOfVideo;
                game.StreamingUrlOfVideoMobile = getGame.StreamingUrlOfVideoMobile;
                game.EmbededVideoHtml = getGame.EmbededVideoHtml;
                game.LastModified = DateTime.UtcNow;
                game.IdForOnlineManagementUse = getGame.IdForOnlineManagementUse;
                game.ElapsedTimeGameClockMilliSeconds = (long)getGame.ElapsedGameTimeInMilliseconds;
                game.GameDate = getGame.GameDate;
                game.GameEndDate = getGame.GameEndDate;
                game.GameId = id;
                game.GameName = getGame.GameName;
                game.HasGameEnded = getGame.IsGameOver;
                game.HasGameStarted = getGame.HasGameStarted;
                game.GameLocation = getGame.GameLocation;
                game.PublishGameOnline = getGame.IsGameLive;
                game.SaveGameOnline = getGame.IsGameScrimmage;
                GameClock.getPeriodClock(id, game);
                GameClock.getIntermissionClock(id, game);
                GameClock.getLineUpClock(id, game);
                GameClock.getTimeOutClock(id, game);
                if (getGame.Paywall != null)
                    game.PaywallId = getGame.Paywall.PaywallId;


                if (getGame.ScoreboardType == 0)
                    game.ScoreboardMode = ScoreboardModeEnum.Debug;
                else if (getGame.ScoreboardType == 1)
                    game.ScoreboardMode = ScoreboardModeEnum.Live;

                //we order the teams so the first one in, is also the first one out.
                var getTeams = getGame.GameTeams.OrderByDescending(x => x.Created).ToList();
                if (game.ScoresTeam1 == null)
                    game.ScoresTeam1 = new List<ScoreViewModel>();
                if (game.ScoresTeam2 == null)
                    game.ScoresTeam2 = new List<ScoreViewModel>();

                game.GameLinks = new List<GameLinkViewModel>();
                var gameLinkss = getGame.GameLinks.ToList();
                for (int i = 0; i < getGame.GameLinks.Count; i++)
                {
                    GameLinkViewModel gameLink = new GameLinkViewModel();
                    gameLink.GameLink = gameLinkss[i].Link;
                    gameLink.LinkId = gameLinkss[i].GameLinkId;
                    gameLink.LinkType = (GameLinkTypeEnum)Enum.ToObject(typeof(GameLinkTypeEnum), gameLinkss[i].LinkType);
                    game.GameLinks.Add(gameLink);
                }


                for (int i = 0; i < getTeams.Count; i++)
                {
                    TeamViewModel tvm = new TeamViewModel();
                    tvm.TeamId = getTeams[i].TeamId;
                    tvm.Logo = new Portable.Classes.Team.TeamLogo();

                    tvm.TeamLinkId = getTeams[i].TeamIdLink;
                    var dc = new ManagementContext();
                    if (getTeams[i].Logo != null)
                    {
                        tvm.Logo.ImageUrl = getTeams[i].Logo.ImageUrl;
                        tvm.Logo.TeamLogoId = getTeams[i].Logo.TeamLogoId;
                    }

                    tvm.TeamName = getTeams[i].TeamName;
                    tvm.TimeOutsLeft = getTeams[i].CurrentTimeouts;
                    tvm.TeamMembers = new System.Collections.ObjectModel.ObservableCollection<TeamMembersViewModel>();
                    if (i == 0)
                    {
                        game.CurrentTeam1Score = getTeams[i].CurrentScore;
                        game.Team1 = tvm;
                    }
                    else if (i == 1)
                    {
                        game.CurrentTeam2Score = getTeams[i].CurrentScore;
                        game.Team2 = tvm;
                    }


                    foreach (var mem in getTeams[i].GameMembers)
                    {
                        TeamMembersViewModel mvm = new TeamMembersViewModel();
                        mvm.SkaterId = mem.GameMemberId;
                        mvm.SkaterName = mem.MemberName;
                        mvm.SkaterNumber = mem.MemberNumber;
                        mvm.SkaterLinkId = mem.MemberLinkId;

                        if (getTeams[i].TeamId == game.Team1.TeamId)
                            game.Team1.TeamMembers.Add(mvm);
                        else if (getTeams[i].TeamId == game.Team2.TeamId)
                            game.Team2.TeamMembers.Add(mvm);
                    }
                    //scores must come after teams  members get added.
                    var scores = getTeams[i].GameScores.OrderBy(x => x.JamNumber);
                    foreach (var score in scores)
                    {
                        try
                        {
                            ScoreViewModel svm = new ScoreViewModel(score.Point, score.PeriodTimeRemainingMilliseconds, score.JamId, score.JamNumber, score.PeriodNumber, score.DateTimeScored, score.GameScoreId);

                            if (getTeams[i].TeamId == game.Team1.TeamId)
                            {
                                if (score.MemberWhoScored != null)
                                    svm.PlayerWhoScored = game.Team1.TeamMembers.Where(x => x.SkaterId == score.MemberWhoScored.GameMemberId).FirstOrDefault();
                                game.ScoresTeam1.Add(svm);
                            }
                            else if (getTeams[i].TeamId == game.Team2.TeamId)
                            {
                                if (score.MemberWhoScored != null)
                                    svm.PlayerWhoScored = game.Team2.TeamMembers.Where(x => x.SkaterId == score.MemberWhoScored.GameMemberId).FirstOrDefault();
                                game.ScoresTeam2.Add(svm);
                            }
                        }
                        catch (Exception exception)
                        {
                            ErrorDatabaseManager.AddException(exception, exception.GetType());
                        }
                    }


                }
                game.BlocksForTeam1 = new List<BlockViewModel>();
                game.BlocksForTeam2 = new List<BlockViewModel>();
                game.AssistsForTeam1 = new List<AssistViewModel>();
                game.AssistsForTeam2 = new List<AssistViewModel>();
                game.PenaltiesForTeam1 = new List<PenaltyViewModel>();
                game.PenaltiesForTeam2 = new List<PenaltyViewModel>();
                //blocks must come after teams  members get added.
                var blocks = getGame.GameMemberBlocks.OrderBy(x => x.JamNumber);
                foreach (var block in blocks)
                {
                    try
                    {
                        BlockViewModel svm = new BlockViewModel(block.PeriodTimeRemainingMilliseconds, block.JamNumber, block.PeriodNumber, block.DateTimeBlocked, block.GameBlockId);

                        var member = game.Team1.TeamMembers.Where(x => x.SkaterId == block.MemberWhoBlocked.GameMemberId).FirstOrDefault();
                        if (member == null)
                        {
                            member = game.Team2.TeamMembers.Where(x => x.SkaterId == block.MemberWhoBlocked.GameMemberId).FirstOrDefault();
                            svm.PlayerWhoBlocked = member;
                            game.BlocksForTeam2.Add(svm);
                        }
                        else
                        {
                            svm.PlayerWhoBlocked = member;
                            game.BlocksForTeam1.Add(svm);
                        }
                    }
                    catch (Exception exception)
                    {
                        ErrorDatabaseManager.AddException(exception, exception.GetType());
                    }
                }

                //blocks must come after teams  members get added.
                var assists = getGame.GameMemberAssists.OrderBy(x => x.JamNumber);
                foreach (var assist in assists)
                {
                    try
                    {
                        AssistViewModel svm = new AssistViewModel(assist.PeriodTimeRemainingMilliseconds, assist.JamNumber, assist.PeriodNumber, assist.DateTimeAssisted, assist.GameAssistId);

                        var member = game.Team1.TeamMembers.Where(x => x.SkaterId == assist.MemberWhoAssisted.GameMemberId).FirstOrDefault();
                        if (member == null)
                        {
                            member = game.Team2.TeamMembers.Where(x => x.SkaterId == assist.MemberWhoAssisted.GameMemberId).FirstOrDefault();
                            svm.PlayerWhoAssisted = member;
                            game.AssistsForTeam2.Add(svm);
                        }
                        else
                        {
                            svm.PlayerWhoAssisted = member;
                            game.AssistsForTeam1.Add(svm);
                        }
                    }
                    catch (Exception exception)
                    {
                        ErrorDatabaseManager.AddException(exception, exception.GetType());
                    }
                }

                var penal = getGame.GameMemberPenalties.OrderBy(x => x.JamNumber);
                foreach (var pen in penal)
                {
                    try
                    {
                        PenaltyViewModel svm = new PenaltyViewModel((PenaltiesEnum)Enum.Parse(typeof(PenaltiesEnum), pen.PenaltyType.ToString()), pen.PeriodTimeRemainingMilliseconds, pen.JamNumber, pen.PeriodNumber, pen.DateTimePenaltied, pen.GamePenaltyId);

                        var member = game.Team1.TeamMembers.Where(x => x.SkaterId == pen.MemberWhoPenaltied.GameMemberId).FirstOrDefault();
                        if (member == null)
                        {
                            member = game.Team2.TeamMembers.Where(x => x.SkaterId == pen.MemberWhoPenaltied.GameMemberId).FirstOrDefault();
                            svm.PenaltyAgainstMember = member;
                            game.PenaltiesForTeam2.Add(svm);
                        }
                        else
                        {
                            svm.PenaltyAgainstMember = member;
                            game.PenaltiesForTeam1.Add(svm);
                        }
                    }
                    catch (Exception exception)
                    {
                        ErrorDatabaseManager.AddException(exception, exception.GetType());
                    }
                }

                var getJams = getGame.GameJams.OrderBy(x => x.JamNumber).ToList();
                var getJamClocks = (from xx in db.GameStopWatch
                                    where xx.StopwatchForId == id
                                    where xx.Type == (int)StopWatchTypeEnum.JamClock
                                    select xx).ToList();

                foreach (var jam in getJams)
                {
                    try
                    {
                        JamViewModel jvm = new JamViewModel(jam.JamNumber, jam.GameTimeElapsedMillisecondsStart, jam.CurrentPeriod);
                        var scoresT1 = game.ScoresTeam1.Where(x => x.JamNumber == jam.JamNumber);
                        foreach (var score in scoresT1)
                            jvm.TotalPointsForJamT1 += score.Points;

                        var scoresT2 = game.ScoresTeam2.Where(x => x.JamNumber == jam.JamNumber);
                        foreach (var score in scoresT2)
                            jvm.TotalPointsForJamT2 += score.Points;

                        var getClock = getJamClocks.Where(x => x.JamNumber == jam.JamNumber).FirstOrDefault();
                        if (getClock != null)
                        {
                            StopwatchWrapper stop = new StopwatchWrapper();
                            stop.IsClockAtZero = getClock.IsClockAtZero == 1 ? true : false;
                            stop.IsRunning = getClock.IsRunning == 1 ? true : false;
                            stop.StartTime = getClock.StartDateTime;
                            stop.TimeElapsed = getClock.TimeElapsed;
                            stop.TimeRemaining = getClock.TimeRemaining;
                            stop.TimerLength = getClock.Length;
                            jvm.JamClock = stop;
                        }

                        if (jam.Blocker1Team1 != null)
                        {
                            TeamMembersViewModel tmvm = new TeamMembersViewModel();
                            tmvm.SkaterId = jam.Blocker1Team1.GameMemberId;
                            tmvm.SkaterLinkId = jam.Blocker1Team1.MemberLinkId;
                            tmvm.SkaterName = jam.Blocker1Team1.MemberName;
                            tmvm.SkaterNumber = jam.Blocker1Team1.MemberNumber;
                            jvm.Blocker1T1 = tmvm;
                        }
                        if (jam.Blocker2Team1 != null)
                        {
                            TeamMembersViewModel tmvm = new TeamMembersViewModel();
                            tmvm.SkaterId = jam.Blocker2Team1.GameMemberId;
                            tmvm.SkaterLinkId = jam.Blocker2Team1.MemberLinkId;
                            tmvm.SkaterName = jam.Blocker2Team1.MemberName;
                            tmvm.SkaterNumber = jam.Blocker2Team1.MemberNumber;
                            jvm.Blocker2T1 = tmvm;
                        }
                        if (jam.Blocker3Team1 != null)
                        {
                            TeamMembersViewModel tmvm = new TeamMembersViewModel();
                            tmvm.SkaterId = jam.Blocker3Team1.GameMemberId;
                            tmvm.SkaterLinkId = jam.Blocker3Team1.MemberLinkId;
                            tmvm.SkaterName = jam.Blocker3Team1.MemberName;
                            tmvm.SkaterNumber = jam.Blocker3Team1.MemberNumber;
                            jvm.Blocker3T1 = tmvm;
                        }
                        if (jam.Blocker4Team1 != null)
                        {
                            TeamMembersViewModel tmvm = new TeamMembersViewModel();
                            tmvm.SkaterId = jam.Blocker4Team1.GameMemberId;
                            tmvm.SkaterLinkId = jam.Blocker4Team1.MemberLinkId;
                            tmvm.SkaterName = jam.Blocker4Team1.MemberName;
                            tmvm.SkaterNumber = jam.Blocker4Team1.MemberNumber;
                            jvm.Blocker4T1 = tmvm;
                        }
                        if (jam.PivotTeam1 != null)
                        {
                            TeamMembersViewModel tmvm = new TeamMembersViewModel();
                            tmvm.SkaterId = jam.PivotTeam1.GameMemberId;
                            tmvm.SkaterLinkId = jam.PivotTeam1.MemberLinkId;
                            tmvm.SkaterName = jam.PivotTeam1.MemberName;
                            tmvm.SkaterNumber = jam.PivotTeam1.MemberNumber;
                            jvm.PivotT1 = tmvm;
                        }
                        if (jam.JammerTeam1 != null)
                        {
                            TeamMembersViewModel tmvm = new TeamMembersViewModel();
                            tmvm.SkaterId = jam.JammerTeam1.GameMemberId;
                            tmvm.SkaterLinkId = jam.JammerTeam1.MemberLinkId;
                            tmvm.SkaterName = jam.JammerTeam1.MemberName;
                            tmvm.SkaterNumber = jam.JammerTeam1.MemberNumber;
                            jvm.JammerT1 = tmvm;
                        }
                        if (jam.Blocker1Team2 != null)
                        {
                            TeamMembersViewModel tmvm = new TeamMembersViewModel();
                            tmvm.SkaterId = jam.Blocker1Team2.GameMemberId;
                            tmvm.SkaterLinkId = jam.Blocker1Team2.MemberLinkId;
                            tmvm.SkaterName = jam.Blocker1Team2.MemberName;
                            tmvm.SkaterNumber = jam.Blocker1Team2.MemberNumber;
                            jvm.Blocker1T2 = tmvm;
                        }
                        if (jam.Blocker2Team2 != null)
                        {
                            TeamMembersViewModel tmvm = new TeamMembersViewModel();
                            tmvm.SkaterId = jam.Blocker2Team2.GameMemberId;
                            tmvm.SkaterLinkId = jam.Blocker2Team2.MemberLinkId;
                            tmvm.SkaterName = jam.Blocker2Team2.MemberName;
                            tmvm.SkaterNumber = jam.Blocker2Team2.MemberNumber;
                            jvm.Blocker2T2 = tmvm;
                        }
                        if (jam.Blocker3Team2 != null)
                        {
                            TeamMembersViewModel tmvm = new TeamMembersViewModel();
                            tmvm.SkaterId = jam.Blocker3Team2.GameMemberId;
                            tmvm.SkaterLinkId = jam.Blocker3Team2.MemberLinkId;
                            tmvm.SkaterName = jam.Blocker3Team2.MemberName;
                            tmvm.SkaterNumber = jam.Blocker3Team2.MemberNumber;
                            jvm.Blocker3T2 = tmvm;
                        }
                        if (jam.Blocker4Team2 != null)
                        {
                            TeamMembersViewModel tmvm = new TeamMembersViewModel();
                            tmvm.SkaterId = jam.Blocker4Team2.GameMemberId;
                            tmvm.SkaterLinkId = jam.Blocker4Team2.MemberLinkId;
                            tmvm.SkaterName = jam.Blocker4Team2.MemberName;
                            tmvm.SkaterNumber = jam.Blocker4Team2.MemberNumber;
                            jvm.Blocker4T2 = tmvm;
                        }
                        if (jam.PivotTeam2 != null)
                        {
                            TeamMembersViewModel tmvm = new TeamMembersViewModel();
                            tmvm.SkaterId = jam.PivotTeam2.GameMemberId;
                            tmvm.SkaterLinkId = jam.PivotTeam2.MemberLinkId;
                            tmvm.SkaterName = jam.PivotTeam2.MemberName;
                            tmvm.SkaterNumber = jam.PivotTeam2.MemberNumber;
                            jvm.PivotT2 = tmvm;
                        }
                        if (jam.JammerTeam2 != null)
                        {
                            TeamMembersViewModel tmvm = new TeamMembersViewModel();
                            tmvm.SkaterId = jam.JammerTeam2.GameMemberId;
                            tmvm.SkaterLinkId = jam.JammerTeam2.MemberLinkId;
                            tmvm.SkaterName = jam.JammerTeam2.MemberName;
                            tmvm.SkaterNumber = jam.JammerTeam2.MemberNumber;
                            jvm.JammerT2 = tmvm;
                        }

                        //gets all the lead jammers for this particular jam.
                        var getLeadJammers = jam.LeadJammers.ToList();
                        foreach (var lJam in getLeadJammers)
                        {
                            try
                            {
                                if (lJam.GameMemberId != new Guid())
                                {
                                    LeadJammerViewModel ljvm = new LeadJammerViewModel();
                                    ljvm.GameTimeInMilliseconds = lJam.GameTimeInMilliseconds;
                                    ljvm.Jammer = new TeamMembersViewModel();
                                    ljvm.Jammer.SkaterId = lJam.GameMemberId;
                                    ljvm.JamTimeInMilliseconds = lJam.JamTimeInMilliseconds;
                                    ljvm.GameLeadJamId = lJam.GameJamLeadId;
                                    jvm.LeadJammers.Add(ljvm);
                                }
                            }
                            catch (Exception exception)
                            { ErrorDatabaseManager.AddException(exception, exception.GetType()); }
                        }

                        game.Jams.Add(jvm);
                    }
                    catch (Exception exception)
                    { ErrorDatabaseManager.AddException(exception, exception.GetType()); }
                }


                var Penalties = getGame.GameMemberPenaltyBox.ToList();

                for (int i = 0; i < Penalties.Count; i++)
                {
                    SkaterInPenaltyBoxViewModel skater = new SkaterInPenaltyBoxViewModel();
                    skater.GameTimeInMillisecondsReleased = Penalties[i].GameTimeMilliSecondsReturned;
                    skater.GameTimeInMillisecondsSent = Penalties[i].GameTimeMilliSecondsSent;
                    skater.JamNumberReleased = Penalties[i].JamNumberReturned;
                    skater.JamNumberSent = Penalties[i].JamNumberSent;
                    skater.JamTimeInMillisecondsReleased = Penalties[i].JamTimeMilliSecondsReturned;
                    skater.JamTimeInMillisecondsSent = Penalties[i].JamTimeMilliSecondsSent;
                    skater.PenaltyId = Penalties[i].PenaltyIdFromGame;
                    skater.PenaltyScale = (PenaltyScaleEnum)Enum.ToObject(typeof(PenaltyScaleEnum), (int)Penalties[i].PenaltyScale);
                    skater.PenaltyType = (PenaltiesEnum)Enum.Parse(typeof(PenaltiesEnum), Penalties[i].PenaltyType);
                    skater.PenaltyNumberForSkater = Penalties[i].PenaltyNumberForSkater;
                    bool checkIfPenaltyIsAssigned = false;


                    for (int j = 0; j < game.Team1.TeamMembers.Count; j++)
                    {
                        if (game.Team1.TeamMembers[j].SkaterId == Penalties[i].Member.GameMemberId)
                        {
                            skater.PlayerSentToBox = game.Team1.TeamMembers[j];
                            game.Team1.TeamMembers[j].Penalties.Add(new PenaltyViewModel(skater.PenaltyType));
                            checkIfPenaltyIsAssigned = true;
                            break;
                        }
                    }
                    if (!checkIfPenaltyIsAssigned)
                    {
                        for (int j = 0; j < game.Team2.TeamMembers.Count; j++)
                        {
                            if (game.Team2.TeamMembers[j].SkaterId == Penalties[i].Member.GameMemberId)
                            {
                                skater.PlayerSentToBox = game.Team2.TeamMembers[j];
                                game.Team2.TeamMembers[j].Penalties.Add(new PenaltyViewModel(skater.PenaltyType));
                                checkIfPenaltyIsAssigned = true;
                                break;
                            }
                        }
                    }

                    game.PenaltyBox.Add(skater);
                }

                var getPolicies = getGame.GamePolicy;
                if (getPolicies != null)
                {
                    if (game.Policy == null)
                        game.Policy = PolicyViewModel.Instance;
                    game.Policy.AdChangeAutomaticallyChangeImage = getPolicies.AdChangeAutomaticallyChangeImage == 0 ? false : true;
                    game.Policy.AdChangeDisplayChangesInMilliSeconds = (long)getPolicies.AdChangeDisplayChangesInMilliSeconds;
                    game.Policy.AdChangeShowAdsDuringIntermission = getPolicies.AdChangeShowAdsDuringIntermission == 0 ? false : true;
                    game.Policy.AdChangeShowAdsRandomly = getPolicies.AdChangeShowAdsRandomly == 0 ? false : true;
                    game.Policy.AdChangeUseLineUpClock = getPolicies.AdChangeUseLineUpClock == 0 ? false : true;
                    game.Policy.AlwaysShowJamClock = getPolicies.AlwaysShowJamClock == 0 ? false : true;
                    game.Policy.EnableAdChange = getPolicies.EnableAdChange == 0 ? false : true;
                    game.Policy.EnableIntermissionNaming = getPolicies.EnableIntermissionNaming == 0 ? false : true;
                    game.Policy.EnableIntermissionStartOfClock = getPolicies.EnableIntermissionStartOfClock == 0 ? false : true;
                    game.Policy.FirstIntermissionNameConfirmedText = getPolicies.FirstIntermissionNameConfirmedText;
                    game.Policy.FirstIntermissionNameText = getPolicies.FirstIntermissionNameText;
                    game.Policy.GameSelectionType = (GameTypeEnum)Enum.Parse(typeof(GameTypeEnum), getPolicies.GameSelectionType);
                    game.Policy.HideClockTimeAfterBout = getPolicies.HideClockTimeAfterBout == 0 ? false : true;
                    game.Policy.IntermissionOtherText = getPolicies.IntermissionOtherText;
                    game.Policy.IntermissionStartOfClockInMilliseconds = (long)getPolicies.IntermissionStartOfClockInMilliseconds;
                    game.Policy.IntermissionStopClockEnable = getPolicies.IntermissionStopClockEnable == 0 ? false : true;
                    game.Policy.IntermissionStopClockIncrementJamNumber = getPolicies.IntermissionStopClockIncrementJamNumber == 0 ? false : true;
                    game.Policy.IntermissionStopClockIncrementPeriodNumber = getPolicies.IntermissionStopClockIncrementPeriodNumber == 0 ? false : true;
                    game.Policy.IntermissionStopClockResetJamNumber = getPolicies.IntermissionStopClockResetJamNumber == 0 ? false : true;
                    game.Policy.IntermissionStopClockResetJamTime = getPolicies.IntermissionStopClockResetJamTime == 0 ? false : true;
                    game.Policy.IntermissionStopClockResetPeriodNumber = getPolicies.IntermissionStopClockResetPeriodNumber == 0 ? false : true;
                    game.Policy.IntermissionStopClockResetPeriodTime = getPolicies.IntermissionStopClockResetPeriodTime == 0 ? false : true;
                    game.Policy.JamClockControlsLineUpClock = getPolicies.JamClockControlsLineUpClock == 0 ? false : true;
                    game.Policy.JamClockControlsTeamPositions = getPolicies.JamClockControlsTeamPositions == 0 ? false : true;
                    game.Policy.JamClockTimePerJam = (long)getPolicies.JamClockTimePerJam;
                    game.Policy.LineupClockControlsStartJam = getPolicies.LineupClockControlsStartJam == 0 ? false : true;
                    game.Policy.LineUpClockPerJam = (long)getPolicies.LineUpClockPerJam;
                    game.Policy.NumberOfPeriods = (int)getPolicies.NumberOfPeriods;
                    game.Policy.PenaltyBoxControlsLeadJammer = getPolicies.PenaltyBoxControlsLeadJammer == 0 ? false : true;
                    game.Policy.PeriodClock = (long)getPolicies.PeriodClock;
                    game.Policy.PeriodClockControlsLineupJamClock = getPolicies.PeriodClockControlsLineupJamClock == 0 ? false : true;
                    game.Policy.SecondIntermissionNameConfirmedText = getPolicies.SecondIntermissionNameConfirmedText;
                    game.Policy.SecondIntermissionNameText = getPolicies.SecondIntermissionNameText;
                    game.Policy.TimeOutClock = (long)getPolicies.TimeOutClock;
                    game.Policy.TimeoutClockControlsLineupClock = getPolicies.TimeoutClockControlsLineupClock == 0 ? false : true;
                    game.Policy.TimeOutsPerPeriod = (int)getPolicies.TimeOutsPerPeriod;
                }




                //TODO: get game adverts.


                var getTimeOuts = getGame.GameTimeouts.ToList();
                foreach (var time in getTimeOuts)
                {
                    TimeOutViewModel tvm = new TimeOutViewModel();

                    tvm.TimeoutId = time.TimeOutId;
                    if (time.GameTeam != null && time.GameTeam.TeamId == game.Team1.TeamId)
                        tvm.TimeOutType = TimeOutTypeEnum.Team1;
                    else if (time.GameTeam != null && time.GameTeam.TeamId == game.Team2.TeamId)
                        tvm.TimeOutType = TimeOutTypeEnum.Team2;
                    else
                        tvm.TimeOutType = TimeOutTypeEnum.Offical;

                    if (game.TimeOuts == null)
                        game.TimeOuts = new List<TimeOutViewModel>();

                    game.TimeOuts.Add(tvm);
                }

                return game;
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return null;
        }