예제 #1
0
            public async Task <BankAccountGrainState> Close(BankAccountGrainState state)
            {
                var stateMachineData  = BankAccountData.NewBalance(Balance.ZeroBalance);
                var stateMachineState = BankAccountState.ClosedState;

                return(await Task.FromResult(new BankAccountGrainState(stateMachineData, stateMachineState)));
            }
예제 #2
0
            public async Task <BankAccountGrainState> Deposit(BankAccountGrainState state, Amount amount)
            {
                var newBalance = state.StateMachineData.Match(_ => _.Item.Deposit(amount));

                var stateMachineData  = BankAccountData.NewBalance(newBalance);
                var stateMachineState = BankAccountState.ActiveState;

                return(await Task.FromResult(new BankAccountGrainState(stateMachineData, stateMachineState)));
            }
            public Task <ActiveWithdrawResult> Withdraw(BankAccountGrainState state, Amount amount)
            {
                var newBalance = state.StateMachineData.Match(_ => _.Item.Withdraw(amount));

                var stateMachineData = BankAccountData.NewBalance(newBalance);

                var stateMachineState = newBalance.IsZeroBalance
                    ? ActiveWithdrawResultState.ZeroBalanceState
                    : (newBalance.IsOverdrawnBalance
                        ? ActiveWithdrawResultState.OverdrawnState
                        : ActiveWithdrawResultState.ActiveState);

                return(Task.FromResult(new ActiveWithdrawResult(stateMachineData, stateMachineState)));
            }