예제 #1
0
        public async Task Handle(DepositMoney depositMoney, IMessageHandlerContext context)
        {
            try
            {
                log.Info($"DepositMoneyHandler, TransactionId = {depositMoney.TransactionId}");
                var nHibernateSession = context.SynchronizedStorageSession.Session();
                var bankAccountId     = BankAccountId.FromExisting(depositMoney.ToBankAccountId);
                var toBankAccount     = nHibernateSession.Get <BankAccount>(bankAccountId) ?? BankAccount.NonExisting();
                if (toBankAccount.DoesNotExist())
                {
                    var toBankAccountNotFound = new ToBankAccountNotFound(depositMoney.TransactionId);
                    await context.Publish(toBankAccountNotFound);

                    return;
                }
                toBankAccount.Deposit(depositMoney.Amount);
                toBankAccount.ChangeUpdatedAt();
                nHibernateSession.Save(toBankAccount);
                var moneyDeposited = new MoneyDeposited
                                     (
                    depositMoney.TransactionId,
                    toBankAccount.BankAccountId.Id,
                    depositMoney.Amount,
                    toBankAccount.Balance.Amount
                                     );
                await context.Publish(moneyDeposited);
            }
            catch (Exception ex)
            {
                log.Error(ex.Message + " ** " + ex.StackTrace);
            }
        }
예제 #2
0
        public async Task On(MoneyDeposited @event, long sequence)
        {
            var balance = await _repository.GetAsync(@event.Id);

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

            _logger.LogInformation(
                $"Money deposited from bank account {_repository.BankAccount}. New Balance: {balance.Balance}");
        }
예제 #3
0
        public void Deposit(decimal amount)
        {
            if (amount <= 0)
            {
                throw new IncorrectDepositAmountException();
            }

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

            Apply(@event);
            AddDomainEvent(@event);
        }
예제 #4
0
        public void Handle(MoneyDeposited e)
        {
            if (e.Transaction == Guid.Empty)
            {
                return;
            }

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

            _commander.Send(status);

            var complete = new CompleteTransfer(e.Transaction);

            _commander.Send(complete);
        }
예제 #5
0
        private void Handle(MoneyDeposited 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
                });
            }
        }
예제 #6
0
 private void Apply(MoneyDeposited obj)
 {
     Balance += obj.Quantity;
 }
예제 #7
0
 public void Handle(MoneyDeposited c)
 {
     _store.IncreaseAccountBalance(c.AggregateIdentifier, c.Amount);
 }
예제 #8
0
 void IApply <MoneyDeposited> .Apply(MoneyDeposited @event)
 {
     balance += @event.Amount;
 }
예제 #9
0
 private void When(MoneyDeposited @event)
 {
     balance += @event.Amount;
 }
예제 #10
0
 /// <summary>
 /// Apply money deposited state changes.
 /// </summary>
 /// <param name="e">The money deposited event.</param>
 protected void Apply(MoneyDeposited e)
 {
     Balance = e.Balance;
 }
예제 #11
0
 protected void Apply(MoneyDeposited moneyDeposited)
 {
     Balance += moneyDeposited.Amount;
 }
예제 #12
0
 public void Handle(MoneyDeposited e)
 {
 }