コード例 #1
0
        public async Task <IActionResult> Create([FromBody] CreatePollAnswer model,
                                                 [FromRoute] int questionId)
        {
            var resultPQ = await _pollQuestionService.GetById(questionId);

            if (!resultPQ.Succeeded)
            {
                return(BadRequest(resultPQ.Errors));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(model));
            }

            var dto = _mapper.Map <DtoPollAnswer>(model);

            dto.Id             = 0;
            dto.PollQuestionId = questionId;

            var result = await _pollAnswerService.CreateAsync(dto, UserId);

            if (!result.Succeeded)
            {
                return(UnprocessableEntity(result.Errors));
            }

            return(Ok(result.Result));
        }