Exemplo 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());
        }