public String Withdraw(int accountID, double amount)
 {
     try
     {
         BusinessCheckingAccount ba = AccountDAL.accountList.Find(account => account.AccountID == accountID) as BusinessCheckingAccount;
         if (ba.Credit > 0)
         {
             double setAmount = ba.Credit - amount;
             if (setAmount < 0)
             {
                 return(new BusinessCheckingDAL().Withdraw(ba, amount, setAmount)); // return negative value for debit
             }
             else
             {
                 return(new BusinessCheckingDAL().Withdraw(ba, amount, setAmount)); // return positive value for credit
             }
         }
         else if (ba.Debit > 0)
         {
             double remainder = ba.Debit + amount;
             return(new BusinessCheckingDAL().Withdraw(ba, amount, -remainder));
         }
         else
         {
             return(new BusinessCheckingDAL().Withdraw(ba, amount, -amount));
         }
     }
     catch
     {
         throw;
     }
 }
 public String Deposit(int accountID, double amount)
 {
     try
     {
         BusinessCheckingAccount ba = AccountDAL.accountList.Find(account => account.AccountID == accountID) as BusinessCheckingAccount;
         if (ba.Credit > 0)
         {
             double setAmount = ba.Credit + amount;
             return(new BusinessCheckingDAL().Deposit(ba, amount, setAmount));
         }
         else if (ba.Debit > 0)
         {
             double remainder = ba.Debit - amount; // -4700 = 300 - 5000
             if (remainder <= 0)
             {
                 return(new BusinessCheckingDAL().Deposit(ba, amount, Math.Abs(remainder)));
             }
             else
             {
                 return(new BusinessCheckingDAL().Deposit(ba, amount, -remainder));
             }
         }
         else
         {
             return(new BusinessCheckingDAL().Deposit(ba, amount, amount));
         }
     }
     catch
     {
         throw;
     }
 }
Example #3
0
        public Dictionary <String, String> GetCustomerAccounts(int custID)
        {
            Dictionary <String, String> accountLists = new Dictionary <string, string>();
            List <Account> custAccList = GetAllCustomerAccounts(custID);

            Console.Clear();
            //Console.WriteLine("The following are your available accounts");

            foreach (Account acc in custAccList)
            {
                if (acc is PersonalCheckingAccount)
                {
                    PersonalCheckingAccount acc2 = acc as PersonalCheckingAccount;
                    accountLists.Add($"Type: Personal Checking  Credit: {acc2.Credit}  Debit: {acc2.Debit}  ID: {acc.AccountID}", "PersonalCheckingAccount");
                }
                else if (acc is BusinessCheckingAccount)
                {
                    BusinessCheckingAccount acc2 = acc as BusinessCheckingAccount;
                    accountLists.Add($"Type: Business Checking  Credit: {acc2.Credit}  Debit: {acc2.Debit}  ID: {acc.AccountID}", "BusinessCheckingAccount");
                }
                else if (acc is LoanAccount)
                {
                    LoanAccount acc2 = acc as LoanAccount;
                    accountLists.Add($"Type: Loan  Debit: {acc2.Debit}  Interest Rate: {acc2.interestRate} ID: {acc.AccountID}", "LoanAccount");
                }
                else if (acc is TermDepositAccount)
                {
                    TermDepositAccount acc2 = acc as TermDepositAccount;
                    accountLists.Add($"Type: Term Deposit  Credit: {acc2.Credit}  Term Length: {acc2.depositTerm} Interest Rate: {acc2.interestRate} ID: {acc.AccountID}", "TermDepositAccount");
                }
            }

            return(accountLists);
        }
Example #4
0
        public ActionResult DeleteConfirmed(int id)
        {
            BusinessCheckingAccount personalCheckingAccount = _db.BusinessAccounts.Find(id);

            _db.BusinessAccounts.Remove(personalCheckingAccount);
            _db.SaveChanges();
            return(RedirectToAction("Index", "Home", new { area = "" }));
        }
Example #5
0
        public ActionResult TransferTo(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            BusinessCheckingAccount personalCheckingAccount = _db.BusinessAccounts.Find(id);

            if (personalCheckingAccount == null)
            {
                return(NotFound());
            }
            return(View(personalCheckingAccount));
        }
Example #6
0
        public ActionResult Withdraw(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            BusinessCheckingAccount businessCheckingAccount = _db.BusinessAccounts.Find(id);

            if (businessCheckingAccount == null)
            {
                return(NotFound());
            }
            return(View(businessCheckingAccount));
        }
Example #7
0
        public Account Create(Customer cust)
        {
            BusinessCheckingAccount newAccount = new BusinessCheckingAccount()
            {
                AccountID    = AccountDAL.accountList.Count + 1000,
                customerID   = cust.ID,
                Credit       = 0,
                Debit        = 0,
                interestRate = 4.5
            };

            AccountDAL.accountList.Add(newAccount);
            return(newAccount);
        }
Example #8
0
 public String Withdraw(BusinessCheckingAccount ba, double amount, double balance)
 {
     if (balance >= 0) // If credit is still posible after withdrawl
     {
         ba.Debit  = 0;
         ba.Credit = balance;
         ba.transactionLog.Add("Withdrawal of " + amount);
         return($"Your new balance for account {ba.AccountID} is ${ba.Credit}");
     }
     else
     {
         ba.Credit = 0;
         ba.Debit  = Math.Abs(balance);
         ba.transactionLog.Add("Withdrawal of " + amount);
         return($"Your new balance for account {ba.AccountID} is -${ba.Debit}");
     }
 }
Example #9
0
 public String Deposit(BusinessCheckingAccount ba, double amount, double balance)
 {
     try
     {
         if (balance >= 0)
         {
             ba.Debit  = 0;
             ba.Credit = balance;
             ba.transactionLog.Add("Deposit of " + amount);
             return($"Your new balance for account {ba.AccountID} is ${ba.Credit}");
         }
         else
         {
             ba.Credit = 0;
             ba.Debit  = -balance;
             ba.transactionLog.Add("Deposit of " + amount);
             return($"Your new balance for account {ba.AccountID} is -${ba.Debit}");
         }
     }
     catch
     {
         throw;
     }
 }
Example #10
0
        public ActionResult Transfer(string AccountID, string CreditFrom, string TransferValue, string FromAccID, string accountToType)
        {
            System.Diagnostics.Debug.WriteLine(FromAccID);
            System.Diagnostics.Debug.WriteLine(CreditFrom);
            System.Diagnostics.Debug.WriteLine(TransferValue);
            System.Diagnostics.Debug.WriteLine(AccountID);
            System.Diagnostics.Debug.WriteLine(accountToType);
            try
            {
                int    accidFrom = int.Parse(FromAccID);
                int    accidTo   = int.Parse(AccountID);
                double balance   = double.Parse(CreditFrom) - double.Parse(TransferValue);


                if (balance >= 0)
                {
                    PersonalCheckingAccount personalCheckingAccount = _db.CheckingAccounts.Find(accidFrom) as PersonalCheckingAccount;
                    personalCheckingAccount.Credit = balance;
                    Transaction ta = new Transaction()
                    {
                        id                 = 0,
                        accountID          = int.Parse(AccountID),
                        transactionMessage = "Withdrawal of " + TransferValue
                    };
                    _db.Transactions.Add(ta);
                    _db.Entry(personalCheckingAccount).State = EntityState.Modified;

                    if (accountToType == "PersonalChecking")
                    {
                        PersonalCheckingAccount pa = _db.CheckingAccounts.Find(accidTo) as PersonalCheckingAccount;
                        pa.Credit = pa.Credit + double.Parse(TransferValue);
                        Transaction ta2 = new Transaction()
                        {
                            id                 = 0,
                            accountID          = int.Parse(AccountID),
                            transactionMessage = "Deposit of " + TransferValue
                        };
                        _db.Transactions.Add(ta2);
                        _db.Entry(pa).State = EntityState.Modified;
                        _db.SaveChanges();
                        ViewBag.Confirm = $"Your transfer of {TransferValue} was completed from account {FromAccID} to account {AccountID}";
                        return(View("Confirmed"));
                    }
                    else if (accountToType == "BusinessChecking")
                    {
                        BusinessCheckingAccount ba = _db.BusinessAccounts.Find(accidTo) as BusinessCheckingAccount;
                        double doubleCredit        = ba.Credit;
                        double doubleDeposit       = double.Parse(TransferValue);
                        double doubleDebit         = ba.Debit;
                        int    accID = int.Parse(AccountID);


                        if (doubleCredit > 0)
                        {
                            double setAmount = doubleCredit + doubleDeposit;
                            ba.Debit  = 0;
                            ba.Credit = setAmount;
                            Transaction ta2 = new Transaction()
                            {
                                id                 = 0,
                                accountID          = int.Parse(AccountID),
                                transactionMessage = "Deposit of " + TransferValue
                            };
                            _db.Transactions.Add(ta2);
                            _db.Entry(ba).State = EntityState.Modified;
                            _db.SaveChanges();
                            ViewBag.Confirm = $"Your transfer of {TransferValue} was completed from account {FromAccID} to account {AccountID}";
                            return(View("Confirmed"));
                        }
                        else if (doubleDebit > 0)
                        {
                            double remainder = -doubleDebit + doubleDeposit; // 200(balance = -300(debit + 500(deposit
                            if (remainder <= 0)
                            {
                                // when balance stays in debit after deposit
                                ba.Credit = 0;
                                ba.Debit  = -remainder;
                                Transaction ta2 = new Transaction()
                                {
                                    id                 = 0,
                                    accountID          = int.Parse(AccountID),
                                    transactionMessage = "Deposit of " + TransferValue
                                };
                                _db.Transactions.Add(ta2);
                                _db.Entry(ba).State = EntityState.Modified;
                                _db.SaveChanges();
                                ViewBag.Confirm = $"Your transfer of {TransferValue} was completed from account {FromAccID} to account {AccountID}";
                                return(View("Confirmed"));
                            }
                            else
                            {
                                // when balance goes from debit to credit
                                ba.Credit = remainder;
                                ba.Debit  = 0;
                                Transaction ta2 = new Transaction()
                                {
                                    id                 = 0,
                                    accountID          = int.Parse(AccountID),
                                    transactionMessage = "Deposit of " + TransferValue
                                };
                                _db.Transactions.Add(ta2);
                                _db.Entry(ba).State = EntityState.Modified;
                                _db.SaveChanges();
                                ViewBag.Confirm = $"Your transfer of {TransferValue} was completed from account {FromAccID} to account {AccountID}";
                                return(View("Confirmed"));
                            }
                        }
                        else
                        {
                            // Depositing when credit and debit = 0;
                            //return new BusinessCheckingDAL().Deposit(int.Parse(accountID), doubleDeposit, doubleDeposit, userID);
                            ba.Credit = doubleDeposit;
                            ba.Debit  = 0;
                            Transaction ta2 = new Transaction()
                            {
                                id                 = 0,
                                accountID          = int.Parse(AccountID),
                                transactionMessage = "Deposit of " + TransferValue
                            };
                            _db.Transactions.Add(ta2);
                            _db.Entry(ba).State = EntityState.Modified;
                            _db.SaveChanges();
                            ViewBag.Confirm = $"Your transfer of {TransferValue} was completed from account {FromAccID} to account {AccountID}";
                            return(View("Confirmed"));
                        }
                        return(View("Confirmed"));
                    }
                    else if (accountToType == "Loan")
                    {
                        return(View("Confirmed"));
                    }
                }
                else
                {
                    ViewBag.Confirm = $"Your account balance cannot be overdrafted. Transaction canceled.";
                    return(View("Confirmed"));
                }
                return(View("Confirmed"));
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                return(RedirectToAction("Index"));
            }
        }
Example #11
0
        public ActionResult Withdraw(string accountID, string Credit, string Debit, string withdrawvalue)
        {
            try
            {
                //var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
                int accID = int.Parse(accountID);


                double doubleCredit   = double.Parse(Credit);
                double doubleWithdraw = double.Parse(withdrawvalue);
                double doubleDebit    = double.Parse(Debit);
                double setAmount      = doubleCredit - doubleWithdraw;

                BusinessCheckingAccount ba = _db.BusinessAccounts.Find(accID) as BusinessCheckingAccount;
                if (doubleCredit > 0 && setAmount <= 0)
                {
                    ba.Credit = 0;
                    ba.Debit  = Math.Abs(setAmount);

                    Transaction ta = new Transaction()
                    {
                        id                 = 0,
                        accountID          = int.Parse(accountID),
                        transactionMessage = "Withdrawal of " + withdrawvalue
                    };
                    _db.Transactions.Add(ta);
                    _db.Entry(ba).State = EntityState.Modified;
                    _db.SaveChanges();
                    //return ba;
                }
                else if (doubleCredit > 0 && setAmount > 0)
                {
                    ba.Credit = setAmount;
                    ba.Debit  = 0;

                    Transaction ta = new Transaction()
                    {
                        id                 = 0,
                        accountID          = int.Parse(accountID),
                        transactionMessage = "Withdrawal of " + withdrawvalue
                    };
                    _db.Transactions.Add(ta);
                    _db.Entry(ba).State = EntityState.Modified;
                    _db.SaveChanges();
                    //return ba;
                }
                else if (doubleDebit > 0)
                {
                    double remainder = doubleDebit + doubleWithdraw;
                    ba.Credit = 0;
                    ba.Debit  = Math.Abs(remainder);

                    Transaction ta = new Transaction()
                    {
                        id                 = 0,
                        accountID          = int.Parse(accountID),
                        transactionMessage = "Withdrawal of " + withdrawvalue
                    };
                    _db.Transactions.Add(ta);
                    _db.SaveChanges();
                    //return ba;
                }
                else
                {
                    ba.Debit  = doubleWithdraw;
                    ba.Credit = 0;
                    Transaction ta = new Transaction()
                    {
                        id                 = 0,
                        accountID          = int.Parse(accountID),
                        transactionMessage = "Withdrawal of " + withdrawvalue
                    };
                    _db.Transactions.Add(ta);
                    _db.Entry(ba).State = EntityState.Modified;
                    _db.SaveChanges();
                    //return ba;
                }
                ViewBag.Confirm = $"Your withdrawal of {withdrawvalue} was completed from account {accountID}";
                return(View("Confirmed"));
            }
            catch
            {
                return(RedirectToAction("Index"));
            }
        }
Example #12
0
        public ActionResult Transfer(string AccountID, string CreditFrom, string TransferValue, string FromAccID, string accountToType)
        {
            try
            {
                //var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
                int accID = int.Parse(FromAccID);
                BusinessCheckingAccount ba = _db.BusinessAccounts.Find(accID) as BusinessCheckingAccount;

                double doubleCredit   = ba.Credit;
                double doubleWithdraw = double.Parse(TransferValue);
                double doubleDebit    = ba.Debit;
                double setAmount      = doubleCredit - doubleWithdraw;

                if (doubleCredit > 0 && setAmount <= 0)
                {
                    ba.Credit = 0;
                    ba.Debit  = Math.Abs(setAmount);

                    Transaction ta = new Transaction()
                    {
                        id                 = 0,
                        accountID          = int.Parse(FromAccID),
                        transactionMessage = "Withdrawal of " + TransferValue
                    };
                    _db.Transactions.Add(ta);
                    _db.Entry(ba).State = EntityState.Modified;
                    //_db.SaveChanges();
                    //return ba;
                }
                else if (doubleDebit > 0)
                {
                    double remainder = doubleDebit + doubleWithdraw;
                    ba.Credit = 0;
                    ba.Debit  = Math.Abs(remainder);

                    Transaction ta = new Transaction()
                    {
                        id                 = 0,
                        accountID          = int.Parse(FromAccID),
                        transactionMessage = "Withdrawal of " + TransferValue
                    };
                    _db.Transactions.Add(ta);
                    //_db.SaveChanges();
                    //return ba;
                }
                else
                {
                    ba.Debit  = doubleWithdraw;
                    ba.Credit = 0;
                    Transaction ta = new Transaction()
                    {
                        id                 = 0,
                        accountID          = int.Parse(FromAccID),
                        transactionMessage = "Withdrawal of " + TransferValue
                    };
                    _db.Transactions.Add(ta);
                    _db.Entry(ba).State = EntityState.Modified;
                    //_db.SaveChanges();
                    //return ba;
                }
                //ViewBag.Confirm = $"Your withdrawal of {TransferValue} was completed from account {TransferValue}";
                //return View("Confirmed");

                if (accountToType == "PersonalChecking")
                {
                    int accid = int.Parse(AccountID);
                    PersonalCheckingAccount personalCheckingAccount = _db.CheckingAccounts.Find(accid) as PersonalCheckingAccount;
                    double balance = personalCheckingAccount.Credit + double.Parse(TransferValue);

                    personalCheckingAccount.Credit = balance;
                    Transaction ta = new Transaction()
                    {
                        id                 = 0,
                        accountID          = int.Parse(AccountID),
                        transactionMessage = "Deposit of " + TransferValue
                    };
                    _db.Transactions.Add(ta);
                    _db.Entry(personalCheckingAccount).State = EntityState.Modified;
                    _db.SaveChanges();
                    ViewBag.Confirm = $"Your transfer of {TransferValue} was completed from account {FromAccID} to account {AccountID}";
                    return(View("Confirmed"));
                }
                else if (accountToType == "BusinessChecking")
                {
                    accID = int.Parse(AccountID);
                    ba    = _db.BusinessAccounts.Find(accID) as BusinessCheckingAccount;

                    doubleCredit = ba.Credit;
                    double doubleDeposit = double.Parse(TransferValue);
                    doubleDebit = ba.Debit;
                    //double setAmount = doubleCredit - doubleDeposit;


                    if (doubleCredit > 0)
                    {
                        setAmount = doubleCredit + doubleDeposit;
                        ba.Debit  = 0;
                        ba.Credit = setAmount;
                        Transaction ta = new Transaction()
                        {
                            id                 = 0,
                            accountID          = int.Parse(AccountID),
                            transactionMessage = "Deposit of " + TransferValue
                        };
                        _db.Transactions.Add(ta);
                        _db.Entry(ba).State = EntityState.Modified;
                        _db.SaveChanges();
                        ViewBag.Confirm = $"Your transfer of {TransferValue} was completed from account {FromAccID} to account {AccountID}";
                        return(View("Confirmed"));
                    }
                    else if (doubleDebit > 0)
                    {
                        double remainder = -doubleDebit + doubleDeposit; // 200(balance = -300(debit + 500(deposit
                        if (remainder <= 0)
                        {
                            // when balance stays in debit after deposit
                            ba.Credit = 0;
                            ba.Debit  = -remainder;
                            Transaction ta = new Transaction()
                            {
                                id                 = 0,
                                accountID          = int.Parse(AccountID),
                                transactionMessage = "Deposit of " + TransferValue
                            };
                            _db.Transactions.Add(ta);
                            _db.Entry(ba).State = EntityState.Modified;
                            _db.SaveChanges();
                            ViewBag.Confirm = $"Your transfer of {TransferValue} was completed from account {FromAccID} to account {AccountID}";
                            return(View("Confirmed"));
                        }
                        else
                        {
                            // when balance goes from debit to credit
                            ba.Credit = remainder;
                            ba.Debit  = 0;
                            Transaction ta = new Transaction()
                            {
                                id                 = 0,
                                accountID          = int.Parse(AccountID),
                                transactionMessage = "Deposit of " + TransferValue
                            };
                            _db.Transactions.Add(ta);
                            _db.Entry(ba).State = EntityState.Modified;
                            _db.SaveChanges();
                            ViewBag.Confirm = $"Your transfer of {TransferValue} was completed from account {FromAccID} to account {AccountID}";
                            return(View("Confirmed"));
                        }
                    }
                    else
                    {
                        // Depositing when credit and debit = 0;
                        //return new BusinessCheckingDAL().Deposit(int.Parse(accountID), doubleDeposit, doubleDeposit, userID);
                        ba.Credit = doubleDeposit;
                        ba.Debit  = 0;
                        Transaction ta = new Transaction()
                        {
                            id                 = 0,
                            accountID          = int.Parse(AccountID),
                            transactionMessage = "Deposit of " + TransferValue
                        };
                        _db.Transactions.Add(ta);
                        _db.Entry(ba).State = EntityState.Modified;
                        _db.SaveChanges();
                        ViewBag.Confirm = $"Your transfer of {TransferValue} was completed from account {FromAccID} to account {AccountID}";
                        return(View("Confirmed"));
                    }

                    return(View("Confirmed"));
                }
            }
            catch
            {
                return(RedirectToAction("Index"));
            }
            ViewBag.Confirm = $"Error";
            return(View("Confirmed"));
        }
Example #13
0
        public ActionResult Deposit(string accountID, string Credit, string Debit, string depositvalue)
        {
            try
            {
                double doubleCredit  = double.Parse(Credit);
                double doubleDeposit = double.Parse(depositvalue);
                double doubleDebit   = double.Parse(Debit);
                //double setAmount = doubleCredit - doubleDeposit;
                int accID = int.Parse(accountID);
                BusinessCheckingAccount ba = _db.BusinessAccounts.Find(accID) as BusinessCheckingAccount;

                if (doubleCredit > 0)
                {
                    double setAmount = doubleCredit + doubleDeposit;
                    ba.Debit  = 0;
                    ba.Credit = setAmount;
                    Transaction ta = new Transaction()
                    {
                        id                 = 0,
                        accountID          = int.Parse(accountID),
                        transactionMessage = "Deposit of " + depositvalue
                    };
                    _db.Transactions.Add(ta);
                    _db.Entry(ba).State = EntityState.Modified;
                    _db.SaveChanges();
                    //return ba;
                    //return new BusinessCheckingDAL().Deposit(int.Parse(accountID), doubleDeposit, setAmount, userID);
                }
                else if (doubleDebit > 0)
                {
                    double remainder = -doubleDebit + doubleDeposit; // 200(balance = -300(debit + 500(deposit
                    if (remainder <= 0)
                    {
                        // when balance stays in debit after deposit
                        ba.Credit = 0;
                        ba.Debit  = -remainder;
                        Transaction ta = new Transaction()
                        {
                            id                 = 0,
                            accountID          = int.Parse(accountID),
                            transactionMessage = "Deposit of " + depositvalue
                        };
                        _db.Transactions.Add(ta);
                        _db.Entry(ba).State = EntityState.Modified;
                        _db.SaveChanges();
                        //return ba;
                    }
                    else
                    {
                        // when balance goes from debit to credit
                        ba.Credit = remainder;
                        ba.Debit  = 0;
                        Transaction ta = new Transaction()
                        {
                            id                 = 0,
                            accountID          = int.Parse(accountID),
                            transactionMessage = "Deposit of " + depositvalue
                        };
                        _db.Transactions.Add(ta);
                        _db.Entry(ba).State = EntityState.Modified;
                        _db.SaveChanges();
                        //return ba;
                    }
                }
                else
                {
                    // Depositing when credit and debit = 0;
                    //return new BusinessCheckingDAL().Deposit(int.Parse(accountID), doubleDeposit, doubleDeposit, userID);
                    ba.Credit = doubleDeposit;
                    ba.Debit  = 0;
                    Transaction ta = new Transaction()
                    {
                        id                 = 0,
                        accountID          = int.Parse(accountID),
                        transactionMessage = "Deposit of " + depositvalue
                    };
                    _db.Transactions.Add(ta);
                    _db.Entry(ba).State = EntityState.Modified;
                    _db.SaveChanges();
                    //return ba;
                }

                ViewBag.Confirm = $"Your deposit of {depositvalue} was completed from account {accountID}";
                return(View("Confirmed"));
            }
            catch
            {
                return(RedirectToAction("Index"));
            }
        }