예제 #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 openTermDeposit(Customer customer, double amount)
        {
            TermDeposit term = new TermDeposit();

            term.MaturityDate   = generateDate();
            term.Amount         = amount;
            term.AccountType    = "Term Deposit";
            term.AccountBalance = amount;
            term.Activated      = true;
            term.CustomerID     = customer.id;
            term.customer       = customer;
            term.InterestRate   = 2.5;
            AccountList.Add(term);
            customer.AccountList.Add(term);
        }
예제 #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);
        }
예제 #7
0
        public Accounts CreateAccount(string acccounttype, Customer Cust)
        {
            switch (acccounttype)
            {
            case "1":
                var a = new Checking()
                {
                    AccountId    = Id,
                    Balance      = 0,
                    CustomerId   = Cust.CustomerId,
                    CreationDate = DateTime.Now
                };
                Cust.Account.Add(a.AccountId, a.AccountType);
                Checkingaccounts.Add(a);
                AllAccounts.Add(a.AccountId, a.AccountType);
                Id++;
                return(a);

            case "2":
                var b = new Business()
                {
                    AccountId    = Id,
                    Balance      = 0,
                    CustomerId   = Cust.CustomerId,
                    CreationDate = DateTime.Now
                };
                Id++;
                Cust.Account.Add(b.AccountId, b.AccountType);
                BusinessAccounts.Add(b);
                AllAccounts.Add(b.AccountId, b.AccountType);
                return(b);

            case "3":
                var c = new Loan()
                {
                    AccountId    = Id,
                    Balance      = 0,
                    CustomerId   = Cust.CustomerId,
                    CreationDate = DateTime.Now
                };
                Id++;
                LoanAccounts.Add(c);
                Cust.Account.Add(c.AccountId, c.AccountType);

                AllAccounts.Add(c.AccountId, c.AccountType);
                return(c);

            case "4":
                var d = new TermDeposit()
                {
                    AccountId    = Id,
                    Balance      = 0,
                    CustomerId   = Cust.CustomerId,
                    CreationDate = DateTime.Now
                };
                Id++;
                TermDepositAccounts.Add(d);
                Cust.Account.Add(d.AccountId, d.AccountType);
                AllAccounts.Add(d.AccountId, d.AccountType);
                return(d);

            default:
                Console.WriteLine("Invaild Value Entered");
                Console.WriteLine("Please enter a number from 1-4");
                var x = Console.ReadLine();
                CreateAccount(x, Cust);
                return(null);
            }
        }