Ejemplo n.º 1
0
        public IHttpActionResult Put(int surveyId, int questionId)
        {
            try
            {
                // remove questions
                var questionRepository = new QuestionRepository();
                questionRepository.RemoveQuestion(surveyId, questionId);

                // remove options
                var questionOptionsRepository = new QuestionOptionRepository();
                questionOptionsRepository.RemoveOptions(surveyId, questionId);

                return(Ok(questionId));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Ejemplo n.º 2
0
        public IHttpActionResult Post([FromBody] List <Question> questions)
        {
            try
            {
                var questionRepository        = new QuestionRepository();
                var questionOptionsRepository = new QuestionOptionRepository();

                // insert questions
                var surveyQuestions = questionRepository.InsertQuestions(questions);

                // insert options
                var surveyQuestionOptions = questionOptionsRepository.InsertOptions(surveyQuestions);

                return(Created <List <Question> >(Request.RequestUri, surveyQuestionOptions));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Ejemplo n.º 3
0
        public IHttpActionResult Get(int id)
        {
            try
            {
                // get questions
                var questionRepository = new QuestionRepository();
                var surveyQuestions    = questionRepository.GetQuestions(id);

                // get options
                var questionOptionsRepository  = new QuestionOptionRepository();
                var surveyQuestionsWithOptions = questionOptionsRepository.GetQuestionOptions(surveyQuestions);

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

                return(Ok(surveyQuestionsWithOptions));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }