public async Task Handle(SourceAccountNotFoundEvent message, IMessageHandlerContext context) { log.Info($"SourceAccountNotFoundEvent, TransactionId = {message.TransactionId}"); var command = new RejectMoneyTransferCommand( Data.TransferId ); await context.SendLocal(command).ConfigureAwait(false); MarkAsComplete(); }
public async Task Handle(WithdrawMoneyCommand message, IMessageHandlerContext context) { log.Info($"WithdrawMoneyCommand, TransferId = {message.TransactionId}"); var nhibernateSession = context.SynchronizedStorageSession.Session(); var accountAggregate = nhibernateSession.Get <Account>(message.AccountId); if (accountAggregate == null) { var sourceAccountNotFoundEvent = new SourceAccountNotFoundEvent(message.TransactionId); await context.Publish(sourceAccountNotFoundEvent); } else { if (accountAggregate.CanWithdrawMoney(message.Amount)) { accountAggregate.WithdrawMoney(message.Amount); accountAggregate.ChangeUpdateAtUtc(); nhibernateSession.Save(accountAggregate); var moneyWithdrawnEvent = new MoneyWithdrawnEvent ( message.AccountId, message.TransactionId, message.Amount, accountAggregate.Balance.Amount, accountAggregate.Sobregiro_disponible.Amount ); await context.Publish(moneyWithdrawnEvent); } else { var withdrawMoneyRejectedEvent = new WithdrawMoneyRejectedEvent ( message.TransactionId ); await context.Publish(withdrawMoneyRejectedEvent); } } }
public async Task Handle(ReturnMoneyCommand message, IMessageHandlerContext context) { log.Info($"ReturnMoneyCommand, AccountId = {message.AccountId}"); var nhibernateSession = context.SynchronizedStorageSession.Session(); var accountAggregate = nhibernateSession.Get <Account>(message.AccountId); if (accountAggregate == null) { var sourceAccountNotFoundEvent = new SourceAccountNotFoundEvent(message.AccountId); await context.Publish(sourceAccountNotFoundEvent); } else { accountAggregate.ReturnMoney(message.Amount); nhibernateSession.Save(accountAggregate); var moneyReturnedEvent = new MoneyReturnedEvent ( message.AccountId, message.Amount ); await context.Publish(moneyReturnedEvent); } }