public void HandleEventInstance(MoneyWithdrawn eventInstance)
 {
     if (null != eventInstance)
     {
         currentBalance -= eventInstance.AmountWithdrawn;
     }
 }
예제 #2
0
        public async Task On(MoneyWithdrawn @event, long sequence)
        {
            var balance = await _repository.GetAsync(@event.Id);

            balance.Balance -= @event.Amount;
            await _repository.UpdateBalance(balance, sequence);

            _logger.LogInformation(
                $"Money withdrawn from bank account {_repository.BankAccount}. New Balance: {balance.Balance}");
        }
예제 #3
0
        public void WithdrawMoney_WithLimitNotExceeded_WithdrawsMoney()
        {
            var bankAccount           = new BankAccountBuilder(DefaultBankAccountId).WithCurrency(Currency.Euro).WithDepositedMoney(50).WithDepositedMoney(50).Build();
            var bankAccountRepository = ConfigureBankAccountRepositoryForAccount(bankAccount);
            var systemUnderTest       = new WithdrawMoneyHandler(bankAccountRepository);
            var command = new WithdrawMoney(DefaultBankAccountId, Transaction.Of(Guid.Parse("996228f4-70cb-4e44-9716-8a2a3b27d18c")), new Money(100, Currency.Euro), TimeStamp.Of(3));

            systemUnderTest.Handle(command, CancellationToken.None).GetAwaiter().GetResult();

            var moneyDeposited = new MoneyWithdrawn(DefaultBankAccountId.Value, command.Transaction.Value, command.Amount.Amount, command.TimeStamp.Value);

            bankAccountRepository.Received().SaveAsync(Arg.Is <BankAccount>(it => it.IsCorrectBankAccount(DefaultBankAccountId, 4, moneyDeposited)));
        }
예제 #4
0
        public void Withdraw(decimal amount)
        {
            if (amount > balance)
            {
                throw new InsufficientFundsException();
            }

            var @event = new MoneyWithdrawn(
                accountId: Id,
                amount: amount);

            Apply(@event);
            AddDomainEvent(@event);
        }
 public ClassificationResponse.ClassificationResults ClassifyEventInstance(MoneyWithdrawn eventInstance)
 {
     if (null != eventInstance)
     {
         currentBalance -= eventInstance.AmountWithdrawn;
     }
     if (currentBalance >= threshold)
     {
         // Balance is above threshold
         return(ClassificationResponse.ClassificationResults.Exclude);
     }
     else
     {
         return(ClassificationResponse.ClassificationResults.Include);
     }
 }
예제 #6
0
        public void Handle(MoneyWithdrawn e)
        {
            if (e.Transaction == Guid.Empty)
            {
                return;
            }

            var status = new UpdateTransfer(e.Transaction, "Debit Succeeded");

            _commander.Send(status);

            var transfer = (Transfer)_repository.Get <TransferAggregate>(e.Transaction).State;

            var deposit = new DepositMoney(transfer.ToAccount, e.Amount, e.Transaction);

            _commander.Send(deposit);
        }
예제 #7
0
        private void Handle(MoneyWithdrawn evt)
        {
            var ci = indexer.Get <ClientInformation>(evt.ClientID);

            ci.Balance     -= evt.Quantity;
            ci.LastMovement = evt.TimeStamp;

            indexer.Index(ci);

            var ad = indexer.Get <AmountDepositedInTheBank>(evt.TransactionId.ToString());

            if (ad == null)
            {
                indexer.Index(new AmountDepositedInTheBank {
                    Quantity = evt.Quantity, TimeStamp = evt.TimeStamp, ID = evt.ClientID, TransactionId = evt.TransactionId
                });
            }
        }
예제 #8
0
        public async Task Handle(WithdrawMoney withdrawMoney, IMessageHandlerContext context)
        {
            try
            {
                log.Info($"WithdrawMoneyHandler, TransactionId = {withdrawMoney.TransactionId}");
                var nHibernateSession = context.SynchronizedStorageSession.Session();
                var bankAccountId     = BankAccountId.FromExisting(withdrawMoney.FromBankAccountId);
                var fromBankAccount   = nHibernateSession.Get <BankAccount>(bankAccountId) ?? BankAccount.NonExisting();
                if (fromBankAccount.DoesNotExist())
                {
                    var fromBankAccountNotFound = new FromBankAccountNotFound(withdrawMoney.TransactionId);
                    await context.Publish(fromBankAccountNotFound);

                    return;
                }
                if (fromBankAccount.CanBeWithdrawed(withdrawMoney.Amount))
                {
                    fromBankAccount.Withdraw(withdrawMoney.Amount);
                    fromBankAccount.ChangeUpdatedAt();
                    nHibernateSession.Save(fromBankAccount);
                    var moneyWithdrawn = new MoneyWithdrawn
                                         (
                        withdrawMoney.TransactionId,
                        withdrawMoney.FromBankAccountId,
                        withdrawMoney.Amount,
                        fromBankAccount.Balance.Amount
                                         );
                    await context.Publish(moneyWithdrawn);

                    return;
                }
                var withdrawRejected = new WithdrawRejected
                                       (
                    withdrawMoney.TransactionId
                                       );
                await context.Publish(withdrawRejected);
            }
            catch (Exception ex)
            {
                log.Error(ex.Message + " ** " + ex.StackTrace);
            }
        }
예제 #9
0
 private void Apply(MoneyWithdrawn obj)
 {
     Balance -= obj.Quantity;
 }
예제 #10
0
 public void Handle(MoneyWithdrawn c)
 {
     _store.DecreaseAccountBalance(c.AggregateIdentifier, c.Amount);
 }
예제 #11
0
 private void When(MoneyWithdrawn e)
 {
     Balance -= e.Amount;
 }
예제 #12
0
 void IApply <MoneyWithdrawn> .Apply(MoneyWithdrawn @event)
 {
     balance -= @event.Amount;
 }
예제 #13
0
 private void When(MoneyWithdrawn @event)
 {
     balance -= @event.Amount;
 }
예제 #14
0
 /// <summary>
 /// Apply money withdrawn state changes.
 /// </summary>
 /// <param name="e">The money withdrawn event.</param>
 protected void Apply(MoneyWithdrawn e)
 {
     Balance = e.Balance;
 }
예제 #15
0
 public void Handle(MoneyWithdrawn e)
 {
 }