Exemplo n.º 1
0
        public static GivenQuestionDTO ConvertFromEntity(GivenQuestion entity)
        {
            var model = new GivenQuestionDTO
            {
                Id           = entity.Id,
                TestResultId = entity.TestResultId,
                QuestionId   = entity.QuestionId,
                Question     = new QuestionDTO
                {
                    Id        = entity.Question.Id,
                    ImageLink = entity.Question.ImageLink,
                    Text      = entity.Question.Text,
                    TestId    = entity.Question.TestId,
                    Weight    = entity.Question.Weight
                },
            };

            model.Question.Answers = new List <AnswerDTO>();
            foreach (var answer in entity.Question.Answers)
            {
                model.Question.Answers.Add(new AnswerDTO
                {
                    Id         = answer.Id,
                    ImageLink  = answer.ImageLink,
                    QuestionId = answer.QuestionId,
                    IsCorrect  = answer.IsCorrect,
                    Text       = answer.Text
                });
            }
            model.Answers = new List <GivenAnswerDTO>();
            if (entity.Answers != null)
            {
                foreach (var answer in entity.Answers)
                {
                    model.Answers.Add(new GivenAnswerDTO
                    {
                        Id         = answer.Id,
                        AnswerId   = answer.AnswerId,
                        QuestionId = answer.QuestionId
                    });
                }
            }


            return(model);
        }
Exemplo n.º 2
0
        private double GetGradeForQuestion(GivenQuestion question, bool toCalculatePartial, int resultGrade, int countOfQuestions)
        {
            var countOfAnswers            = question.Question.Answers.Count;
            var countOfRightAnswers       = 0;
            var countOfWrongAnswers       = 0;
            var countOfAnswersOfUser      = question.Answers.Count;
            var countOfRightAnswersTarget = question.Question.Answers.Where(x => x.IsCorrect).Count();

            double questionWeight = question.Question.Weight != 0 ?
                                    question.Question.Weight :
                                    (double)resultGrade / (double)countOfQuestions;

            foreach (var answer in question.Answers)
            {
                var  answerId  = answer.AnswerId;
                bool isCorrect = question.Question.Answers.FirstOrDefault(x => x.Id == answerId).IsCorrect;
                if (isCorrect)
                {
                    countOfRightAnswers++;
                }
                else
                {
                    countOfWrongAnswers++;
                }
            }
            if (!toCalculatePartial)
            {
                if (countOfRightAnswers == countOfRightAnswersTarget && countOfWrongAnswers == 0)
                {
                    return(questionWeight);
                }
                else
                {
                    return(0);
                }
            }
            else
            {
                return(((double)countOfRightAnswers / (double)countOfAnswersOfUser) * questionWeight);
            }
        }
Exemplo n.º 3
0
 private double GetWeightOfQuestion(Test test, GivenQuestion question)
 {
     return(question.Question.Weight != 0 ? question.Question.Weight : (double)test.Grade / test.Questions.Count);
 }