コード例 #1
0
        public void Can_create_WithdrawAmount_Command()
        {
            var id       = Guid.NewGuid();
            var funds    = 300;
            var @command = new WithdrawAmount(id, funds);

            Assert.NotNull(@command);
            Assert.Equal(id, @command.AccountId);
            Assert.Equal(funds, @command.Funds);
        }
コード例 #2
0
        public CommandResponse Handle(WithdrawAmount command)
        {
            if (!_repository.TryGetById <AccountAggregate.BankAccount>(command.AccountId, out var account))
            {
                throw new InvalidOperationException("No account with such ID");
            }
            account.WithdrawCash(command.Funds, new WithdrawnAmount(command.AccountId, command.Funds));
            _repository.Save(account);

            return(command.Succeed());
        }
コード例 #3
0
 internal static AmountWithdrawn ToEvent(this WithdrawAmount command, BankAccount bankAccount)
 {
     return(new AmountWithdrawn
     {
         BankTransactionId = Guid.NewGuid().ToString(),
         Entity = bankAccount,
         Amount = command.Amount,
         BankAccountId = command.BankAccountId,
         Reciever = command.Reciever,
         Timestamp = DateTime.Now
     });
 }
コード例 #4
0
        public async Task <HttpResponseMessage> PutWithdraw([FromUri] string id, [FromUri] decimal amount, [FromUri] string reciever)
        {
            var command = new WithdrawAmount
            {
                BankAccountId = id,
                Amount        = amount,
                Reciever      = reciever
            };
            await mediator.Send(command);

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
コード例 #5
0
        public async Task Handle(WithdrawAmount message, CancellationToken cancellationToken)
        {
            Id = message.BankAccountId;
            LoadPreviousEvents();

            withdrawAmountValidator.ValidateAndThrow(new ValidatonContext <WithdrawAmount, BankAccount>(message, this));

            var @event = message.ToEvent(this);

            Apply(@event);

            await eventRepository.Save(@event);
        }
コード例 #6
0
        private async void WithdrawCashImplementation(object o)
        {
            LoaderManager.Instance.ShowLoader();
            var result = await Task.Run(() =>
            {
                bool res = false;
                try
                {
                    res = ClientManager.Instance.WithdrawFromAccount(SelectedAccount.Id, Convert.ToDecimal(WithdrawAmount.Trim()));
                }
                catch (Exception e)
                {
                    MessageBox.Show($"Operation failed.\nReason:{Environment.NewLine}{e.Message}");
                    return(false);
                }
                return(true);
            });

            LoaderManager.Instance.HideLoader();
            if (result)
            {
                MessageBox.Show("Transaction has been done successfully!");
            }

            WithdrawAmount = "0";
            NavigationManager.Instance.Navigate(ViewType.Actions);
        }