Beispiel #1
0
        public IActionResult PostNewQuestion(NewQuestionDto question, [FromRoute] string orgId)
        {
            try
            {
                _unitOfWorkManager.StartUnitOfWork();
                Question createdQuestion = _questionnaireManager.AddQuestion(
                    question.Inquiry,
                    question.Required,
                    question.QuestionType,
                    question.QuestionnaireId);
                _unitOfWorkManager.EndUnitOfWork();

                return(CreatedAtAction(
                           "GetQuestion",
                           new { orgId, id = createdQuestion.QuestionId },
                           _mapper.Map <QuestionMinDto>(createdQuestion)));
            }
            catch (ValidationException ve)
            {
                return(UnprocessableEntity($"Invalid input data: {ve.ValidationResult.ErrorMessage}"));
            }
            catch (Exception e)
            {
                return(BadRequest($"Something went wrong in creating the question: {e.Message}."));
            }
        }
Beispiel #2
0
        public IActionResult UpdateQuestion(int id, NewQuestionDto updatedValues)
        {
            try
            {
                _unitOfWorkManager.StartUnitOfWork();
                Question updatedQuestion = _questionnaireManager.ChangeQuestion(
                    id,
                    updatedValues.Inquiry,
                    updatedValues.QuestionType,
                    updatedValues.QuestionnaireId);
                _unitOfWorkManager.EndUnitOfWork();

                if (updatedQuestion == null)
                {
                    return(BadRequest("Something went wrong while updating the question."));
                }

                return(Ok(_mapper.Map <QuestionMinDto>(updatedQuestion)));
            }
            catch (ValidationException ve)
            {
                return(UnprocessableEntity($"Invalid input data: {ve.ValidationResult.ErrorMessage}"));
            }
            catch (ArgumentException e)
            {
                switch (e.ParamName)
                {
                case "id":
                    return(NotFound(e.Message));

                case "questiontionId":
                    return(UnprocessableEntity(e.Message));

                default:
                    return(BadRequest(e.Message));
                }
            }
        }