Exemplo n.º 1
0
        public static List <AssessmentsTypeView> FillQuiz(
            IQueryable <AssessmentType> assessmentTypes,
            IAssessmentGroupsRepository assessmentGroupsRepository,
            IAssessmentQuestionsRepository assessmentQuestionsRepository,
            FormCollection form)
        {
            List <AssessmentsTypeView> tmpAssessmentsTypes = new List <AssessmentsTypeView>();

            foreach (var assessmentType in assessmentTypes)
            {
                List <AssessmentsGroupView> AssessmentsGroups   = new List <AssessmentsGroupView>();
                AssessmentsTypeView         AssessmentsTypeView = new AssessmentsTypeView();
                AssessmentsTypeView.AssessmentType = assessmentType;

                var assessmentGroups = assessmentGroupsRepository.GetAssessmentGroupsByType(assessmentType.AssessmentTypePK);
                foreach (var assessmentGroup in assessmentGroups)
                {
                    AssessmentsGroupView assessmentsGroupTmp = new AssessmentsGroupView();
                    assessmentsGroupTmp.AssessmentGroup = assessmentGroup;

                    List <AssessmentQuestion>     assessmentsQuestions     = assessmentQuestionsRepository.GetAssessmentQuestionsByGroup(assessmentGroup.AssessmentGroupPK).ToList();
                    List <AssessmentQuestionView> assessmentsQuestionsView = new List <AssessmentQuestionView>();
                    foreach (var assessmentQuestion in assessmentsQuestions)
                    {
                        AssessmentQuestionView assessmentQuestionTmp = new AssessmentQuestionView();
                        assessmentQuestionTmp.AssessmentQuestion = assessmentQuestion;
                        bool?answered = null;
                        if (form != null)
                        {
                            if (form["answer[" + assessmentQuestion.AssessmentQuestionPK + "]"] != null)
                            {
                                if (form["answer[" + assessmentQuestion.AssessmentQuestionPK + "]"].ToString() == "NP")
                                {
                                    answered = null;
                                }
                                else
                                {
                                    answered = form["answer[" + assessmentQuestion.AssessmentQuestionPK + "]"].ToString() == "Da" ? true : false;
                                }
                            }
                        }

                        assessmentQuestionTmp.Answer = answered;
                        assessmentsQuestionsView.Add(assessmentQuestionTmp);
                    }

                    assessmentsGroupTmp.AssessmentQuestions = assessmentsQuestionsView;

                    AssessmentsGroups.Add(assessmentsGroupTmp);
                }
                AssessmentsTypeView.AssessmentGroups = AssessmentsGroups;

                tmpAssessmentsTypes.Add(AssessmentsTypeView);
            }

            return(tmpAssessmentsTypes);
        }
Exemplo n.º 2
0
        public static List <AssessmentAnswers> ExtractQuizAnswers(AssessmentsTypeView atw, int AssessmentPK)
        {
            List <AssessmentAnswers> tmpAssessmentAnswers = new List <AssessmentAnswers>();

            foreach (var group in atw.AssessmentGroups)
            {
                foreach (var question in group.AssessmentQuestions)
                {
                    tmpAssessmentAnswers.Add(new AssessmentAnswers()
                    {
                        AssessmentQuestionFK = question.AssessmentQuestion.AssessmentQuestionPK,
                        AssessmentAnswer     = question.Answer,
                        AssessmentFK         = AssessmentPK
                    });
                }
            }

            return(tmpAssessmentAnswers);
        }