public ActionResult Deposit(string accountID, string Credit, string depositvalue) { try { double balance = double.Parse(Credit) + double.Parse(depositvalue); int accid = int.Parse(accountID); PersonalCheckingAccount personalCheckingAccount = _db.CheckingAccounts.Find(accid) as PersonalCheckingAccount; personalCheckingAccount.Credit = balance; Transaction ta = new Transaction() { id = 0, accountID = int.Parse(accountID), transactionMessage = "Deposit of " + depositvalue }; _db.Transactions.Add(ta); _db.Entry(personalCheckingAccount).State = EntityState.Modified; _db.SaveChanges(); ViewBag.Confirm = $"Your deposit of {depositvalue} was completed from account {accountID}"; return(View("Confirmed")); } catch { return(RedirectToAction("Index")); } }
public ActionResult Withdraw(string accountID, string Credit, string withdrawvalue) { try { int accid = int.Parse(accountID); double balance = double.Parse(Credit) - double.Parse(withdrawvalue); ; if (balance >= 0) { PersonalCheckingAccount personalCheckingAccount = _db.CheckingAccounts.Find(accid) as PersonalCheckingAccount; personalCheckingAccount.Credit = balance; Transaction ta = new Transaction() { id = 0, accountID = int.Parse(accountID), transactionMessage = "Withdrawal of " + withdrawvalue }; _db.Transactions.Add(ta); //_db.Entry(personalCheckingAccount).State = EntityState.Modified; _db.Entry(personalCheckingAccount).State = EntityState.Modified; _db.SaveChanges(); ViewBag.Confirm = $"Your withdrawal of {withdrawvalue} was completed from account {accountID}."; return(View("Confirmed")); } return(RedirectToAction("Index")); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); return(RedirectToAction("Index")); } }
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); }
public ActionResult DeleteConfirmed(int id) { PersonalCheckingAccount personalCheckingAccount = _db.CheckingAccounts.Find(id); _db.CheckingAccounts.Remove(personalCheckingAccount); _db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Delete(int?id) { if (id == null) { return(NotFound()); } PersonalCheckingAccount personalCheckingAccount = _db.CheckingAccounts.Find(id); if (personalCheckingAccount == null) { return(NotFound()); } return(View(personalCheckingAccount)); }
public Account Create(Customer cust) { PersonalCheckingAccount newAccount = new PersonalCheckingAccount() { AccountID = AccountDAL.accountList.Count + 1000, customerID = cust.ID, Credit = 0, Debit = 0, interestRate = 2.5 }; AccountDAL.accountList.Add(newAccount); return(newAccount); }
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")); } }
public String Deposit(PersonalCheckingAccount pa, double amount, double balance) { pa.Credit = balance; pa.transactionLog.Add("Deposit of " + amount); return($"Your new balance for account {pa.AccountID} is ${pa.Credit}"); }
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")); }