public JsonResult Delete(int id) { var expenseCategoryInDb = _expenseCategoryRepository.FindById(id); bool result = false; var expensesThatHaveThisCategory = _expenseRepository.GetAllFromDatabaseEnumerable().Where(e => e.ExpenseCategoryId == id).ToList(); if (expensesThatHaveThisCategory.Count == 0 && expenseCategoryInDb != null) { _expenseCategoryRepository.DeleteFromDatabase(expenseCategoryInDb); _expenseCategoryRepository.Save(); result = true; } else { return(Json(new { })); } return(Json(result, JsonRequestBehavior.AllowGet)); }