public async Task <IActionResult> CreateAnswerForAnotherComment(int id, [FromBody] CreateAnswerModel comment)
        {
            var commentDto = new CreateAnswerCommentDto()
            {
                ParentCommentId = id,
                Body            = comment.Body,
                GameId          = comment.GameId,
                Name            = comment.Name
            };

            await commnetService.AnswerOnComment(commentDto);

            return(StatusCode((int)HttpStatusCode.Created, "Comment was created"));
        }
示例#2
0
        public async Task <IActionResult> Create(CreateAnswerInputModel input)
        {
            if (input.AnswerId == null || input.AnswerId == "" ||
                input.PostId == null || input.PostId == "")
            {
                return(BadRequest(""));
            }

            string userId = User.Claims.First(x => x.Type == ClaimTypes.NameIdentifier).Value;

            var user = await _httpSender.SendGetAsync <GetUserResponse>(UsersController.UsersRoot + "?id=" + userId);

            CreateAnswerModel answer = new CreateAnswerModel
            {
                Text       = input.Text,
                AuthorId   = userId,
                AuthorName = user.Name,
                AnswerId   = input.AnswerId,
                PostId     = input.PostId
            };

            Response response = new Response();

            try
            {
                response = await _httpSender.SendPostAsync <Response, CreateAnswerModel>(answer, AnswersRoot);
            }
            catch (Exception e)
            {
                return(StatusCode(500));
            }

            if (response.Status == Status.Ok)
            {
                return(Ok());
            }
            else if (response.Status == Status.ServerError)
            {
                return(StatusCode(500, response.Error));
            }
            else
            {
                return(BadRequest(response.Error));
            }
        }
示例#3
0
        public IActionResult CreateAnswer([FromBody] CreateAnswerModel model)
        {
            // map model to entity
            var answer = _mapper.Map <Answer>(model);

            try
            {
                // create user answer
                _answerService.Create(answer);
                return(Ok(new {
                    data = answer,
                    message = "Successfully saved user answer."
                }));
            }
            catch (AppException ex)
            {
                // return error message if there was an exception
                return(BadRequest(new { message = ex.Message }));
            }
        }