/// <summary>
 /// Deprecated Method for adding a new object to the TN_ExamUser EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToTN_ExamUser(TN_ExamUser tN_ExamUser)
 {
     base.AddObject("TN_ExamUser", tN_ExamUser);
 }
        public ActionResult ConfirmTest(string ok = "")
        {
            if (Session[SessionKey.UserObject] == null || Session[SessionKey.ExamObject] == null)
            {
                return RedirectToAction("Index", "Home");
            }
            var exam = (TN_Exam)Session[SessionKey.ExamObject];
            var user = (TN_User)Session[SessionKey.UserObject];
            var tnExamUser = new TN_ExamUser()
            {
                JoinDate = DateTime.Now,
                ExamID = exam.ID,
                UserID = user.ID,
                Duration = 0,
                CorrectCount = 0
            };
            db.TN_ExamUser.AddObject(tnExamUser);
            db.SaveChanges();

            Session[SessionKey.ExamUserObject] = tnExamUser;

            // Tạo danh sách câu hỏi cho User
            var listQuestionExam = db.TN_ExamQuestion.Where(m => m.ExamID == exam.ID).ToList();
            if (listQuestionExam.Count > 0)
            {

                if (listQuestionExam.Count == tnExamUser.TN_Exam.QuestionCount)
                {
                    foreach (var item in listQuestionExam)
                    {
                        TN_ExamUserAnswer tnExamUserAnswer = new TN_ExamUserAnswer();
                        tnExamUserAnswer.ExamUserID = tnExamUser.ID;
                        tnExamUserAnswer.QuestionID = item.QuestionID;
                        db.TN_ExamUserAnswer.AddObject(tnExamUserAnswer);
                    }
                    db.SaveChanges();
                }
                else
                {
                    var allQuestion = listQuestionExam.Select(m => m.TN_Question).GroupBy(m => m.Type).ToList();
                    var eachTypeQuestions = Math.Floor((double)exam.QuestionCount / (double)allQuestion.Count);
                    var listQuestion = new List<TN_Question>();
                    foreach (var item in allQuestion)
                    {
                        listQuestion.AddRange(GetRandomListQuestion(item.ToList(), (int)eachTypeQuestions));
                    }
                    foreach (var item in listQuestion)
                    {
                        TN_ExamUserAnswer tnExamUserAnswer = new TN_ExamUserAnswer();
                        tnExamUserAnswer.ExamUserID = tnExamUser.ID;
                        tnExamUserAnswer.QuestionID = item.ID;
                        db.TN_ExamUserAnswer.AddObject(tnExamUserAnswer);
                    }
                    db.SaveChanges();
                }
            }

            return RedirectToAction("Test", "Home");
        }
 /// <summary>
 /// Create a new TN_ExamUser object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="examID">Initial value of the ExamID property.</param>
 /// <param name="userID">Initial value of the UserID property.</param>
 /// <param name="joinDate">Initial value of the JoinDate property.</param>
 /// <param name="duration">Initial value of the Duration property.</param>
 /// <param name="correctCount">Initial value of the CorrectCount property.</param>
 /// <param name="isEnd">Initial value of the IsEnd property.</param>
 public static TN_ExamUser CreateTN_ExamUser(global::System.Int32 id, global::System.Int32 examID, global::System.Int32 userID, global::System.DateTime joinDate, global::System.Int32 duration, global::System.Int32 correctCount, global::System.Boolean isEnd)
 {
     TN_ExamUser tN_ExamUser = new TN_ExamUser();
     tN_ExamUser.ID = id;
     tN_ExamUser.ExamID = examID;
     tN_ExamUser.UserID = userID;
     tN_ExamUser.JoinDate = joinDate;
     tN_ExamUser.Duration = duration;
     tN_ExamUser.CorrectCount = correctCount;
     tN_ExamUser.IsEnd = isEnd;
     return tN_ExamUser;
 }