Example #1
0
        public ActionResult Post([FromBody] QuestionContent question)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                if (_questionService.GetQuestion(question.Id) != null)
                {
                    return(Conflict($"Question with this Id: {question.Id} already exists"));
                }

                _questionService.CreateQuestion(question);
                var questionDTO = new QuestionContentDTO();
                mapQuestion(question, questionDTO);
                return(Created("", questionDTO));
            }
            catch
            {
                // log here
                return(StatusCode(StatusCodes.Status500InternalServerError, "An error has occurred when trying to POST a Question. It has been logged and is being looked into"));
            }
        }
Example #2
0
 private void mapQuestion(QuestionContent question, QuestionContentDTO questionDTO)
 {
     questionDTO.Id              = question.Id;
     questionDTO.Question        = question.Question;
     questionDTO.AcceptedAnswers = question.AcceptedAnswers;
 }