Exemplo n.º 1
0
        private static async Task Main(string[] args)
        {
            var container            = ConfigureIoc();
            var mediator             = container.GetInstance <IMediator>();
            var projectionConnection = await MakeNewEventStoreConnection().ConfigureAwait(false);

            var availableAccountsProjection = new AvailableAccountsProjection();

            using var projectionsDispatcher = new ProjectionsDispatcher(projectionConnection,
                                                                        new PositionStoreNullObject(),
                                                                        new IProjection[] { availableAccountsProjection },
                                                                        LoggerNullObject.Instance);
            projectionsDispatcher.Start();
            while (true)
            {
                try
                {
                    System.Console.Clear();
                    System.Console.WriteLine("(c) - Create new bank account");
                    System.Console.WriteLine("(d) - deposit money");
                    System.Console.WriteLine("(w) - withdraw money");
                    var consoleKeyInfo = System.Console.ReadKey();
                    switch (consoleKeyInfo.Key)
                    {
                    case ConsoleKey.C:
                        await CreateAccountAsync(mediator).ConfigureAwait(false);

                        break;

                    case ConsoleKey.D:
                        await Deposit(mediator, availableAccountsProjection);

                        break;

                    case ConsoleKey.W:
                        await Withdraw(mediator, availableAccountsProjection);

                        break;
                    }
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine(ex.Message);
                    System.Console.WriteLine("Press any key to continue");
                    System.Console.ReadKey();
                }
            }
        }
Exemplo n.º 2
0
        private static Task Deposit(IMediator mediator, AvailableAccountsProjection availableAccountsProjection)
        {
            System.Console.Clear();
            System.Console.Write("IBAN: ");
            var iban = Iban.Of(System.Console.ReadLine());

            System.Console.Write("Amount: ");
            var amount        = decimal.Parse(System.Console.ReadLine());
            var bankAccountId = OId.Of <CoreDomain.BankAccount, Guid>(availableAccountsProjection.GetId(iban));
            var depositMoney  = new DepositMoney(bankAccountId,
                                                 Transaction.Of(Guid.NewGuid()),
                                                 new Money(amount, Currency.Euro),
                                                 TimeStamp.Of(DateTimeOffset.Now.ToUnixTimeSeconds()));

            return(mediator.Send(depositMoney));
        }