示例#1
0
        public void Transfer(IAccount fromAccount, IAccount toAccount, decimal amount, ApplicationDbContext _context)
        {
            if (fromAccount.AccountStatus)
            {
                if (fromAccount.AccountType == "Business")
                {
                    Transaction transactionfromAccount = CreateTransaction(fromAccount, toAccount, amount, "Transfer", _context);
                    Transaction transactiontoAccount   = CreateTransaction(fromAccount, toAccount, amount, "Received", _context);

                    _context.Add(transactionfromAccount);
                    _context.Add(transactiontoAccount);
                }
                else if (amount > 0 && fromAccount.Balance >= amount && fromAccount.AccountType != "Term Deposit")
                {
                    // aamount must greater than 0 to avoid unnecessary transaction
                    Transaction transactionfromAccount = CreateTransaction(fromAccount, toAccount, amount, "Transfer", _context);
                    Transaction transactiontoAccount   = CreateTransaction(fromAccount, toAccount, amount, "Received", _context);

                    _context.Add(transactionfromAccount);
                    _context.Add(transactiontoAccount);
                }

                if (fromAccount.AccountType == "Checking")
                {
                    CheckingAccount ca = new CheckingAccount();
                    ca.Transfer(fromAccount, toAccount, amount);
                }
                else if (fromAccount.AccountType == "Business")
                {
                    BusinessAccount ba = new BusinessAccount();
                    ba.Transfer(fromAccount, toAccount, amount);
                }
                else if (fromAccount.AccountType == "Loan")
                {
                    //can not transfer to loan
                }
                else if (fromAccount.AccountType == "Term Deposit")
                {
                    TermDeposit td = new TermDeposit();
                    td.Transfer(fromAccount, toAccount, amount);
                }



                _context.Update(fromAccount);
                _context.Update(toAccount);

                _context.SaveChanges();
            }//end if account is active
            else
            {
                //account is not active
            }
        }//end
示例#2
0
        public void Withdraw(IAccount account, decimal amount, ApplicationDbContext _context)
        {
            if (account.AccountStatus)
            {
                if (account.AccountType == "Checking")
                {
                    CheckingAccount ca = new CheckingAccount();
                    ca.Withdraw(account, amount);
                }
                else if (account.AccountType == "Business")
                {
                    BusinessAccount ba = new BusinessAccount();
                    ba.Withdraw(account, amount);
                }
                else if (account.AccountType == "Loan")
                {
                    // can not withdraw from loan
                }
                else if (account.AccountType == "Term Deposit")
                {
                    TermDeposit td = new TermDeposit(0);
                    td.Withdraw(account, amount);
                }

                if (amount > 0 && account.AccountType == "Business")
                {
                    Transaction transaction = CreateTransaction(account, account, amount, "Withdraw", _context);
                    _context.Add(transaction);
                }
                else if (amount > 0 && account.AccountType == "Term Deposit" && account.MaturityDateTime > DateTime.Now)
                {
                }

                else if (amount > 0 && (account.Balance - amount) > 0)
                {
                    //condition check to prevent negative amount transaction
                    Transaction transaction = CreateTransaction(account, account, amount, "Withdraw", _context);
                    _context.Add(transaction);
                }
                else if (amount > 0 && (account.MaturityDateTime <= DateTime.Now))
                {
                    Transaction transaction = CreateTransaction(account, account, amount, "Withdraw", _context);
                    _context.Add(transaction);
                }


                _context.Update(account);
                _context.SaveChanges();
            }//end if account is active
            else
            {
                //account is not active
            }
        }
示例#3
0
        public void openBusinessAccount(Customer customer, double amount)
        {
            BusinessAccount business = new BusinessAccount();

            business.AccountBalance = amount;
            business.Activated      = true;
            business.CustomerID     = customer.id;
            business.customer       = customer;
            business.InterestRate   = 2.0;
            business.AccountType    = "Business Account";
            AccountList.Add(business);
            customer.AccountList.Add(business);
        }
示例#4
0
        public void  Deposit(IAccount acc, decimal amount, ApplicationDbContext _context)
        {
            if (acc.AccountStatus)
            {
                if (acc.AccountType == "Checking")
                {
                    CheckingAccount ca = new CheckingAccount();
                    ca.Deposit(acc, amount);
                }
                else if (acc.AccountType == "Business")
                {
                    BusinessAccount ba = new BusinessAccount();
                    ba.Deposit(acc, amount);
                }
                else if (acc.AccountType == "Loan")
                {
                    //no deposit to loan account
                }
                else if (acc.AccountType == "Term Deposit")
                {
                    TermDeposit td = new TermDeposit();
                    td.Deposit(acc, amount);
                }

                if (amount > 0 && acc.AccountType != "Term Deposit")
                {
                    //condition check to prevent negative amount transaction
                    Transaction transaction = CreateTransaction(acc, acc, amount, "Deposit", _context);
                    _context.Add(transaction);
                }
                else if (acc.MaturityDateTime <= DateTime.Now)
                {
                    Transaction transaction = CreateTransaction(acc, acc, amount, "Deposit", _context);
                    _context.Add(transaction);
                }


                _context.Update(acc);
                _context.SaveChanges();
            }//end if account is active
            else
            {
                //account is inactive
            }
        }
示例#5
0
        }//end

        #endregion

        #region void PayLoan(int accountno, decimal amount)
        public void PayLoan(IAccount firstAccount, IAccount secondAccount, decimal amount, ApplicationDbContext _context)
        {
            if (secondAccount.AccountType == "Term Deposit")
            {
                TermDeposit td = new TermDeposit();
                td.PayLoan(firstAccount, secondAccount, amount);
            }
            else if (secondAccount.AccountType == "Business")
            {
                BusinessAccount ba = new BusinessAccount();
                ba.PayLoan(firstAccount, secondAccount, amount);
            }
            else if (secondAccount.AccountType == "Checking")
            {
                secondAccount.PayLoan(firstAccount, secondAccount, amount);
            }
            else if (secondAccount.AccountType == "Loan")
            {
                //loan can no pay loan
            }

            if (secondAccount.AccountType == "Business")
            {
                Transaction transaction     = CreateTransaction(firstAccount, secondAccount, amount, "PayLoan", _context);  //create transaction for loan account
                Transaction transactionfrom = CreateTransaction(secondAccount, firstAccount, amount, "Received", _context); //create transaction for from account

                _context.Add(transaction);
                _context.Add(transactionfrom);
            }

            else if (amount > 0 && (secondAccount.Balance - amount) >= 0)
            {
                Transaction transaction     = CreateTransaction(firstAccount, secondAccount, amount, "PayLoan", _context);  //create transaction for loan account
                Transaction transactionfrom = CreateTransaction(secondAccount, firstAccount, amount, "Received", _context); //create transaction for from account

                _context.Add(transaction);
                _context.Add(transactionfrom);
            }


            _context.Update(firstAccount);
            _context.Update(secondAccount);
            _context.SaveChanges();
        }
示例#6
0
        public static IAccount GetAccount(int accountno, ApplicationDbContext _context)
        {
            IAccount ca = new CheckingAccount();
            IAccount bc = new BusinessAccount();
            IAccount la = new Loan();
            IAccount td = new TermDeposit();


            Account acc = _context.Account.Find(accountno);

            if (acc.AccountType == "Checking")
            {
                ca = acc;
                return(ca);
            }
            else if (acc.AccountType == "Business")
            {
                bc = acc;
                return(bc);
            }
            else if (acc.AccountType == "Loan")
            {
                la = acc;
                return(la);
            }
            else if (acc.AccountType == "Term Deposit")
            {
                td = acc;
                return(td);
            }
            else
            {
                // failed!
            }
            return(ca);
        }