예제 #1
0
        // GET: QuestionAnswers/Create
        public ActionResult loadQuiz(int id)
        {
            QuizQuestionAnswers qqa = new QuizQuestionAnswers();

            qqa.quizId = id;
            quiz quiz = qz.GetById(id);

            var questions = qts.GetMany().Where(x => x.quiz_id_Quiz.Equals(quiz.id_Quiz));

            qqa.Questions = new List <questionModel>();
            qqa.answers   = new List <answerModel>();
            foreach (question quest in questions)
            {
                questionModel questionModel = new questionModel();
                questionModel.id_Question          = quest.id_Question;
                questionModel.question_name        = quest.question_name;
                questionModel.question_description = quest.question_description;
                questionModel.userchoice           = null;

                var answers = ans.GetMany().Where(x => x.question_id_Question.Equals(quest.id_Question));


                foreach (answer answ in answers)
                {
                    answerModel answerModel = new answerModel();
                    answerModel.id_Answer            = answ.id_Answer;
                    answerModel.question_id_Question = answ.question_id_Question;
                    answerModel.answer_name          = answ.answer_name;
                    answerModel.flag = answ.flag;

                    qqa.answers.Add(answerModel);
                }

                qqa.Questions.Add(questionModel);
            }


            return(View(qqa));
        }
예제 #2
0
        public ActionResult loadQuiz(QuizQuestionAnswers qqa)
        {
            try
            {
                //TempData["score"] = 0;
                //TempData["score_quest"] = 0;
                if (qqa != null)
                {
                    quiz         quiz         = qz.GetById((int)qqa.quizId);
                    var          id           = quiz.id_Quiz;
                    var          questions    = qqa.Questions;
                    var          answers      = qqa.answers;
                    List <float> scores       = new List <float>();
                    List <float> score_quests = new List <float>();
                    //  quiz.Result = 0;


                    foreach (var quest in questions)
                    {
                        var      qId = quest.id_Question;
                        question q   = new question();
                        q            = qts.GetById(qId);
                        q.userchoice = quest.userchoice;
                        qts.Commit();
                        //quest.userchoice= questions.Find(x=>x.id_Question==qId).userchoice;

                        // foreach (var answ in answers)
                        //{
                        //answer s = new answer();
                        //s = ans.GetById(answ.id_Answer);
                        // s.id_Answer = answ.id_Answer;
                        //  s.flag = answ.flag;
                        //  s.question_id_Question = answ.question_id_Question;

                        if (q.userchoice.Equals(true))
                        {
                            score += 100 / questions.Count();
                        }
                        score = score + 0;
                        // }
                        // score_quests.Add(scores.Sum());
                        //TempData["score_quest"] = Convert.ToInt32(TempData["score"]) + Convert.ToInt32(TempData["score_quest"]);
                    }

                    qqa.score = (int)score;


                    // quiz.Result+= Convert.ToInt32(TempData["score_quest"]);
                    quiz.Result = qqa.score;
                    qz.Commit();

                    SendEmail(quiz.Result);
                    // qz.Update(quiz);



                    return(RedirectToAction("Details", new { id = qqa.quizId, otherParam = score_quests.Sum() }));
                    //   return RedirectToAction("Index");
                    // return View(quiz);
                }
                else
                {
                    return(new HttpNotFoundResult());
                }
            }

            catch
            {
                return(View());
            }
        }