Esempio n. 1
0
        public ResponseQuestionRadio(Question question, List<int> checkids)
            : base(question, checkids)
        {
            _totalUsersInTest = InTests.Count();
            _ids = InTestDetails.Where(k => checkids.Contains(k.UserInTest.UserID)).Select(i =>
            {
                var listid = new List<int>();
                if (i.AnswerIDs != null)
                {
                    var idStrings = i.AnswerIDs.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
                    idStrings.ForEach(k =>
                    {
                        var tempid = 0;
                        if (int.TryParse(k, out tempid))
                        {
                            listid.Add(tempid);
                        }
                    });
                }
                return listid;
            });
            var rightAnsId = 0;
            var rightAns = question.Answers.FirstOrDefault(k => k.IsRight);
            if (rightAns != null) { rightAnsId = rightAns.AnswerID; }

            var userRightCount = Ids.Count(k => k.Contains(rightAnsId));
            var correctPer = ExtensionModel.SafeDivide(userRightCount, TotalUsersInTest);
            _correctPercent = correctPer.ToPercent();
            _correctPraction = TotalUsersInTest == 0 ? "0" : userRightCount + "/" + TotalUsersInTest;
            var answers = question.Answers.ToList();
            _responseAnswers = new List<ResponseAnswer>();
            answers.ForEach(k =>
            {
                var ans = new ResponseAnswer(this, k);
                _responseAnswers.Add(ans);
            });
        }
Esempio n. 2
0
        public ResponseQuestionMatching(Question question, List<int> checkids)
            : base(question, checkids)
        {
            _totalUsersInTest = InTests.Count();
            _ids = InTestDetails.Where(t => checkids.Contains(t.UserInTest.UserID)).Select(i =>
            {
                var listid = new List<List<int>>();
                if (i.AnswerIDs != null)
                {
                    var idStrings = i.AnswerIDs.Split(';').ToList();
                    idStrings.ForEach(k =>
                    {
                        var twoIdString = k.Split(',').ToList();
                        var twoIds = new List<int>();
                        twoIdString.ForEach(j =>
                        {
                            var tempid = 0;
                            if (int.TryParse(j, out tempid))
                            {
                                twoIds.Add(tempid);
                            }
                        });
                        listid.Add(twoIds);
                    });
                }
                return listid;
            });

            var userRightCount = ListCoupleIds.Count(k => k.All(i =>
            {
                var result = false;
                var firstId = i.ElementAtOrDefault(0);
                var secondId = i.ElementAtOrDefault(1);
                if (firstId != 0)
                {
                    var answer = question.Answers.FirstOrDefault(o => o.AnswerID == firstId);
                    if (answer != null && secondId != 0)
                    {
                        var dependAns = answer.AnswerChilds.FirstOrDefault(q => q.AnswerID == secondId);
                        if (dependAns != null)
                        {
                            result = true;
                        }
                    }
                }
                return result;
            }));
            var correctPer = ExtensionModel.SafeDivide(userRightCount, TotalUsersInTest);
            _correctPercent = correctPer.ToPercent();
            _correctPraction = TotalUsersInTest == 0 ? "0" : userRightCount + "/" + TotalUsersInTest;
            var answers = question.Answers.Where(i => !i.DependencyAnswerID.HasValue).ToList();
            _responseAnswers = new List<ResponseAnswer>();
            answers.ForEach(k =>
            {
                var ans = new ResponseAnswer(this, k);
                _responseAnswers.Add(ans);
            });
        }