示例#1
0
        public void TransferAmount()
        {
            User fromUser = this.bankUsers[this.fromUser];
            User toUser   = this.bankUsers[this.toUser];

            IAccountEntity toAccount   = toUser.CheckStatus(this.toAccountType) as IAccountEntity;
            IAccountEntity fromAccount = fromUser.CheckStatus(this.fromAccountType) as IAccountEntity;

            toAccount.SetCurrentAmount(toAccount.GetCurrentAmount() + this.transferAmount);
            fromAccount.SetCurrentAmount(fromAccount.GetCurrentAmount() - this.transferAmount);

            // create operations on both accounts for transfer.//
            OperationBuilder operationBuilder = new OperationBuilder()
                                                .SetType("TransferOperation")
                                                .SetAmount(this.transferAmount)
                                                .SetPayee(this.toUser);

            fromAccount.PushOperation(operationBuilder.Build());

            operationBuilder = new OperationBuilder()
                               .SetType("DepositOperation")
                               .SetAmount(this.transferAmount)
                               .SetPayee(this.fromUser);
            toAccount.PushOperation(operationBuilder.Build());
        }