public void CreateStudentQuestion(int code) // tạo 1 câu hỏi cho học sinh { List <quests_of_test> qs = (from x in db.quests_of_test // lấy các ra câu hỏi của bài thi theo mã bài thi where x.test_code == code select x).OrderBy(x => Guid.NewGuid()).ToList(); foreach (var item in qs) // với mỗi câu hỏi truyền vào ai làm và đáp án { // truyền vào các thông tin var StudentTest = new student_test_detail(); StudentTest.id_question = item.id_question; // mã câu hỏi StudentTest.test_code = code; // mã bài thi StudentTest.id_student = user.ID; // mã học sinh làm question q = db.questions.SingleOrDefault(x => x.id_question == item.id_question); // truyền vào các lựa chọn của đáp án string[] answer = { q.answer_a, q.answer_b, q.answer_c, q.answer_d }; answer = ShuffleArray.Randomize(answer); StudentTest.answer_a = answer[0]; StudentTest.answer_b = answer[1]; StudentTest.answer_c = answer[2]; StudentTest.answer_d = answer[3]; db.student_test_detail.Add(StudentTest); db.SaveChanges(); } }
public IActionResult CreateStudentQuestion(int code1) { List <quests_of_test> qs = (from x in db.quests_of_test where x.test_code == code1 select x).OrderBy(x => Guid.NewGuid()).ToList(); var rd = new Random(); var list = db.students.ToList(); foreach (var item in qs) { var StudentTest = new student_test_detail(); StudentTest.id_question = item.id_question; StudentTest.test_code = code1; StudentTest.id_student = 1; question q = db.questions.SingleOrDefault(x => x.id_question == item.id_question); string[] answer = { q.answer_a, q.answer_b, q.answer_c, q.answer_d }; answer = ShuffleArray.Randomize(answer); StudentTest.answer_a = answer[0]; StudentTest.answer_b = answer[1]; StudentTest.answer_c = answer[2]; StudentTest.answer_d = answer[3]; db.student_test_detail.Add(StudentTest); db.SaveChanges(); } return(RedirectToAction("DoingTest", new { test_code = code1 })); }
public void CreateStudentQuestion(int code) { List <quests_of_test> qs = (from x in db.quests_of_test where x.test_code == code select x).OrderBy(x => Guid.NewGuid()).ToList(); foreach (var item in qs) { var StudentTest = new student_test_detail(); StudentTest.id_question = item.id_question; StudentTest.test_code = code; StudentTest.id_student = user.ID; question q = db.questions.SingleOrDefault(x => x.id_question == item.id_question); string[] answer = { q.answer_a, q.answer_b, q.answer_c, q.answer_d }; answer = ShuffleArray.Randomize(answer); StudentTest.answer_a = answer[0]; StudentTest.answer_b = answer[1]; StudentTest.answer_c = answer[2]; StudentTest.answer_d = answer[3]; db.student_test_detail.Add(StudentTest); db.SaveChanges(); } }