示例#1
0
        public IActionResult AddComment(AddCommentViewModel vm)
        {
            var material = _service.GetMaterial(vm.MaterialId);

            if (material == null)
            {
                ModelState.AddModelError("ERROR", "Taki materiał nie istnieje");
                RedirectToAction("Material", vm.MaterialId);
            }

            var materialViewModel = PrepareMaterialViewModel(material);

            if (!ModelState.IsValid)
            {
                return(View("Material", materialViewModel));
            }

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

            _service.AddComment(vm.NewComment, material, commentAuthor);

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