예제 #1
0
        public IActionResult CreateDeleteSuggestion(DeleteRequestViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return(View(vm));
            }

            if (vm.ReasonId == 5 && string.IsNullOrEmpty(vm.AdditionalComment))
            {
                ModelState.AddModelError("AdditionalComment", "Wybranie przyczyny \"Inne\" wymaga podania dodatkowego wyjaśnienia");
                return(View(vm));
            }

            var deleter = _userService.FindByIdentityUserId(User.FindFirstValue(ClaimTypes.NameIdentifier));

            try
            {
                _service.CreateDeleteRequest(deleter, vm.MaterialId, vm.ReasonId, vm.AdditionalComment);
            }
            catch (ArgumentNullException)
            {
                return(RedirectToAction("ResourceNotFound", "Error", new { error = "materiał o podanym Id nie istnieje" }));
            }

            return(RedirectToAction("Material", new { materialId = vm.MaterialId }));
        }