Ejemplo n.º 1
0
        public Result Handle(RenamePlayerInTournament command)
        {
            Tournament tournament = _tournamentRepository.GetTournamentById(command.TournamentId);

            if (tournament == null)
            {
                return(Result.Failure($"Could not rename player ({ command.CurrentPlayerName }) to { command.NewPlayerName } in tournament ({ command.TournamentId }). Tournament not found."));
            }

            PlayerReference playerReference = tournament.GetPlayerReferenceByName(command.CurrentPlayerName);

            if (playerReference == null)
            {
                return(Result.Failure($"Could not rename player ({ command.CurrentPlayerName }) to { command.NewPlayerName } in tournament ({ command.TournamentId }). Player not found."));
            }

            bool renameSuccessful = _tournamentRepository.RenamePlayerReferenceInTournament(playerReference, command.NewPlayerName);

            if (!renameSuccessful)
            {
                return(Result.Failure($"Could not rename player ({ command.CurrentPlayerName }) to { command.NewPlayerName } in tournament ({ command.TournamentId })."));
            }

            _tournamentRepository.Save();
            return(Result.Success());
        }
Ejemplo n.º 2
0
        public Result Handle(ChangeBestOfInMatch command)
        {
            Tournament tournament = _tournamentRepository.GetTournamentById(command.TournamentId);

            if (tournament == null)
            {
                return(Result.Failure($"Could not change best of ({ command.BestOf }) setting in match ({ command.MatchId }). Tournament ({ command.TournamentId }) not found."));
            }

            Match match = tournament.GetMatchById(command.MatchId);

            if (match == null)
            {
                return(Result.Failure($"Could not change best of ({ command.BestOf }) setting in match ({ command.MatchId }). Match not found."));
            }

            bool changeSuccessful = _tournamentRepository.SetBestOfInMatch(match, command.BestOf);

            if (!changeSuccessful)
            {
                return(Result.Failure($"Could not change best of ({ command.BestOf }) setting in match ({ command.MatchId })."));
            }

            _tournamentRepository.Save();
            return(Result.Success());
        }
Ejemplo n.º 3
0
        public Result Handle(ChangeAdvancingPerGroupCountInRound command)
        {
            Tournament tournament = _tournamentRepository.GetTournamentById(command.TournamentId);

            if (tournament == null)
            {
                return(Result.Failure($"Could not change advancing per group count ({ command.AdvancingPerGroupCount }) setting in round ({ command.RoundId }). Tournament ({ command.TournamentId }) not found."));
            }

            RoundBase round = tournament.GetRoundById(command.RoundId);

            if (round == null)
            {
                return(Result.Failure($"Could not change advancing per group count ({ command.AdvancingPerGroupCount }) setting in round ({ command.RoundId }). Round not found."));
            }

            bool changeSuccessful = _tournamentRepository.SetAdvancingPerGroupCountInRound(round, command.AdvancingPerGroupCount);

            if (!changeSuccessful)
            {
                return(Result.Failure($"Could not change advancing per group count ({ command.AdvancingPerGroupCount }) setting in round ({ command.RoundId })."));
            }

            _tournamentRepository.Save();
            return(Result.Success());
        }
Ejemplo n.º 4
0
        public Result Handle(RenameRoundInTournament command)
        {
            Tournament tournament = _tournamentRepository.GetTournamentById(command.TournamentId);

            if (tournament == null)
            {
                return(Result.Failure($"Could not rename round ({ command.RoundId }) to { command.NewRoundName } in tournament ({ command.TournamentId }). Tournament not found."));
            }

            RoundBase round = tournament.GetRoundById(command.RoundId);

            if (round == null)
            {
                return(Result.Failure($"Could not rename round ({ command.RoundId }) to { command.NewRoundName } in tournament ({ command.TournamentId }). Round not found."));
            }

            bool renameSuccessful = _tournamentRepository.RenameRoundInTournament(round, command.NewRoundName);

            if (!renameSuccessful)
            {
                return(Result.Failure($"Could not rename round ({ command.RoundId }) to { command.NewRoundName } in tournament ({ command.TournamentId })."));
            }

            _tournamentRepository.Save();
            return(Result.Success());
        }
Ejemplo n.º 5
0
        public Result Handle(AddBetterToTournament command)
        {
            Tournament tournament = _tournamentRepository.GetTournamentById(command.TournamentId);

            if (tournament == null)
            {
                return(Result.Failure($"Could not add better to tournament. Tournament ({ command.TournamentId }) not found."));
            }

            User user = _userRepository.GetUserById(command.UserId);

            if (user == null)
            {
                return(Result.Failure($"Could not add better to tournament with given user ({ command.UserId }). Tournament ({ command.TournamentId }) not found."));
            }

            Better better = _tournamentRepository.AddBetterToTournament(tournament, user);

            if (better == null)
            {
                return(Result.Failure($"Could not add better to tournament with given user ({ command.UserId })."));
            }

            _tournamentRepository.Save();
            return(Result.Success());
        }
Ejemplo n.º 6
0
        public Result Handle(SelectPlayerThatAdvancesDuringProblematicTime command)
        {
            Tournament tournament = _tournamentRepository.GetTournamentById(command.TournamentId);

            if (tournament == null)
            {
                return(Result.Failure($"Could not select advancing player ({ command.PlayerName }) in group ({ command.GroupId }) during problematic tie. Tournament ({ command.TournamentId }) not found."));
            }

            GroupBase group = tournament.GetGroupById(command.GroupId);

            if (group == null)
            {
                return(Result.Failure($"Could not select advancing player ({ command.PlayerName }) in group ({ command.GroupId }) during problematic tie. Group not found."));
            }

            List <PlayerReference> playerReferences = group.GetPlayerReferences();
            PlayerReference        playerReference  = playerReferences.FirstOrDefault(playerReference => playerReference.Name == command.PlayerName);

            if (playerReference == null)
            {
                return(Result.Failure($"Could not select advancing player ({ command.PlayerName }) in group ({ command.GroupId }) during problematic tie. Player not found."));
            }

            bool playerChosenSuccessfully = _tournamentRepository.SolveTieByChoosingPlayerInGroup(group, playerReference);

            if (!playerChosenSuccessfully)
            {
                return(Result.Failure($"Could not select advancing player ({ command.PlayerName }) in group ({ command.GroupId }) during problematic tie."));
            }

            _tournamentRepository.Save();
            return(Result.Success());
        }
Ejemplo n.º 7
0
        public Result Handle(ChangeStartTimeOfMatch command)
        {
            Tournament tournament = _tournamentRepository.GetTournamentById(command.TournamentId);

            if (tournament == null)
            {
                return(Result.Failure($"Could not change start time ({ command.StartDateTime }) in match ({ command.MatchId }). Tournament ({ command.TournamentId }) not found."));
            }

            Match match = tournament.GetMatchById(command.MatchId);

            if (match == null)
            {
                return(Result.Failure($"Could not change start time ({ command.StartDateTime }) in match ({ command.MatchId }). Match not found."));
            }

            bool changeSuccessful = _tournamentRepository.SetStartTimeForMatch(match, command.StartDateTime);

            if (!changeSuccessful)
            {
                return(Result.Failure($"Could not change start time ({ command.StartDateTime }) in match ({ command.MatchId })."));
            }

            _tournamentRepository.Save();
            return(Result.Success());
        }
Ejemplo n.º 8
0
        public Result <TournamentDto> Handle(GetTournamentById query)
        {
            Tournament tournament = _tournamentRepository.GetTournamentById(query.TournamentId);

            if (tournament == null)
            {
                return(Result.Failure <TournamentDto>($"Could not find tournament ({ query.TournamentId })"));
            }

            TournamentDto tournamentDto = DomainToDtoConverters.ConvertToTournamentDto(tournament);

            return(Result.Success(tournamentDto));
        }
Ejemplo n.º 9
0
        public Result Handle(SwitchPlacesOfTwoPlayersWithinRound command)
        {
            Tournament tournament = _tournamentRepository.GetTournamentById(command.TournamentId);

            if (tournament == null)
            {
                return(Result.Failure($"Could not switch places on two players ({ command.Player1Id }, { command.Player2Id }) in matches ({ command.Match1Id }, { command.Match2Id }). Tournament ({ command.TournamentId }) not found."));
            }

            Match match1 = tournament.GetMatchById(command.Match1Id);

            if (match1 == null)
            {
                return(Result.Failure($"Could not switch places on two players ({ command.Player1Id }, { command.Player2Id }) in matches ({ command.Match1Id }, { command.Match2Id }). Match ({ command.Match1Id }) not found."));
            }

            Match match2 = tournament.GetMatchById(command.Match2Id);

            if (match2 == null)
            {
                return(Result.Failure($"Could not switch places on two players ({ command.Player1Id }, { command.Player2Id }) in matches ({ command.Match1Id }, { command.Match2Id }). Match ({ command.Match2Id }) not found."));
            }

            Player player1 = match1.FindPlayer(command.Player1Id);

            if (player1 == null)
            {
                return(Result.Failure($"Could not switch places on two players ({ command.Player1Id }, { command.Player2Id }) in matches ({ command.Match1Id }, { command.Match2Id }). Player ({ command.Player1Id }) not found."));
            }

            Player player2 = match2.FindPlayer(command.Player2Id);

            if (player2 == null)
            {
                return(Result.Failure($"Could not switch places on two players ({ command.Player1Id }, { command.Player2Id }) in matches ({ command.Match1Id }, { command.Match2Id }). Player ({ command.Player2Id }) not found."));
            }

            bool switchMade = _tournamentRepository.SwitchPlayersInMatches(player1, player2);

            if (!switchMade)
            {
                return(Result.Failure($"Could not switch places on two players ({ command.Player1Id }, { command.Player2Id }) in matches ({ command.Match1Id }, { command.Match2Id })."));
            }

            _tournamentRepository.Save();
            return(Result.Success());
        }
Ejemplo n.º 10
0
        public Result Handle(RemovePlayerFromTournament command)
        {
            Tournament tournament = _tournamentRepository.GetTournamentById(command.TournamentId);

            if (tournament == null)
            {
                return(Result.Failure($"Could not player ({ command.PlayerName}) from tournament ({ command.TournamentId }). Tournament not found."));
            }

            bool playerRemoved = _tournamentRepository.RemovePlayerReferenceFromTournament(tournament, command.PlayerName);

            if (!playerRemoved)
            {
                return(Result.Failure($"Could not player ({ command.PlayerName}) from tournament ({ command.TournamentId })."));
            }

            _tournamentRepository.Save();
            return(Result.Success());
        }
Ejemplo n.º 11
0
        public Result Handle(AddScoreToPlayerInMatch command)
        {
            Tournament tournament = _tournamentRepository.GetTournamentById(command.TournamentId);

            if (tournament == null)
            {
                return(Result.Failure($"Could add score ({ command.Score }) to player ({ command.PlayerId }) in match ({ command.MatchId }). Tournament ({ command.TournamentId }) not found."));
            }

            bool scoreAdded = _tournamentRepository.AddScoreToPlayerInMatch(tournament, command.MatchId, command.PlayerId, command.Score);

            if (!scoreAdded)
            {
                return(Result.Failure($"Could add score ({ command.Score }) to player ({ command.PlayerId }) in match ({ command.MatchId })."));
            }

            _tournamentRepository.Save();
            return(Result.Success());
        }
Ejemplo n.º 12
0
        public Result Handle(RemoveBetterFromTournament command)
        {
            Tournament tournament = _tournamentRepository.GetTournamentById(command.TournamentId);

            if (tournament == null)
            {
                return(Result.Failure($"Could not remove better ({ command.BetterId }) from tournament ({ command.TournamentId }). Tournament not found."));
            }

            bool betterRemoved = _tournamentRepository.RemoveBetterFromTournamentById(tournament, command.BetterId);

            if (!betterRemoved)
            {
                return(Result.Failure($"Could not remove better ({ command.BetterId }) from tournament ({ command.TournamentId })."));
            }

            _tournamentRepository.Save();
            return(Result.Success());
        }
Ejemplo n.º 13
0
        public Result Handle(AddPlayerToTournament command)
        {
            Tournament tournament = _tournamentRepository.GetTournamentById(command.TournamentId);

            if (tournament == null)
            {
                return(Result.Failure($"Could not add new player ({ command.PlayerName }) to tournament. Tournament ({ command.TournamentId }) not found."));
            }

            PlayerReference playerReference = _tournamentRepository.AddPlayerReference(tournament, command.PlayerName);

            if (playerReference == null)
            {
                return(Result.Failure($"Could not add new player ({ command.PlayerName }) to tournament."));
            }

            _tournamentRepository.Save();
            return(Result.Success());
        }
Ejemplo n.º 14
0
        public Result Handle(AddRoundToTournament command)
        {
            Tournament tournament = _tournamentRepository.GetTournamentById(command.TournamentId);

            if (tournament == null)
            {
                return(Result.Failure($"Could not add round ({ command.RoundType }) to tournament. Tournament ({ command.TournamentId }) not found."));
            }

            string    parsedRoundType = StringUtility.ToUpperNoSpaces(command.RoundType);
            RoundBase round;

            switch (parsedRoundType)
            {
            case "BRACKET":
                round = _tournamentRepository.AddBracketRoundToTournament(tournament);
                break;

            case "DUALTOURNAMENT":
                round = _tournamentRepository.AddDualTournamentRoundToTournament(tournament);
                break;

            case "ROUNDROBIN":
                round = _tournamentRepository.AddRoundRobinRoundToTournament(tournament);
                break;

            default:
                return(Result.Failure($"Could not add round ({ command.RoundType }) to tournament. Invalid round type ({ command.RoundType }) given."));
            }

            if (round == null)
            {
                return(Result.Failure($"Could not add round ({ command.RoundType }) to tournament."));
            }

            _tournamentRepository.Save();
            return(Result.Success());
        }