示例#1
0
        public async Task <IActionResult> Add([FromBodyAttribute] QuestionIgnoreId question)
        {
            try
            {
                if (question == null || string.IsNullOrEmpty(question.TopicId))
                {
                    return(BadRequest());
                }

                var topicId = question.TopicId;

                var topic = await _quizManager.GetTopicByIdAsync(topicId);

                if (topic == null)
                {
                    return(NotFound("Topic not found"));
                }

                await _quizManager.AddQuestionAsync(new ResponseData.Question {
                    TopicId     = topicId,
                    Description = question.Description,
                    Notes       = question.Notes
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine($"[Error ] {ex}");
                return(BadRequest());
            }
            return(new StatusCodeResult((int)HttpStatusCode.Created));
        }