Exemple #1
0
        //Method to execute the transfer transaction
        override public void Execute()
        {
            base.Execute();

            //throwing exception if already executed
            if (_executed)
            {
                throw new InvalidOperationException("The transfer transaction has been already attempted");
            }

            _executed = true;

            //withdrawing the amount from _fromAccount first
            _withdraw.Execute();

            //if amount is withdrawn successfully
            if (_withdraw.Success)
            {
                //Depositing the amount to _toAccount
                _deposit.Execute();

                //if deposit is not succesfull, then rollback the withdraw
                if (!_deposit.Success)
                {
                    _withdraw.Rollback();
                }
            }
        }