コード例 #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);
            }
コード例 #2
0
        public static Validation <(Event Event, AccountState NewState)> Freeze
            (this AccountState @this, FreezeAccount cmd)
        {
            if (@this.Status == AccountStatus.Frozen)
            {
                return(Errors.AccountNotActive);
            }

            var evt      = cmd.ToEvent();
            var newState = @this.Apply(evt);

            return(evt as Event, newState);
        }
コード例 #3
0
        // handle commands

        public static Validation <(Event Event, AccountState NewState)> Debit
            (this AccountState @this, MakeTransfer cmd)
        {
            if (@this.Status != AccountStatus.Active)
            {
                return(Errors.AccountNotActive);
            }

            if (@this.Balance - cmd.Amount < @this.AllowedOverdraft)
            {
                return(Errors.InsufficientBalance);
            }

            var evt      = cmd.ToEvent();
            var newState = @this.Apply(evt);

            return(evt as Event, newState);
        }