public IActionResult Delete(DeleteMaterialViewModel vm) { if (!ModelState.IsValid) { return(View(vm)); } var identityUserId = User.FindFirstValue(ClaimTypes.NameIdentifier); var materialToDelete = _service.GetMaterial(vm.MaterialId); if (materialToDelete == null) { return(RedirectToAction("ResourceNotFound", "Error", new { error = "materiał o podanym Id nie istnieje." })); } if (IsUserAllowedToEditOrDelete(identityUserId, materialToDelete)) { return(RedirectToAction("ActionForbidden", "Error", new { error = "nie masz uprawnień do tego działania" })); } _filesManagement.DeleteWholeMaterialFolder(materialToDelete.MaterialId); _service.DeleteMaterial(materialToDelete); return(RedirectToAction("Materials", new { @lessonId = vm.LessonId })); }
public IActionResult Delete(int lessonId, bool confirmation = false) { var lessonToDelete = _traversalService.GetLesson(lessonId); ConfigureDeleteBreadcrumbs(lessonToDelete); if (!confirmation) { var vm = new LessonViewModel { Id = lessonId, TitleOrFullName = lessonToDelete.Subject.Name, SemesterId = lessonToDelete.SemesterId, DepartmentId = lessonToDelete.DepartmentId, MaterialsCount = lessonToDelete.MaterialsCount }; return(View(vm)); } else { // First - delete materials due to database constraints betwee Lesson and Material foreach (var material in lessonToDelete.Materials) { _filesManagement.DeleteWholeMaterialFolder(material.MaterialId); _materialsService.DeleteMaterial(material); } // actually delete _managementService.DeleteLesson(lessonToDelete.LessonId); return(RedirectToAction("Lessons", new { semesterId = lessonToDelete.SemesterId, departmentId = lessonToDelete.DepartmentId })); } }
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")); } }