示例#1
0
 public IEnumerable<Match> GetByRound(Round round)
 {
     using (var matchRepository = new RepositoryFactory().CreateMatchRepository())
      {
     return matchRepository.GetByRound(round.Id);
      }
 }
示例#2
0
        public List<Match> DrawNextRound(Round previousRound)
        {
            var matchesToUpdate = new List<Match>();

             // Determine whether for the given round all matches have been played.
             using (var matchRepository = new RepositoryFactory().CreateMatchRepository())
             using (var roundRepository = new RepositoryFactory().CreateRoundRepository())
             {
            var matchesCurrentRound = matchRepository.GetByRound(previousRound.Id).ToList();
            bool allMatchesPlayed = matchesCurrentRound.All(match => match.MatchStatus == MatchStatus.Ended);

            if (allMatchesPlayed)
            {
               // Determine the next round and verify the matches have no home and away teams defined yet.
               var nextRound = roundRepository.GetNextRound(previousRound);
               if (nextRound != null)
               {
                  var matchesNextRound = matchRepository.GetByRound(nextRound.Id).ToList();
                  bool roundMustBeDrawn = matchesNextRound.All(match => match.MatchStatus == MatchStatus.TeamsUndefined);

                  if (roundMustBeDrawn)
                  {
                     var winners = matchesCurrentRound.Select(match => match.GetWinner()).ToList();
                     new KnockoutTournamentManager().DrawNextRound(winners, matchesNextRound);

                     foreach (var match in matchesNextRound)
                     {
                        matchesToUpdate.Add(match);
                     }
                  }
               }
            }
             }

             return matchesToUpdate;
        }