Exemple #1
0
        public async Task <IActionResult> Add(string questionId,
                                              [FromBodyAttribute] AnswerIgnoreIdAndQuestion answer)
        {
            try
            {
                var question = _quizManager.GetQuestionByIdAsync(questionId);
                if (question == null)
                {
                    return(BadRequest("Question Not found"));
                }

                await _quizManager.AddAnswerAsync(new ResponseData.Answer {
                    QuestionId  = questionId,
                    Description = answer.Description,
                    Notes       = answer.Notes
                });

                return(new StatusCodeResult((int)HttpStatusCode.Created));
            }
            catch (System.Exception ex)
            {
                Console.WriteLine($"[Error ] {ex}");
                return(BadRequest());
            }
        }
Exemple #2
0
        public async Task <IActionResult> Get(string topicId)
        {
            if (string.IsNullOrEmpty(topicId))
            {
                return(BadRequest());
            }
            try
            {
                var response = await _quizManager.GetQuestionByIdAsync(topicId);

                if (response != null)
                {
                    return(new OkObjectResult(response));
                }

                return(NotFound());
            }
            catch (Exception ex)
            {
                _log.LogError($"Class = {typeof(QuestionController).Name} Exception={ex}");
                throw;
            }
        }