public CurrentTopicTestResultsModel(int curriculumChapterTopicId, TopicTypeEnum topicType, int groupId, ILmsService lmsService)
 {
     this.group = lmsService.FindService<IUserService>().GetGroup(groupId);
     var currenUser = lmsService.FindService<IUserService>().GetCurrentUser();
     var curriculumChapterTopic = lmsService.FindService<ICurriculumService>().GetCurriculumChapterTopicById(curriculumChapterTopicId);
     if (currenUser != null & curriculumChapterTopic != null)
     {
         var attemptResults = lmsService.FindService<ITestingService>().GetResults(currenUser, curriculumChapterTopic, topicType).ToList();
         if (attemptResults.Any())
         {
             // hotfix: added checking of Course id
             this.attempt =
                 attemptResults.FirstOrDefault(x => x.CurriculumChapterTopic.Topic.TestCourseRef == x.IudicoCourseRef);
             if (this.attempt != null)
             {
                 this.courseInfo =
                     lmsService.FindService<ICourseService>().GetCourseInfo(this.attempt.IudicoCourseRef);
                 this.userAnswers = lmsService.FindService<ITestingService>().GetAnswers(this.attempt);
                 
                 this.hasNoData = this.userAnswers == null;
             }
         }
         else
             this.hasNoData = true;
     }
     else
         this.hasNoData = true;
 }
Ejemplo n.º 2
0
        public static IudicoCourseInfo Parse(Course course, ICourseStorage storage)
        {
            int id = course.Id;
            IudicoCourseInfo ci = new IudicoCourseInfo();
            ci.Id = id;

            var nodes = storage.GetNodes(id).ToList();

            for (var i = 0; i < nodes.Count; i++)
            {
                if (nodes[i].IsFolder == false)
                {
                    try
                    {
                        ci.NodesInfo.Add(ParseNode(nodes[i], storage));
                    }
                    catch
                    {
                        
                    }
                }
                else
                {
                    var subNodes = storage.GetNodes(id, nodes[i].Id);
                    nodes.AddRange(subNodes);
                }
            }

            return ci;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// constructor that get all information from Testing System
        /// </summary>
        /// <param name="attemptId">id of attempt to show</param>
        /// <param name="attList">list of attempts from Session Context</param>
        /// <param name="lmsService">ILmsService for conection to Testing System</param>
        public TopicTestResultsModel(long attemptId, IEnumerable<AttemptResult> attList, int groupId, ILmsService lmsService)
        {
            if (attemptId != -1)
            {
                this.group = lmsService.FindService<IUserService>().GetGroup(groupId);
                // hotfix: added checking of Course id
                this.attempt =
                    attList.FirstOrDefault(
                        c =>
                        c.AttemptId == attemptId && c.CurriculumChapterTopic.Topic.TestCourseRef == c.IudicoCourseRef);
                if (this.attempt != null)
                {
                    this.userAnswers = lmsService.FindService<ITestingService>().GetAnswers(this.attempt);
                    this.courseInfo =
                            lmsService.FindService<ICourseService>().GetCourseInfo(this.attempt.IudicoCourseRef);

                    this.hasNoData = this.userAnswers == null;
                }
                else
                {
                    this.hasNoData = true;
                }                
            }
            else
                this.hasNoData = true;
        }
Ejemplo n.º 4
0
        public int AddCourseInfo(IudicoCourseInfo courseInfo)
        {
            var id = this.storage.AddCourseInfo(courseInfo);

            this.cacheProvider.Invalidate("coursesInfo");

            return id;
        }
Ejemplo n.º 5
0
        public IudicoCourseInfo GetCourseInfo(int id)
        {
            var db = this.GetDbContext();

            var courseInfo = new IudicoCourseInfo { Id = id };

            var databaseNodesInfo = db.NodesInfo.Where(n => n.CourseId == id);
            foreach (var ni in databaseNodesInfo)
            {
                var nodeInfo = new IudicoNodeInfo { CourseId = id, Id = ni.NodeId };
                var databaseQuestionsInfo = db.QuestionsInfo.Where(q => q.NodeId == ni.NodeId);

                foreach (var qi in databaseQuestionsInfo)
                {
                    IudicoQuestionInfo questionInfo = null;
                    switch (qi.Type)
                    {
                        case 1:
                            var simpleQuestion = db.SimpleQuestions.Single(q => q.QuestionId == qi.Id);

                            questionInfo = new IudicoSimpleQuestion
                            {
                                QuestionText = qi.Text,
                                MaxScore = qi.MaxScore,
                                Type = IudicoQuestionType.IudicoSimple,
                                CorrectAnswer = simpleQuestion.CorrectAnswer
                            };
                            break;

                        case 2:
                            var options = db.ChoiceQuestionsOptions.Where(q => q.QuestionId == qi.Id);
                            var correctChoice = db.ChoiceQuestionsCorrectChoices.Single(q => q.QuestionId == qi.Id);

                            questionInfo = new IudicoChoiceQuestion
                            {
                                QuestionText = qi.Text,
                                MaxScore = qi.MaxScore,
                                Type = IudicoQuestionType.IudicoChoice,
                                CorrectChoice = correctChoice.CorrectChoice,
                                Options = (from o in options
                                           select new Tuple<string, string>(o.Option, o.Description)).ToList()
                            };
                            break;

                        case 3:
                            var compiledTests = db.CompiledTestQuestions.Where(q => q.QuestionId == qi.Id);

                            questionInfo = new IudicoCompiledTest
                            {
                                QuestionText = qi.Text,
                                MaxScore = qi.MaxScore,
                                Type = IudicoQuestionType.IudicoCompile,
                                TestInputs = (from ct in compiledTests
                                              select new Tuple<string, string>("testInput" + ct.TestNumber, ct.TestInput)).ToList(),
                                TestOutputs = (from ct in compiledTests
                                               select new Tuple<string, string>("testOutput" + ct.TestNumber, ct.TestOutput)).ToList(),
                            };
                            break;
                    }

                    nodeInfo.QuestionsInfo.Add(questionInfo);
                }

                courseInfo.NodesInfo.Add(nodeInfo);
            }

            return courseInfo;
        }
Ejemplo n.º 6
0
        public virtual int AddCourseInfo(IudicoCourseInfo courseInfo)
        {
            var db = this.GetDbContext();

            CoursesInfo ci = new CoursesInfo
            {
                CourseId = courseInfo.Id,
                OverallMaxScore = (float)courseInfo.OverallMaxScore
            };

            db.CoursesInfo.InsertOnSubmit(ci);
            db.SubmitChanges();

            foreach (IudicoNodeInfo nodeInfo in courseInfo.NodesInfo)
            {
                NodesInfo ni = new NodesInfo
                {
                    CourseId = courseInfo.Id,
                    NodeId = nodeInfo.Id,
                    MaxScore = (float)nodeInfo.MaxScore
                };

                db.NodesInfo.InsertOnSubmit(ni);
                db.SubmitChanges();

                foreach (IudicoQuestionInfo questionInfo in nodeInfo.QuestionsInfo)
                {
                    QuestionsInfo qi = new QuestionsInfo
                    {
                        NodeId = nodeInfo.Id,
                        Text = questionInfo.QuestionText,
                        MaxScore = (float)questionInfo.MaxScore
                    };

                    switch (questionInfo.Type)
                    {
                        case IudicoQuestionType.IudicoSimple:
                            qi.Type = 1;
                            break;

                        case IudicoQuestionType.IudicoChoice:
                            qi.Type = 2;
                            break;

                        case IudicoQuestionType.IudicoCompile:
                            qi.Type = 3;
                            break;
                    }

                    db.QuestionsInfo.InsertOnSubmit(qi);
                    db.SubmitChanges();

                    switch (questionInfo.Type)
                    {
                        case IudicoQuestionType.IudicoSimple:
                            SimpleQuestion sq = new SimpleQuestion
                            {
                                QuestionId = qi.Id,
                                CorrectAnswer = (questionInfo as IudicoSimpleQuestion).CorrectAnswer
                            };

                            db.SimpleQuestions.InsertOnSubmit(sq);
                            db.SubmitChanges();
                            break;

                        case IudicoQuestionType.IudicoChoice:
                            ChoiceQuestionsCorrectChoice cqcc = new ChoiceQuestionsCorrectChoice
                            {
                                QuestionId = qi.Id,
                                CorrectChoice = (questionInfo as IudicoChoiceQuestion).CorrectChoice
                            };

                            db.ChoiceQuestionsCorrectChoices.InsertOnSubmit(cqcc);
                            db.SubmitChanges();

                            foreach (var option in (questionInfo as IudicoChoiceQuestion).Options)
                            {
                                ChoiceQuestionsOption cqo = new ChoiceQuestionsOption
                                {
                                    QuestionId = qi.Id,
                                    Option = option.Item1,
                                    Description = option.Item2
                                };

                                db.ChoiceQuestionsOptions.InsertOnSubmit(cqo);
                                db.SubmitChanges();
                            }
                            break;

                        case IudicoQuestionType.IudicoCompile:
                            for (int i = 0; i < (questionInfo as IudicoCompiledTest).NumberOfTests; ++i)
                            {
                                CompiledTestQuestion ctq = new CompiledTestQuestion
                                {
                                    QuestionId = qi.Id,
                                    TestNumber = i,
                                    TestInput = (questionInfo as IudicoCompiledTest).TestInputs[i].Item2,
                                    TestOutput = (questionInfo as IudicoCompiledTest).TestOutputs[i].Item2
                                };


                                db.CompiledTestQuestions.InsertOnSubmit(ctq);
                                db.SubmitChanges();
                            }
                            break;
                    }
                }
            }

            return courseInfo.Id;
        }