Beispiel #1
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 }));
            }