public ActionResult Update(UpdateResponseDto model)
        {
            var entity = _repo.Get(model.EntityId);

            if (entity == null)
            {
                return(RedirectToAction("Index"));
            }

            entity.Name = model.Name;

            _repo.Update(entity);

            return(RedirectToAction("Index"));
        }
Exemple #2
0
        public async Task Update(string commentId, string id, UpdateResponseDto dto)
        {
            User user = await _sessionService.GetUser();

            Validate("modify", dto.Content, user);

            Response response = await _responseRepository.GetById(id);

            if (response == null)
            {
                _logger.LogWarning($"Response {id} does not exist");
                throw HttpError.NotFound($"Response {id} does not exist");
            }

            if (response.CommentId != commentId)
            {
                throw HttpError.NotFound("");
            }

            if (response.AuthorId != user.Id)
            {
                _logger.LogWarning($"Response {id} does not belong to user");
                throw HttpError.Forbidden($"Response {id} does not belong to user");
            }

            response.Content        = dto.Content;
            response.LastUpdateTime = DateTime.Now;

            bool success = await _responseRepository.Update(response);

            if (!success)
            {
                _logger.LogWarning("Error during update response");
                throw HttpError.InternalServerError("");
            }
        }
Exemple #3
0
        public async Task <IActionResult> Update([FromRoute] string commentId, string id, [FromBody] UpdateResponseDto dto)
        {
            await _responseService.Update(commentId, id, dto);

            return(NoContent());
        }