예제 #1
0
        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 }));
        }
예제 #2
0
        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 }));
            }
        }
예제 #3
0
        public IActionResult RejectMaterial(int materialId)
        {
            var materialToReject = _materialsService.GetMaterial(materialId);

            if (materialToReject == null)
            {
                return(RedirectToAction("ResourceNotFound", "Error", new { error = "materiał o podanym Id nie istnieje." }));
            }

            _filesManagement.DeleteWholeMaterialFolder(materialId);
            _materialsService.RejectMaterial(materialToReject);
            return(RedirectToAction("MaterialsToApprove"));
        }
        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 IActionResult ApproveDeleteRequest(int deleteRequestId)
        {
            var loggedModerator = _userService.FindByIdentityUserId(User.FindFirstValue(ClaimTypes.NameIdentifier));

            try
            {
                var deleteRequest = _materialsService.GetDeleteRequest(deleteRequestId);
                if (deleteRequest == null)
                {
                    return(RedirectToAction("ResourceNotFound", "Error", new { error = "sugestia usunięcia o podanym Id nie istnieje." }));
                }

                _filesManagement.DeleteWholeMaterialFolder(deleteRequest.MaterialToDeleteId.Value);
                _materialsService.ApproveDeleteRequest(deleteRequest, loggedModerator);
            }
            catch (ArgumentException)
            {
                return(BadRequest("Sugestia usunięcia o podanym Id nie istnieje"));
            }

            return(RedirectToAction("DeleteSuggestions"));
        }