Example #1
0
        /// <summary>
        /// Add a account for a customer
        /// </summary>
        /// <param name="customerNumber"></param>
        /// <param name="typeCode"></param>
        /// <returns></returns>
        public int AddAccount(int customerNumber, Account account)
        {
            using (CWS.SimpleBank.Data.Interview101Entities1 db = new Interview101Entities1())
            {
                var customer = db.Customers.Where(c => c.CustomerNumber == customerNumber).FirstOrDefault();
                if (customer == null)
                {
                    return(0);
                }

                if (account == null)
                {
                    account = new Account();
                }
                account.Balance  = 0M;
                account.TypeCode = "U";
                account.OpenDate = DateTime.Today;

                if (account.GetType() == typeof(LoanAccount))
                {
                    LoanAccount loan = account as LoanAccount;
                    loan.TypeCode     = "L";
                    account.Balance   = loan.OriginalLoanAmount;
                    loan.MaturityDate = DateTime.Today.AddMonths(loan.Term);
                    loan.APR          = 9.99M;

                    customer.Accounts.Add(loan);
                }
                else if (account.GetType() == typeof(CreditCardAccount))
                {
                    CreditCardAccount creditcard = account as CreditCardAccount;
                    creditcard.TypeCode       = "C";
                    creditcard.ExpirationDate = DateTime.Today.AddYears(5);
                    creditcard.PurchaseAPR    = 12.99M;
                    creditcard.CashAPR        = 16.99M;

                    customer.Accounts.Add(creditcard);
                }
                else if (account.GetType() == typeof(CertificateDeposit))
                {
                    CertificateDeposit deposit = account as CertificateDeposit;
                    deposit.TypeCode     = "D";
                    deposit.MaturityDate = DateTime.Today.AddMonths(deposit.Term);
                    deposit.Balance      = deposit.Principal;
                    deposit.APY          = 3.99M;

                    customer.Accounts.Add(deposit);
                }
                else
                {
                    customer.Accounts.Add(account);
                }

                db.SaveChanges();

                return(account.AccountNumber);
            }
        }
        public int AddDeposit(int customerNumber, int term, decimal amount)
        {
            BankService        service = new BankService();
            CertificateDeposit deposit = new CertificateDeposit
            {
                Term      = term,
                Principal = amount
            };

            return(service.AddAccount(customerNumber, deposit));
        }