Exemplo n.º 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));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetById(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(BadRequest());
            }

            try
            {
                var results = await _quizManager.GetTopicByIdAsync(id);

                if (results == null)
                {
                    return(NotFound());
                }

                return(new ObjectResult(results));
            }
            catch (System.Exception ex)
            {
                _loggerTopic.LogError($"Error {ex}");
                return(new StatusCodeResult((int)HttpStatusCode.InternalServerError));
            }
        }