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); }
public void Handle(AccountBlockedEvent message) { state = message.AccountState; Accounts.First(acct => acct.Id == message.AccountId.ToString()).State = state; redraw(); }
private void Apply(AccountBlockedEvent blockedEvent) { State = blockedEvent.AccountState; }
public Task HandleEventAsync(AccountBlockedEvent @event) { // TODO : Add event to event store Console.WriteLine($"Received message '{@event.Reason}'"); return(Task.CompletedTask); }
public void Apply(AccountBlockedEvent @event) { AccountState = Enumerations.AccountState.Blocked; }
public Task Handle(AccountBlockedEvent message, IMessageHandlerContext context) { throw new NotImplementedException(); }