public IActionResult SendFeedback([FromBody] FeedbackResponseDTO result)
        {
            try
            {
                var response = _responseRepository.GetResponse(result.ResponseId);
                response.CreateDate = DateTime.Now;

                foreach (var answer in result.FeedbackResult)
                {
                    response.ResponseItems.Add(new ResponseItem
                    {
                        ResponseId   = result.ResponseId,
                        SurveyItemId = answer
                    });
                }

                _responseRepository.Update(response);

                return(View("ThankYou"));
            }
            catch (Exception ex)
            {
                throw new Exception("Ocorreu algum erro");
            }
        }
        public IActionResult PutArticle(ArticleModel articleModel)
        {
            var articleContent  = articleModel.articleApi;
            var articleRequest  = articleModel.requestApi;
            var articleResponse = articleModel.responseApi;
            var requestLength   = articleModel.requestApi.Count;

            for (int i = 0; i < requestLength; i++)
            {
                if (_requestRepository.FindRequestByID(articleRequest[i].RequestID.ToString()) == true)
                {
                    _requestRepository.Update(articleRequest[i]);
                }
                else
                {
                    _requestRepository.InsertData(articleRequest[i]);
                }
            }
            var responseLength = articleModel.responseApi.Count;

            for (int i = 0; i < responseLength; i++)
            {
                if (_responseRepository.FindResponseByID(articleResponse[i].ResponseID.ToString()) == true)
                {
                    _responseRepository.Update(articleResponse[i]);
                }
                else
                {
                    _responseRepository.InsertData(articleResponse[i]);
                }
            }
            _articleRepository.Update(articleContent);
            return(StatusCode(201, "Updated success"));
        }
Exemple #3
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("");
            }
        }