Ejemplo n.º 1
0
        public TournamentGames GetGame(int player1Id, int player2Id, int tournamentId, int groupId)
        {
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("@tournamentId", tournamentId);
            parameters.Add("@groupId", groupId);
            parameters.Add("@player1Id", player1Id);
            parameters.Add("@player2Id", player2Id);

            using (var cmd = CreateCommand("GetGame", parameters))
            {
                using (var reader = cmd.ExecuteReader())
                {
                    reader.Read();
                    var game = new TournamentGames()
                    {
                        tournamentId = (int)reader["TournamentId"],
                        player1Score = (int)reader["Player1Score"],
                        player2Score = (int)reader["Player2Score"],
                        state        = ((string)reader["State"])[0],
                        scoreEditor  = reader["ScoreEditor"] as int?
                    };

                    return(game);
                }
            }
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,TournametId,GameId")] TournamentGames tournamentGames)
        {
            if (id != tournamentGames.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tournamentGames);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TournamentGamesExists(tournamentGames.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GameId"]      = new SelectList(_context.Game, "Id", "Name", tournamentGames.GameId);
            ViewData["TournametId"] = new SelectList(_context.Tournament, "Id", "Location", tournamentGames.TournametId);
            return(View(tournamentGames));
        }
Ejemplo n.º 3
0
 private static void ReadGamesList(RoundTypes roundTypeFilter, IDataReader reader, List <TournamentGames> tournamentGamesList)
 {
     while (reader.Read())
     {
         TournamentGames game = GetTournamentGameFromReader(reader);
         if (GameIsIncludedInFilter(roundTypeFilter, game))
         {
             tournamentGamesList.Add(game);
         }
     }
 }
Ejemplo n.º 4
0
        private static TournamentGames GetTournamentGameFromReader(IDataReader reader)
        {
            TournamentGames game = new TournamentGames()
            {
                tournamentId = (int)reader["TournamentId"],
                groupId      = (int)reader["GroupID"],
                name         = (string)reader["Name"],
                player1Id    = (int)reader["Player1Id"],
                player1Name  = (string)reader["player1Name"],
                player1Score = (reader["Player1Score"] is DBNull) ? 0 : (int)reader["Player1Score"],
                player2Id    = (int)reader["Player2Id"],
                player2Name  = (string)reader["player2Name"],
                player2Score = (reader["Player2Score"] is DBNull) ? 0 : (int)reader["Player2Score"],
                roundId      = (int)reader["RoundId"],
                state        = (char)GetGameStateFromReader(reader)
            };

            return(game);
        }
Ejemplo n.º 5
0
 private static bool GameIsIncludedInFilter(RoundTypes roundTypeFilter, TournamentGames game)
 {
     if ((RoundTypes)game.roundId == roundTypeFilter || roundTypeFilter == RoundTypes.ANY_TYPE)
     {
         return(true);
     }
     if (roundTypeFilter == RoundTypes.KNOCKOUT_ANY &&
         ((RoundTypes)game.roundId == RoundTypes.KNOCKOUT_64 ||
          (RoundTypes)game.roundId == RoundTypes.KNOCKOUT_32 ||
          (RoundTypes)game.roundId == RoundTypes.KNOCKOUT_16 ||
          (RoundTypes)game.roundId == RoundTypes.KNOCKOUT_8 ||
          (RoundTypes)game.roundId == RoundTypes.QUATERFINALS ||
          (RoundTypes)game.roundId == RoundTypes.SEMIFINALS ||
          (RoundTypes)game.roundId == RoundTypes.FINALS))
     {
         return(true);
     }
     return(false);
 }
        public async Task <IActionResult> Create(int gameId, string gameName, [Bind("Id,TournametId")] TournamentGames tournamentGames)
        {
            if (gameName == null)
            {
                return(RedirectToAction("Home", "Index"));
            }
            TournamentGames tg = new TournamentGames();

            tg.GameId = gameId;
            tournamentGames.GameId = gameId;
            tg.TournametId         = tournamentGames.TournametId;

            if (ModelState.IsValid)
            {
                _context.Add(tg);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", new { id = gameId, name = gameName }));
            }

            return(RedirectToAction("Index", new { id = gameId, name = gameName }));
        }
Ejemplo n.º 7
0
 private static void AddWinner(TournamentGames game, List <PlayerScore> winners)
 {
     // Knockout games are best of 3, so draws are not possible
     if (Player1Wins(game))
     {
         winners.Add(
             new PlayerScore()
         {
             id = game.player1Id, groupId = game.groupId
         }
             );
     }
     else
     {
         winners.Add(
             new PlayerScore()
         {
             id = game.player2Id, groupId = game.groupId
         }
             );
     }
 }
Ejemplo n.º 8
0
 private static bool InputScoreMatchesExistingScore(int player1Score, int player2Score, TournamentGames game)
 {
     return(game.scoreEditor != null && player1Score == game.player1Score && player2Score == game.player2Score);
 }
Ejemplo n.º 9
0
 private static bool UserIsScoreEditor(int userId, TournamentGames game)
 {
     return(userId == game.scoreEditor);
 }
Ejemplo n.º 10
0
 private static bool Player1Wins(TournamentGames game)
 {
     return(game.player1Score > game.player2Score);
 }