public ActionResult Delete(DeleteLivingSpaceView collection) { List <WorkerView> workers = new List <WorkerView>(); workers = WorkerRepo.GetAllWorkers(); List <LivingSpaceListView> livingspaces = new List <LivingSpaceListView>(); livingspaces = LivingSpaceRepos.getLivingSpaceByAddress(collection.address); bool rado = false; foreach (var a in livingspaces) { foreach (var b in workers) { if (a.id_LivingSpace == b.fk_LivingSpaceid_LivingSpace) { rado = true; break; } } } if (rado == false) { LivingSpaceRepos.ConfirmDeleteLivingSpace(collection.address); return(RedirectToAction("Index")); } TempData["err"] = "There are still users registered to this address"; return(View()); }