Example #1
0
        protected void Page_Init(object sender, EventArgs e)
        {
            var testId = Convert.ToInt32(Request["testId"]);

            Label1.Text = obj.TEST.Single(p => p.TESTID == testId).TESTTITLE;
            if (Session["quest_list"] == null)
            {
                var questions = obj.QUESTION.Where(q => q.TESTID == testId);
                var sa        = new List <int>();
                foreach (var question in questions)
                {
                    sa.Add((int)question.QUESTIONID);
                }
                //var a15 = Operation.GetRandomValues(sa, 15);   //вопрос рандомятся
                Answerss          answerss   = new Answerss();
                Questionss        questionss = new Questionss();
                List <Answerss>   answ_list  = new List <Answerss>();
                List <Questionss> quest_list = new List <Questionss>();
                //foreach (var itemQ in a15)
                foreach (var itemQ in sa)
                {
                    var       QuestionId   = itemQ;
                    var       QuestionText = obj.QUESTION.Single(h => h.TESTID == testId).QUESTIONTEXT;              //текст вопроса
                    var       qa           = obj.QA.Where(l => l.QUESTIONID == QuestionId).ToList();                 // Id всех ответов на вопрос
                    var       ans          = obj.ANSWER.Where(a => qa.Select(l => l.ANSWERID).Contains(a.ANSWERID)); //ответы на вопрос
                    List <QA> qas          = new List <QA>();
                    foreach (var item in ans)
                    {
                        bool?t   = obj.QA.Where(l => l.ANSWERID == item.ANSWERID && l.QUESTIONID == QuestionId).First().CORRECTANSWER;
                        QA   qa1 = new QA()
                        {
                            QUESTIONID    = QuestionId,
                            ANSWERID      = item.ANSWERID,
                            CORRECTANSWER = t,
                            ANSWER        = new ANSWER()
                            {
                                ANSWERID   = item.ANSWERID,
                                ANSWERTEXT = item.ANSWERTEXT,
                                ANSWERNOTE = item.ANSWERNOTE,
                            }
                        };
                        qas.Add(qa1);
                    }
                    foreach (var es in qas)//запись ответов
                    {
                        answerss = new Answerss {
                            TextOtv = es.ANSWER.ANSWERTEXT, AnswerCorrect = es.CORRECTANSWER.Value, QuestionId = es.QUESTIONID.Value
                        };                                                                                                                                   //тип  новый
                        answ_list.Add(answerss);
                    }
                    ;
                    questionss = new Questionss {
                        ID = QuestionId, QuestName = QuestionText, answerss = answ_list                          /*, enumq = enumqs */
                    };                                                                                           //тип"вопросы".
                    quest_list.Add(questionss);
                }
                Session["answ_list"]  = answ_list;
                Session["quest_list"] = quest_list;
                Session["answerss"]   = answerss;
            }
        }
        protected void Page_Init(object sender, EventArgs e)
        {
            if (Session["login"] == null)
            {
                Response.Redirect("Login.aspx");
            }
            else
            {
                lblUserName.Text = Session["login"].ToString();
            }
            var testId = Convert.ToInt32(Request["testId"]);

            Session["testId"] = testId;
            if (Session["testId"] != null)
            {
                testId = (int)Session["testId"];
            }
            Label1.Text = obj.TEST.Single(p => p.TESTID == testId).TESTTITLE;
            if (Session["quest_list"] == null)
            {
                var questions = obj.QUESTION.Where(q => q.TESTID == testId);
                var sa        = new List <int>();
                //int i = 0;
                foreach (var question in questions)
                {
                    sa.Add(question.QUESTIONID);
                    //i++;
                    //if (i == 2) break;
                }
                //var a15 = Operation.GetRandomValues(sa, 15);
                Answerss answerss = new Answerss();

                Questionss        questionss = new Questionss();
                List <Answerss>   answ_list  = new List <Answerss>();
                List <Questionss> quest_list = new List <Questionss>();
                foreach (var itemSa in sa)
                {
                    var       QuestionId   = itemSa;
                    var       QuestionText = obj.QUESTION.Single(h => h.TESTID == testId && h.QUESTIONID == QuestionId).QUESTIONTEXT; //текст вопроса
                    var       qa           = obj.QA.Where(l => l.QUESTIONID == QuestionId).Select(l => l.ANSWERID).ToList();          // Id всех ответов на Question
                    var       ans          = obj.ANSWER.Where(a => qa.Contains(a.ANSWERID)).ToList();                                 //ответы на Question
                    List <QA> qas          = new List <QA>();
                    foreach (var item in ans)
                    {
                        bool?t   = obj.QA.Where(l => l.ANSWERID == item.ANSWERID && l.QUESTIONID == QuestionId).First().CORRECTANSWER;
                        QA   qa1 = new QA()
                        {
                            QUESTIONID    = QuestionId,
                            ANSWERID      = item.ANSWERID,
                            CORRECTANSWER = t,
                            ANSWER        = new ANSWER()
                            {
                                ANSWERID   = item.ANSWERID,
                                ANSWERTEXT = item.ANSWERTEXT,
                                ANSWERNOTE = item.ANSWERNOTE,
                            }
                        };
                        qas.Add(qa1);
                    }
                    foreach (var es in qas)//запись ответов
                    {
                        answerss = new Answerss {
                            AnswerText = es.ANSWER.ANSWERTEXT, IsAnswerCorrect = es.CORRECTANSWER.Value, QuestionId = es.QUESTIONID.Value
                        };                                                                                                                                        //тип  новый
                        answ_list.Add(answerss);
                    }
                    ;
                    questionss = new Questionss {
                        ID = QuestionId, QuestName = QuestionText, answerss = answ_list                          /*, enumq = enumqs */
                    };                                                                                           //тип"вопросы".
                    quest_list.Add(questionss);
                }

                Session["answ_list"]  = answ_list;
                Session["quest_list"] = quest_list;
                Session["answerss"]   = answerss;
            }
        }