FindAcctByNumber() public static method

public static FindAcctByNumber ( string number ) : CheckingAccount
number string
return CheckingAccount
Esempio n. 1
0
        public Transfer MakeTransfer(String counterAccount, Money amount)
        {
            // 1. Check withdrawal limit:
            if (amount.GreaterThan(this.transferLimit))
            {
                throw new BusinessException("Limit exceeded!");
            }
            // 2. Assuming result is 9-digit bank account number, validate 11-test:
            int sum = 0;

            for (int i = 0; i < counterAccount.Length; i++)
            {
                sum = sum + (9 - i) * (int)Char.GetNumericValue(
                    counterAccount[i]);
            }
            if (sum % 11 == 0)
            {
                // 3. Look up counter account and make transfer object:
                CheckingAccount acct   = Accounts.FindAcctByNumber(counterAccount);
                Transfer        result = new Transfer(this, acct, amount);
                return(result);
            }
            else
            {
                throw new BusinessException("Invalid account number!");
            }
        }
        public Transfer makeTransfer(string counterAccount, Money amount)
        {
            // 1. Assuming result is 9-digit bank account number, validate 11-test:
            if (String.IsNullOrEmpty(counterAccount) || counterAccount.Length != 9)
            {
                throw new BusinessException("Invalid account number!");
            }
            int sum = 0;

            for (int i = 0; i < counterAccount.Length; i++)
            {
                sum = sum + (9 - i) * (int)Char.GetNumericValue(counterAccount[i]);
            }
            if (sum % 11 == 0)
            {
                // 2. Look up counter account and make transfer object:
                CheckingAccount acct   = Accounts.FindAcctByNumber(counterAccount);
                Transfer        result = new Transfer(this, acct, amount); // <2>
                // 3. Check whether withdrawal is to registered counter account:
                if (result.CounterAccount.Equals(this.RegisteredCounterAccount))
                {
                    return(result);
                }
                else
                {
                    throw new BusinessException("Counter-account not registered!");
                }
            }
            else
            {
                throw new BusinessException("Invalid account number!!");
            }
        }
        private Transfer TransferMoney(string counterAccount, Money amount)
        {
            // 2. Look up counter account and make transfer object:
            CheckingAccount acct   = Accounts.FindAcctByNumber(counterAccount);
            Transfer        result = new Transfer(this, acct, amount); // <2>

            // 3. Check whether withdrawal is to registered counter account:
            if (result.CounterAccount.Equals(this.RegisteredCounterAccount))
            {
                return(result);
            }
            else
            {
                throw new BusinessException("Counter-account not registered!");
            }
        }
        private Transfer MakeTransferWithAmountWithinLimit(string counterAccount, Money amount)
        {
            int sum = Accounts.CalculateSum(counterAccount);

            if (sum % 11 == 0)
            {
                // 3. Look up counter account and make transfer object:
                CheckingAccount acct   = Accounts.FindAcctByNumber(counterAccount);
                Transfer        result = new Transfer(this, acct, amount);
                return(result);
            }
            else
            {
                throw new BusinessException("Invalid account number!");
            }
        }
        public Transfer MakeTransfer(String counterAccount, Money amount)
        {
            // 1. Check withdrawal limit:
            AssertAmount(amount);
            AssertCounterAccount(counterAccount);

            // 2. Assuming result is 9-digit bank account number, validate 11-test:
            int sum = Do11Test(counterAccount);

            if (sum % 11 == 0)
            {
                // 3. Look up counter account and make transfer object:
                CheckingAccount acct   = Accounts.FindAcctByNumber(counterAccount);
                Transfer        result = new Transfer(this, acct, amount);
                return(result);
            }
            else
            {
                throw new BusinessException("Invalid account number!");
            }
        }