コード例 #1
0
        /// <summary>
        /// Method to Create an Account with the Bank
        /// </summary>
        /// <param name="EmailID"> Email Address of the User</param>
        /// <param name="Accounttype">What type of Account User wants to create at the Bank</param>
        /// <param name="InitialDeposit">The Amount Customer wishes to Deposit with the Bank</param>
        /// <returns>returns the newly created account to the user</returns>

        /*The return type of CreateAccount method
         * is the class Account type  as the account will be created
         * with the bank*/
        //since Virtual Bank is a static class CreateAccount method is also static
        //defaulting parameter to checking account in the code below

        /*As a general rule of thumb all required parameters should be
         * mentioned first and then optional parameters in the method  */
        public static Account CreateAccount(string EmailID,
                                            TypeofAccount Accounttype = TypeofAccount.Checking, decimal InitialDeposit = 0)
        {
            var account = new Account
            {
                EmailAddress = EmailID,
                AccountType  = Accounttype
            };

            /*since balance cannot be set by the customer and it has to be set via Bank
             * we mention a condition that if initial amount deposited is more than zero bank deposits in
             * the respective Bank account created for the customer*/

            if (InitialDeposit > 0)
            {
                account.Deposit(InitialDeposit);
            }
            return(account);
        }
コード例 #2
0
        /// <summary>
        /// create account with the bank
        /// </summary>
        /// <param name="emailId">Email Address of the account</param>
        /// <param name="accountType">Type of account</param>
        /// <param name="initialamount">Initial deposit</param>
        /// <returns>newly created account</returns>
        /// <exception cref="ArgumentNullException"/>
        public static Account CreateAccount(string emailId, TypeofAccount accounttype = TypeofAccount.checking, decimal initialamount = 0)
        {
            if (String.IsNullOrEmpty(emailId))
            {
                throw new ArgumentNullException(nameof(emailId), "Email address is required");
            }
            if (!IsValidEmail(emailId))
            {
                throw new FormatException("Email address is invalid");
            }
            var account = new Account
            {
                EmailAddress = emailId,
                AccountType  = accounttype
            };

            if (initialamount > 0)
            {
                account.Deposit(initialamount);
            }
            accounts.Add(account);
            return(account);
        }