public IActionResult Delete(int universityId, bool confirmation = false) { var universityToDelete = _traversalService.GetUniversity(universityId); if (universityToDelete == null) { return(RedirectToAction("ResourceNotFound", "Error", new { error = "uczelnia o podanym Id nie istnieje." })); } ConfigureDeleteBreadcrumbs(universityId); if (!confirmation) { var vm = new UniversityViewModel { Id = universityId, TitleOrFullName = universityToDelete.Name }; return(View(vm)); } else { // First - delete materials due to database constraints betwee Lesson and Material foreach (var dept in universityToDelete.Departments) { foreach (var lesson in dept.Lessons) { foreach (var materialToDelete in lesson.Materials) { _filesManagement.DeleteWholeMaterialFolder(materialToDelete.MaterialId); _materialsService.DeleteMaterial(materialToDelete); } } } // actually delete _managementService.DeleteUniversity(universityToDelete); return(RedirectToAction("Universities")); } }
public void Delete(int universityId) { var universityToDelete = _traversalService.GetUniversity(universityId); _managementService.DeleteUniversity(universityToDelete); }