private void AddTransaction(CDAccounts currAcct, decimal balance, string v) { Transaction newTrans = new Transaction() { AccountNum = currAcct.AccountNumber, Amount = balance, Type = v, UserID = currAcct.UserID, TimeTransaction = DateTime.Now }; _context.AccountTransactions.Add(newTrans); }
private bool CheckWithdrawOverdraft(CDAccounts currAcct, CDAccounts cdAcct) { if ((currAcct.Balance - cdAcct.Balance) < 0) { ModelState.AddModelError("", "Not Enough Funds To Withdraw"); return(true); } else if (cdAcct.Balance == 0) { ModelState.AddModelError("", "Did not specify Withdraw Amount"); return(true); } return(false); }
public async Task <IActionResult> Withdraw(int id, CDAccounts cDAccount) { if (id != cDAccount.Id) { return(NotFound()); } var currAcct = await _context.TermAccounts.FirstOrDefaultAsync(m => m.Id == id); if (ModelState.IsValid) { try { var newBalance = currAcct.Balance - cDAccount.Balance; int num = DateTime.Compare(DateTime.Today, currAcct.MaturityDate); if (num < 0) { ModelState.AddModelError("", "Cannot Withdraw Maturity Date has not been reached"); return(View(currAcct)); } if (CheckWithdrawOverdraft(currAcct, cDAccount)) //check if enough funds to withdraw { return(View(currAcct)); } AddTransaction(currAcct, cDAccount.Balance, "Direct Withdraw"); currAcct.Balance = newBalance; //_context.Update(checkingAccount); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CDAccountsExists(cDAccount.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } //return Content(currAcct.AccountNumber); return(View(currAcct)); }
public async Task <IActionResult> Create([Bind("Id,Balance,IsOpen,InterestRate,AccountNumber,MaturityDate,CreationDate,UserID")] CDAccounts cDAccounts) { if (ModelState.IsValid) { //var userId = _context._httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; var user = User.FindFirstValue(ClaimTypes.NameIdentifier); cDAccounts.UserID = user; cDAccounts.IsOpen = true; cDAccounts.CreationDate = DateTime.Today; cDAccounts.InterestRate = randomInterestRate(); cDAccounts.AccountNumber = randomAccountNumber(); _context.Add(cDAccounts); AddTransaction(cDAccounts, cDAccounts.Balance, "CD Deposit"); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(cDAccounts)); }
private bool CheckWithdrawOverdraft(CDAccounts currAcct, decimal amount) { if ((currAcct.Balance - amount) < 0) { ModelState.AddModelError("", "Not Enough Funds To Withdraw"); return(true); } else if (amount == 0) { ModelState.AddModelError("", "Did not specify Withdraw Amount"); return(true); } else if (amount < 0) { ModelState.AddModelError("", "Amount Can't be negative"); return(true); } return(false); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Balance,IsOpen,InterestRate,AccountNumber,MaturityDate,CreationDate,UserID")] CDAccounts cDAccounts) { return(View()); }