private void Apply(AccountCashWithdrawnEvent @event)
 {
     if (@event.WithdrawDate.Date == DateTime.UtcNow.Date)
     {
         _withdrawnToday += @event.Amount;
     }
     else
     {
         _withdrawnToday = 0;
     }
     Balance -= @event.Amount;
 }
        public string Debit(decimal amount, CorrelatedMessage source)
        {
            var msg = string.Empty;

            if (amount <= 0)
            {
                throw new ValidationException("Cannot withdraw a negative amount");
            }

            if (State.ToLower() == "blocked")
            {
                throw new ValidationException("Account is blocked");
            }

            if (DailyWireTransferLimit <= _withdrawnToday + amount)
            {
                var blocked = new AccountBlockedEvent(source)
                {
                    AccountId    = Id,
                    AccountState = "Blocked"
                };
                Raise(blocked);
                msg = $"Account is blocked, you only have {DailyWireTransferLimit - _withdrawnToday} left to withdraw today";
            }

            if (State.ToLower() == "active")
            {
                if (Balance - amount < 0 && Math.Abs(Balance - amount) > OverDraftLimit)
                {
                    var blocked = new AccountBlockedEvent(source)
                    {
                        AccountId    = Id,
                        AccountState = "Blocked"
                    };
                    Raise(blocked);
                    msg = $"Account is blocked, you exceeded your overdraft limit";
                }
                else
                {
                    var withdrawn = new AccountCashWithdrawnEvent(source)
                    {
                        AccountId    = Id,
                        Amount       = amount,
                        WithdrawDate = DateTime.UtcNow
                    };
                    Raise(withdrawn);
                }
            }

            return(msg);
        }
Beispiel #3
0
 public void Handle(AccountCashWithdrawnEvent message)
 {
     balance -= (decimal)message.Amount;
     Accounts.First(acct => acct.Id == message.AccountId.ToString()).Balance = balance;
     redraw();
 }