public void Handle(AmountWithdrawalEvent @event)
        {
            var account = this.accountDailyBalances.FirstOrDefault(o => o.AccountId == @event.AggregateId);

            if (account != null)
            {
                account.Date        = @event.DateOccured;
                account.AccountName = account.AccountName;

                var accBalance = account.Balance.SingleOrDefault(o => o.Currency == @event.Amount.Currency);
                if (accBalance != null)
                {
                    int idx = account.Balance.IndexOf(accBalance);
                    account.Balance[idx] = new Money(accBalance.Currency, (accBalance.Value - @event.Amount.Value));
                }
                else
                {
                    accBalance = new Money(@event.Amount.Currency, @event.Amount.Value);
                    account.Balance.Add(accBalance);
                }
            }
            else
            {
                throw new Exception(String.Format("Account does not exists with Id: {0}", @event.AggregateId));
            }
        }
Ejemplo n.º 2
0
        private void OnAmountWithdrawn(AmountWithdrawalEvent @event)
        {
            var amount = @event.Amount;
            int idx    = this.balance.FindIndex(b => b.Currency == amount.Currency);

            if (idx != -1)
            {
                this.balance[idx].Value -= amount.Value;
            }
            else
            {
                this.balance.Add(new Money(amount.Currency, amount.Value));
            }
        }
Ejemplo n.º 3
0
        public void Handle(AmountWithdrawalEvent @event)
        {
            var account = this.accountAuditCurrent.FirstOrDefault(o => o.AccountId == @event.AggregateId);

            if (account != null)
            {
                AccountAudit accAudit = new AccountAudit
                {
                    AccountId   = @event.AggregateId,
                    AccountName = account.AccountName,
                    Action      = "Amount Withdrawn",
                    Time        = @event.DateOccured
                };
                this.accountAuditCurrent.Add(accAudit);
            }
            else
            {
                throw new Exception(String.Format("No account found with Id: {0}", @event.AggregateId));
            }
        }