Beispiel #1
0
        public List <QuestionOutputModel> ConvertQuestionWithAnswersDTOToQuestionOutputModel(List <QuestionWithAnswersDTO> questions)
        {
            List <QuestionOutputModel> result = new List <QuestionOutputModel>();

            foreach (var a in questions)
            {
                if (a != null)
                {
                    QuestionOutputModel tmp = new QuestionOutputModel()
                    {
                        AnswerCount = a.AnswersCount,
                        ID          = a.IDQuestion,
                        Value       = a.Value,
                        Weight      = a.Weight,
                        Answers     = ConvertAnswerDTOToAnswerModelList(a.Answers),
                    };
                    switch (a.Type)
                    {
                    case 0:
                        tmp.Type = Shared.QuestionType.SingleAnswer;
                        break;

                    case 1:
                        tmp.Type = Shared.QuestionType.MultipleAnswers;
                        break;

                    case 2:
                        tmp.Type = Shared.QuestionType.TextAnswer;
                        break;
                    }
                    result.Add(tmp);
                }
            }
            return(result);
        }
Beispiel #2
0
        public ActionResult <QuestionOutputModel> GetQuestionById([FromBody] int questionId)
        {
            Mapper              mapper     = new Mapper();
            AuthorDataAccess    question   = new AuthorDataAccess();
            QuestionOutputModel model      = mapper.ConvertQuestionDTOToQuestionOutputModel(question.GetQuestionById(questionId));
            QuestionStatistics  statistics = new QuestionStatistics(questionId);

            model.PercentageOfCorrectlyAnswered = statistics.GetPercentageOfCorrectlyAnswered(questionId);
            return(Ok(model));
        }