public IActionResult GetMatchups(int tournamentId) { var matchups = roundRepository.GetAllMatchups(tournamentId); if (matchups == null || !matchups.Any()) { return(NoContent()); } var currentRound = roundRepository.GetCurrentRound(tournamentId); var scores = roundRepository.GetScoresForTournament(tournamentId); return(Ok(matchups.Select(x => new RoundMatchupDto { RoundNumber = x.Key, RoundId = x.Any() ? x.First().RoundId : -1, Public = currentRound == null ? false : x.Any() && currentRound.Id == x.First().RoundId ? currentRound.Public : true, Matchups = x.Select(y => new MatchupDto { Id = y.Id, TableNumber = y.TableNumber, Player1Id = y.Player1Id, Player2Id = y.Player2Id ?? -1, Player1Score = scores.SingleOrDefault(s => s.MatchupId == y.Id && s.PlayerId == y.Player1Id)?.Amount ?? 0, Player2Score = scores.SingleOrDefault(s => s.MatchupId == y.Id && s.PlayerId == y.Player2Id)?.Amount ?? 0 }).ToList() }))); }
public bool CanGenerateNextRound(int tournamentId) { var currentRound = roundRepository.GetCurrentRound(tournamentId); if (currentRound == null) { return(true); } var scores = roundRepository.GetScoresForTournament(tournamentId); var scoresForCurrentRound = scores.Where(s => s.MatchupId.HasValue && currentRound.Matchups.Select(m => m.Id).Contains(s.MatchupId.Value)).ToList(); return(scoresForCurrentRound.Count == currentRound.Matchups.Sum(m => m.Player2Id.HasValue ? 2 : 1)); }