public ActionResult RemoveCustomer(int customerId) { Customer cusdelete = new Customer(); TransRecievablesViewModel tr = new TransRecievablesViewModel(); bool success = false; try { //get customer in db // check if has balance //var customertrans = tr.GetAllRecievables().Where(x => x.cusId == cusdelete.c_Id) // .Any(b => b.balance > 0); var hasBookings = _dbcontext.Bookings.Any(x => x.c_Id == customerId); if (!hasBookings) { cusdelete = _dbcontext.Customers.Find(customerId); if (cusdelete != null) { _dbcontext.Customers.Remove(cusdelete); } _dbcontext.SaveChanges(); success = true; } } catch (Exception e) { Console.WriteLine(e); throw; } return(Json(new { success = success }, JsonRequestBehavior.AllowGet)); }