Example #1
0
        private void AddTeamPenalties(IList <Jam> jams, Dictionary <string, Player> players, Dictionary <int, PlayerPenaltiesModel> playerPenalties)
        {
            //PenaltyProcessor processor = new PenaltyProcessor(jams, players);
            PenaltyGateway penaltyGateway = new PenaltyGateway(_connection, _transaction);
            bool           isSuccess      = true;

            foreach (KeyValuePair <int, PlayerPenaltiesModel> kvp in playerPenalties)
            {
                int penaltyCount = 0;
                foreach (PenaltyModel penalty in kvp.Value.Penalties)
                {
                    Jam jam = jams.FirstOrDefault(j => j.IsFirstHalf == penalty.IsFirstHalf && j.JamNumber == penalty.JamNumber);
                    if (jam == null)
                    {
                        Console.WriteLine(string.Format("Unknown jam number {0} on penalty for player {1}.", penalty.JamNumber, kvp.Value.PlayerNumber));
                        isSuccess = false;
                    }
                    penaltyCount++;
                    Penalty pen = new Penalty
                    {
                        JamID         = jam.ID,
                        PlayerID      = kvp.Key,
                        PenaltyCode   = penalty.PenaltyCode,
                        PenaltyNumber = penaltyCount,
                        MatchingKey   = penalty.SpecificKey
                    };
                    if (pen.MatchingKey != null)
                    {
                        Console.WriteLine(string.Format("Special case penalty {0}{1} encountered in {2}", penalty.PenaltyCode, penalty.SpecificKey, penalty.JamNumber));
                    }
                    penaltyGateway.AddBasicPenalty(pen);
                }
            }
            if (!isSuccess)
            {
                throw new InvalidOperationException("Bad penalty data");
            }
        }
Example #2
0
 private void AddTeamPenalties(IList<Jam> jams, Dictionary<string, Player> players, Dictionary<int, PlayerPenaltiesModel> playerPenalties)
 {
     //PenaltyProcessor processor = new PenaltyProcessor(jams, players);
     PenaltyGateway penaltyGateway = new PenaltyGateway(_connection, _transaction);
     bool isSuccess = true;
     foreach(KeyValuePair<int, PlayerPenaltiesModel> kvp in playerPenalties)
     {
         int penaltyCount = 0;
         foreach(PenaltyModel penalty in kvp.Value.Penalties)
         {
             Jam jam = jams.FirstOrDefault(j => j.IsFirstHalf == penalty.IsFirstHalf && j.JamNumber == penalty.JamNumber);
             if(jam == null)
             {
                 Console.WriteLine(string.Format("Unknown jam number {0} on penalty for player {1}.", penalty.JamNumber, kvp.Value.PlayerNumber));
                 isSuccess = false;
             }
             penaltyCount++;
             Penalty pen = new Penalty
             {
                 JamID = jam.ID,
                 PlayerID = kvp.Key,
                 PenaltyCode = penalty.PenaltyCode,
                 PenaltyNumber = penaltyCount,
                 MatchingKey = penalty.SpecificKey
             };
             if(pen.MatchingKey != null)
             {
                 Console.WriteLine(string.Format("Special case penalty {0}{1} encountered in {2}", penalty.PenaltyCode, penalty.SpecificKey, penalty.JamNumber));
             }
             penaltyGateway.AddBasicPenalty(pen);
         }
     }
     if(!isSuccess)
     {
         throw new InvalidOperationException("Bad penalty data");
     }
 }