Beispiel #1
0
            // handle commands

            public static (Event Event, AccountState NewState) Debit
                (this AccountState @this, MakeTransfer transfer)
            {
                var evt      = transfer.ToEvent();
                var newState = @this.Apply(evt);

                return(evt, newState);
            }
Beispiel #2
0
            public static AccountState Apply(this AccountState @this, Event evt)
            => new Pattern <AccountState>
            {
                (DepositedCash e) => @this.Credit(e.Amount),
                (DebitedTransfer e) => @this.Debit(e.DebitedAmount),
                (FrozeAccount e) => @this.WithStatus(AccountStatus.Frozen),
            }

            .Match(evt);
            public IActionResult MakeTransfer([FromBody] MakeTransfer cmd)
            {
                AccountState account = getAccount(cmd.DebitedAccountId);

                // performs the transfer
                (Event evt, AccountState newState) = account.Debit(cmd);

                saveAndPublish(evt);

                // returns information to the user about the new state
                return(Ok(new { Balance = newState.Balance }));
            }