Esempio n. 1
0
        public static int GradeExam(Models.Exam azureExam, IEnumerable <ExamResponse> examResponses)
        {
            foreach (ExamQuestion examQuestion in azureExam.ExamQuestions)
            {
                foreach (ExamChoice examChoice in examQuestion.ExamChoices)
                {
                    if (examResponses.Any(x => x.ExamChoiceID == examChoice.ID))
                    {
                        examChoice.IsSelected = true; //examResponses.FirstOrDefault(x => x.ExamChoiceID == examChoice.ID).IsSelected;
                    }
                }
            }

            return(azureExam.ExamQuestions.Select(x => x.ExamChoices.Where(y => y.IsSelected && y.IsCorrect).Count()).Sum());
        }
Esempio n. 2
0
        public static IEnumerable <ExamResponse> CollectExamResponses(Models.Exam azureExam, Func <ExamChoice, bool> f)
        {
            List <ExamResponse> lstExamResponses = new List <ExamResponse>();

            foreach (ExamQuestion examQuestion in azureExam.ExamQuestions)
            {
                foreach (ExamChoice examChoice in examQuestion.ExamChoices)
                {
                    lstExamResponses.Add(new ExamResponse()
                    {
                        ExamChoiceID = examChoice.ID,
                        IsSelected   = f(examChoice)
                    });
                }
            }

            return(lstExamResponses.Where(x => x.IsSelected));
        }