public Task HandleAsync(AllPlayerMovesSubmittedForTurnEvent @event, CancellationToken cancellationToken = default(CancellationToken))
 {
     _playersReadForBattle.Add(@event.Player);
     if (_playersReadForBattle.Count == PlayerInfo.PLAYER_COUNT)
     {
         _commandDelegator.SendAsync(new ProcessTurnCommand(@event.AggregateRootId));
     }
     return(Task.CompletedTask);
 }
Beispiel #2
0
        public Task HandleAsync(ShowLoginScreenEvent @event, CancellationToken cancellationToken = default(CancellationToken))
        {
            Console.Clear();

            Console.WriteLine("1. Input UserName");
            var userName = Console.ReadLine();

            Console.WriteLine("2. Input password");
            var password = Console.ReadLine();

            return(_commandDelegator.SendAsync(new LoginCommand(userName, password), cancellationToken));
        }
        public Task HandleAsync(ShowCreateAccountScreenEvent @event, CancellationToken cancellationToken = default(CancellationToken))
        {
            Console.Clear();
            Console.WriteLine("1. Input Email");
            var email = Console.ReadLine();

            Console.WriteLine("1. Input UserName");
            var userName = Console.ReadLine();

            Console.WriteLine("1. Input password");
            var password = Console.ReadLine();

            return(_commandDelegator.SendAsync(new CreateAccountCommand(userName, email, password)));
        }
        public Task HandleAsync(ShowRecordWithdrawScreenEvent @event, CancellationToken cancellationToken = default(CancellationToken))
        {
            Console.Clear();

            Console.WriteLine("Create a WITHDRAW transaction");
            Console.Write("PLEASE INPUT AMOUNT:");
            var amountString = Console.ReadLine();

            decimal.TryParse(amountString, out decimal amount);
            if (amount < 0)
            {
                throw new InputAmountInvalidException(amount);
            }

            return(_commandDelegator.SendAsync(new RecordWithdrawCommand(applicationContext.UserInfo.DebitAccountId, amount), cancellationToken));
        }
        public override async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            string productId = RequestInput("Enter product ID:", input =>
            {
                if (Guid.TryParse(input, out Guid i))
                {
                    return(InputValidationResult.Success);
                }

                return(InputValidationResult.WithErrors("Invalid product ID."));
            });

            await _commandDelegator.SendAsync(new DeactivateProductCommand(Guid.Parse(productId)));

            System.Console.WriteLine("Product deactivated.");
        }
Beispiel #6
0
        public override async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            string id = RequestInput("Enter product ID:", input =>
            {
                if (int.TryParse(input, out int i))
                {
                    return(InputValidationResult.Success);
                }

                return(InputValidationResult.WithErrors("Invalid product ID."));
            });

            string productName = RequestInput("Enter product name:");

            await _commandDelegator.SendAsync(new RegisterProductCommand(int.Parse(id), productName));

            System.Console.WriteLine($"{productName} registered.");
        }
Beispiel #7
0
        public async Task Run()
        {
            do
            {
                try
                {
                    await _eventDelegator.SendAsync(new ShowHomeScreenEvent());

                    var keyCode = Console.ReadKey();
                    if (int.TryParse(keyCode.KeyChar.ToString(), out int actionNumber))
                    {
                        var action = (ActionEnum)Convert.ToInt16(actionNumber);
                        switch (action)
                        {
                        case ActionEnum.CreateAccount:
                            await _eventDelegator.SendAsync(new ShowCreateAccountScreenEvent());

                            break;

                        case ActionEnum.Login:
                            await _eventDelegator.SendAsync(new ShowLoginScreenEvent());

                            break;

                        case ActionEnum.Logout:
                            var ApplicationContext = _serviceProvider.GetService(typeof(ApplicationContext)) as ApplicationContext;
                            await _commandDelegator.SendAsync(new LogoutCommand(ApplicationContext.UserInfo.AccessToken));

                            break;

                        case ActionEnum.CreateDeposit:
                            await _eventDelegator.SendAsync(new ShowRecordDepositScreenEvent());

                            break;

                        case ActionEnum.CreateWithDraw:
                            await _eventDelegator.SendAsync(new ShowRecordWithdrawScreenEvent());

                            break;

                        case ActionEnum.CheckBalance:
                            await _commandDelegator.SendAsync(new CheckBalanceCommand(_applicationContext.UserInfo.DebitAccountId));

                            break;

                        case ActionEnum.ListTransactions:
                            await _commandDelegator.SendAsync(new ListTransactionsCommand(_applicationContext.UserInfo.DebitAccountId));

                            break;

                        case ActionEnum.Close:
                            return;

                        default:
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogCritical(ex.Message);

                    Console.ReadKey();
                }
            }while (true);
        }