public void PayLoanInstallment(Account account, Account account2, MyClientDbContext _context, double amount)
        {
            double previous = account.AccountBalance;

            if (account.AccountType == "Loan" && account2.AccountType == "Checking")
            {
                double          prev = account2.AccountBalance;
                CheckingAccount ca   = new CheckingAccount();
                ca.WithDraw(account2, amount);
                if (prev > account2.AccountBalance)
                {
                    Loan loan = new Loan();
                    loan.payLoanInstallment(account, amount);
                }
            }
            else if (account.AccountType == "Loan" && account2.AccountType == "Business")
            {
                BusinessAccount ba = new BusinessAccount();
                ba.WithDraw(account2, amount);
                Loan loan = new Loan();
                loan.payLoanInstallment(account, amount);
            }

            createTransaction(account, previous, account.AccountBalance, amount, "PayLoan", _context);
            if (account.AccountBalance == 0)
            {
                account.Activated = false;
            }
            _context.Accounts.Update(account);
            _context.SaveChanges();
        }
 public void Transfer(Account account, Account account2, MyClientDbContext _context, double amount)
 {
     if (account.AccountNumber == account2.AccountNumber)
     {
         Console.WriteLine("Can't Transfer to the same account");
     }
     else
     {
         if (account.AccountType.Equals("Checking") && (account2.AccountType.Equals("Checking") || account2.AccountType.Equals("Business")))
         {
             account.WithDraw(account, amount);
             account2.Deposit(account2, amount);
         }
         else if (account.AccountType.Equals("Business") && (account2.AccountType.Equals("Business") || account2.AccountType.Equals("Checking")))
         {
             BusinessAccount ba = new BusinessAccount();
             ba.WithDraw(account, amount);
             account2.Deposit(account2, amount);
         }
     }
     transferTransaction(account, account2, account.AccountBalance, account2.AccountBalance, amount, "Transfer", _context);
     _context.Accounts.Update(account);
     _context.Accounts.Update(account2);
     _context.SaveChanges();
 }
        public void WithDraw(Account account, MyClientDbContext _context, double amount)
        {
            double previous = account.AccountBalance;

            if (account.AccountType == "Business")
            {
                BusinessAccount ba = new BusinessAccount();
                ba.WithDraw(account, amount);
            }
            else if (account.AccountType == "Checking")
            {
                CheckingAccount ca = new CheckingAccount();
                ca.WithDraw(account, amount);
            }
            else if (account.AccountType == "Loan")
            {
                Loan loan = new Loan();
                loan.WithDraw(account, amount);
            }
            else if (account.AccountType == "Term")
            {
                TermDeposit term = new TermDeposit();
                term.WithDraw(account, amount);
            }

            _context.Accounts.Update(account);
            _context.SaveChanges();
            createTransaction(account, previous, account.AccountBalance, amount, "WithDraw", _context);
        }
 public void RemoveAccount(Account account, MyClientDbContext _context)
 {
     if (account.AccountBalance == 0)
     {
         account.Activated = false;
         _context.Accounts.Update(account);
         _context.SaveChanges();
     }
     else if ((account.AccountBalance > 0 || account.AccountBalance < 0))
     {
         Console.WriteLine("You can't close the account because it doesn't have a balance of $0");
     }
 }
        public void transferTransaction(Account account, Account account2, double Account1Balance, double Account2Balance, double amount, string operation, MyClientDbContext _context)
        {
            Transaction transaction = new Transaction();
            Random      random      = new Random();

            transaction.AccountNumber      = account.AccountNumber;
            transaction.CustomerID         = account.CustomerID;
            transaction.AccountNumber2     = account2.AccountNumber;
            transaction.AccountNum1Balance = Account1Balance;
            transaction.AccountNum2Balance = Account2Balance;
            transaction.amount             = amount;
            transaction.Operation          = operation;
            transaction.dateMade           = DateTime.Now;
            _context.Transactions.Add(transaction);
            _context.SaveChanges();
        }
        public void createTransaction(Account account, double previous, double current, double amount, string operation, MyClientDbContext _context)
        {
            Random      random      = new Random();
            Transaction transaction = new Transaction();

            transaction.AccountNumber   = account.AccountNumber;
            transaction.CustomerID      = account.CustomerID;
            transaction.PreviousBalance = previous;
            transaction.CurrentBalance  = current;
            transaction.amount          = amount;
            transaction.Operation       = operation;
            transaction.dateMade        = DateTime.Now;

            _context.Transactions.Add(transaction);
            _context.SaveChanges();
        }
        public void Deposit(Account account, MyClientDbContext _context, double amount)
        {
            double previous = account.AccountBalance;

            if (account.AccountType == "Checking")
            {
                CheckingAccount checking = new CheckingAccount();
                checking.Deposit(account, amount);
            }
            else if (account.AccountType == "Business")
            {
                BusinessAccount business = new BusinessAccount();
                business.Deposit(account, amount);
            }
            _context.Accounts.Update(account);

            _context.SaveChanges();
            createTransaction(account, previous, account.AccountBalance, amount, "Deposit", _context);
        }
        public void OpenAccount(Account account, MyClientDbContext _context)
        {
            _context.Accounts.Add(account);

            _context.SaveChanges();
        }