Example #1
0
        public IActionResult Answers(int id)
        {
            try
            {
                IEnumerable <Answer> answers = answerManager.Find(x => x.QuestionId == id);

                return(Ok(answers));
            }
            catch (Exception ex)
            {
                logger.LogError($"Failed to get answers for question {id}: {ex}");
                return(BadRequest(config["Error:Default"]));
            }
        }
Example #2
0
        public IActionResult Search([FromQuery] Answer answer, [FromQuery] Question question,
                                    [FromQuery] Period period, QuestionType questionType, [FromQuery] string isOpen,
                                    [FromQuery] string hasAnswers)
        {
            try
            {
                IEnumerable <Answer> answers = answerManager.Find(x =>
                                                                  x.AnswerId == answer.AnswerId &&
                                                                  x.AnswerText == answer.AnswerText &&
                                                                  x.AnswerSort == answer.AnswerSort &&
                                                                  x.Question.QuestionTypeId == question.QuestionTypeId &&
                                                                  x.Question.PeriodId == question.PeriodId &&
                                                                  x.Question.Period.StartDate == period.StartDate &&
                                                                  x.Question.Period.EndDate == period.EndDate &&
                                                                  x.Question.QuestionText == question.QuestionText &&
                                                                  x.Question.QuestionSort == question.QuestionSort &&
                                                                  x.Question.QuestionType.Description == questionType.Description);

                if (!string.IsNullOrWhiteSpace(isOpen))
                {
                    bool isOp;
                    bool.TryParse(isOpen, out isOp);

                    answers = answers.Where(x => x.Question.Period.IsOpen == isOp);
                }

                if (!string.IsNullOrWhiteSpace(hasAnswers))
                {
                    bool hasAns;
                    bool.TryParse(hasAnswers, out hasAns);

                    answers = answers.Where(x => x.Question.QuestionType.HasAnswers == hasAns);
                }

                return(Ok(answers));
            }
            catch (Exception ex)
            {
                logger.LogError($"Failed to find answer(s): {ex}");
                return(BadRequest(config["Error:Default"]));
            }
        }