Esempio n. 1
0
        private void Handle(RollbackTransaction cmd)
        {
            var sender = Sender;

            if (cmd.AccountNumber != _state.AccountNumber)
            {
                throw new NotFoundException("Invalid Account Number");
            }

            if (_state.OutstandingTransaction.ContainsKey(cmd.TransactionId))
            {
                // command idempotent, just confirm that it is done
                // btw, this particular case is the one that should be validate if transaction even exists but before
                // command reaches aggregate. For such purpose we need to use command handlers as facade to domain
                Respond(sender, "Rolled Back");
                return;
            }

            var amount = _state.OutstandingTransaction[cmd.TransactionId];
            var commit = new AccountDebitRolledBack
            {
                TransactionId = cmd.TransactionId,
                AccountNumber = _state.AccountNumber,
                Reason        = cmd.Reason,
                Amount        = amount
            };

            Persist(commit, e =>
            {
                ApplyEvent(e);
                Respond(sender, "Commited", new[] { commit });
            });
        }
 internal static void OnRollbackTransaction(object sender, EventArgs e)
 {
     RollbackTransaction?.Invoke(sender, e);
 }