public ActionResult DeleteConfirmed(int BankAccountID) { bankaccount bankaccount = db.bankaccounts.Find(BankAccountID); bool hasIncome = IncomeRepository.IncomeByBankAccount(BankAccountID); bool hasExpense = ExpenseRepository.ExpenseByBankAccount(BankAccountID); if ((hasIncome || hasExpense) == false) { db.bankaccounts.Remove(bankaccount); db.SaveChanges(); } else { TempData["Message2"] = string.Format("Can not delete. Account has income or expense data."); } return(RedirectToAction("List")); }