Exemplo n.º 1
0
        private void AddPenaltyServices(Dictionary<string, Player> homePlayerMap, Dictionary<string, Player> awayPlayerMap, 
                                        IList<Jam> jams, IList<JamLineupModel> lineups, IList<JamScoreModel> scores, PenaltiesModel penalties)
        {
            Dictionary<int, Dictionary<int, IList<Models.BoxTimeModel>>> homePlayerBoxTimeMap = new Dictionary<int, Dictionary<int, IList<Models.BoxTimeModel>>>();
            Dictionary<int, Dictionary<int, IList<Models.BoxTimeModel>>> awayPlayerBoxTimeMap = new Dictionary<int, Dictionary<int, IList<Models.BoxTimeModel>>>();
            Dictionary<int, int> homeEndJammerMap = new Dictionary<int, int>();
            Dictionary<int, int> awayEndJammerMap = new Dictionary<int, int>();
            foreach (JamLineupModel jamLineup in lineups)
            {
                Jam jam = jams.First(j => j.IsFirstHalf == jamLineup.IsFirstHalf && j.JamNumber == jamLineup.JamNumber);
                JamScoreModel jsm = scores.First(s => s.IsFirstHalf == jam.IsFirstHalf && s.JamNumber == jam.JamNumber);
                foreach (PlayerLineupModel playerLineup in jamLineup.HomeLineup)
                {
                    if(playerLineup == null)
                    {
                        continue;
                    }
                    int playerID = homePlayerMap[playerLineup.PlayerNumber].ID;
                    if (playerLineup.IsJammer && jsm.HomeStarPass == null)
                    {
                        homeEndJammerMap[jam.ID] = playerID;
                    }
                    else if(playerLineup.IsPivot && jsm.HomeStarPass != null)
                    {
                        homeEndJammerMap[jam.ID] = playerID;
                    }
                    if (playerLineup.BoxTimes != null && playerLineup.BoxTimes.Any())
                    {

                        if (!homePlayerBoxTimeMap.ContainsKey(playerID))
                        {
                            homePlayerBoxTimeMap[playerID] = new Dictionary<int, IList<Models.BoxTimeModel>>();
                        }
                        homePlayerBoxTimeMap[playerID][jam.ID] = playerLineup.BoxTimes;
                    }
                }
                foreach (PlayerLineupModel playerLineup in jamLineup.AwayLineup)
                {
                    if (playerLineup == null)
                    {
                        continue;
                    }
                    int playerID = awayPlayerMap[playerLineup.PlayerNumber].ID;
                    if (playerLineup.IsJammer && jsm.HomeStarPass == null)
                    {
                        awayEndJammerMap[jam.ID] = playerID;
                    }
                    else if (playerLineup.IsPivot && jsm.HomeStarPass != null)
                    {
                        awayEndJammerMap[jam.ID] = playerID;
                    }
                    if (playerLineup.BoxTimes != null && playerLineup.BoxTimes.Any())
                    {
                        if (!awayPlayerBoxTimeMap.ContainsKey(playerID))
                        {
                            awayPlayerBoxTimeMap[playerID] = new Dictionary<int, IList<Models.BoxTimeModel>>();
                        }
                        awayPlayerBoxTimeMap[playerID][jam.ID] = playerLineup.BoxTimes;
                    }
                }
            }

            Dictionary<int, PlayerPenaltiesModel> homePlayerPenalties = penalties.HomePlayerPenalties.ToDictionary(pp => homePlayerMap[pp.PlayerNumber].ID);
            Dictionary<int, PlayerPenaltiesModel> awayPlayerPenalties = penalties.AwayPlayerPenalties.ToDictionary(pp => awayPlayerMap[pp.PlayerNumber].ID);

            PenaltyProcessor processor = new PenaltyProcessor(jams, homePlayerMap, awayPlayerMap);
            var service = processor.ProcessPenalties(homePlayerBoxTimeMap, homePlayerPenalties, homeEndJammerMap, awayPlayerBoxTimeMap, awayPlayerPenalties, awayEndJammerMap);
            PenaltyGateway penaltyGateway = new PenaltyGateway(_connection, _transaction);
            penaltyGateway.AddPenalties(service);
        }
Exemplo n.º 2
0
        private void AddPenaltyServices(Dictionary <string, Player> homePlayerMap, Dictionary <string, Player> awayPlayerMap,
                                        IList <Jam> jams, IList <JamLineupModel> lineups, IList <JamScoreModel> scores, PenaltiesModel penalties)
        {
            Dictionary <int, Dictionary <int, IList <Models.BoxTimeModel> > > homePlayerBoxTimeMap = new Dictionary <int, Dictionary <int, IList <Models.BoxTimeModel> > >();
            Dictionary <int, Dictionary <int, IList <Models.BoxTimeModel> > > awayPlayerBoxTimeMap = new Dictionary <int, Dictionary <int, IList <Models.BoxTimeModel> > >();
            Dictionary <int, int> homeEndJammerMap = new Dictionary <int, int>();
            Dictionary <int, int> awayEndJammerMap = new Dictionary <int, int>();

            foreach (JamLineupModel jamLineup in lineups)
            {
                Jam           jam = jams.First(j => j.IsFirstHalf == jamLineup.IsFirstHalf && j.JamNumber == jamLineup.JamNumber);
                JamScoreModel jsm = scores.First(s => s.IsFirstHalf == jam.IsFirstHalf && s.JamNumber == jam.JamNumber);
                foreach (PlayerLineupModel playerLineup in jamLineup.HomeLineup)
                {
                    if (playerLineup == null)
                    {
                        continue;
                    }
                    int playerID = homePlayerMap[playerLineup.PlayerNumber].ID;
                    if (playerLineup.IsJammer && jsm.HomeStarPass == null)
                    {
                        homeEndJammerMap[jam.ID] = playerID;
                    }
                    else if (playerLineup.IsPivot && jsm.HomeStarPass != null)
                    {
                        homeEndJammerMap[jam.ID] = playerID;
                    }
                    if (playerLineup.BoxTimes != null && playerLineup.BoxTimes.Any())
                    {
                        if (!homePlayerBoxTimeMap.ContainsKey(playerID))
                        {
                            homePlayerBoxTimeMap[playerID] = new Dictionary <int, IList <Models.BoxTimeModel> >();
                        }
                        homePlayerBoxTimeMap[playerID][jam.ID] = playerLineup.BoxTimes;
                    }
                }
                foreach (PlayerLineupModel playerLineup in jamLineup.AwayLineup)
                {
                    if (playerLineup == null)
                    {
                        continue;
                    }
                    int playerID = awayPlayerMap[playerLineup.PlayerNumber].ID;
                    if (playerLineup.IsJammer && jsm.AwayStarPass == null)
                    {
                        awayEndJammerMap[jam.ID] = playerID;
                    }
                    else if (playerLineup.IsPivot && jsm.AwayStarPass != null)
                    {
                        awayEndJammerMap[jam.ID] = playerID;
                    }
                    if (playerLineup.BoxTimes != null && playerLineup.BoxTimes.Any())
                    {
                        if (!awayPlayerBoxTimeMap.ContainsKey(playerID))
                        {
                            awayPlayerBoxTimeMap[playerID] = new Dictionary <int, IList <Models.BoxTimeModel> >();
                        }
                        awayPlayerBoxTimeMap[playerID][jam.ID] = playerLineup.BoxTimes;
                    }
                }
            }

            Dictionary <int, PlayerPenaltiesModel> homePlayerPenalties = penalties.HomePlayerPenalties.ToDictionary(pp => homePlayerMap[pp.PlayerNumber].ID);
            Dictionary <int, PlayerPenaltiesModel> awayPlayerPenalties = penalties.AwayPlayerPenalties.ToDictionary(pp => awayPlayerMap[pp.PlayerNumber].ID);

            PenaltyProcessor processor    = new PenaltyProcessor(jams, homePlayerMap, awayPlayerMap);
            var            service        = processor.ProcessPenalties(homePlayerBoxTimeMap, homePlayerPenalties, homeEndJammerMap, awayPlayerBoxTimeMap, awayPlayerPenalties, awayEndJammerMap);
            PenaltyGateway penaltyGateway = new PenaltyGateway(_connection, _transaction);

            penaltyGateway.AddPenalties(service);
        }