public static int GenerateReadingTestPaper( this TestCategoryManager _TestCategoryManager, PieceOfTestManager _PieceOfTestManager, ReadingPartOneManager _ReadingPartOneManager, ReadingPartTwoManager _ReadingPartTwoManager, int UserId, int?InstructorId) { // Kiến tạo danh sách câu hỏi và câu trả lời, đồng thời xáo trộn câu trả lời ReadingTestPaper paper = _TestCategoryManager.GenerateReadingTestPaper(_ReadingPartOneManager, _ReadingPartTwoManager); // Khởi tạo đối tượng lưu trữ bài kiểm tra này và lưu paper mặc định có đáp án đúng vào var piceOfTest = new PieceOfTest { UserId = UserId, InstructorId = InstructorId, TypeCode = TestCategory.READING, PartId = -1, ResultOfTestJson = JsonConvert.SerializeObject(paper), }; // Lưu trữ bài thi vào database trước khi bắt đầu _PieceOfTestManager.Add(piceOfTest); return(piceOfTest.Id); }
public void SubmitToolResultForWriting(PieceOfTest pot, WritingTestPaper.WritingPartTwoDTO wp2DTO) { // Nếu nội dung đánh giá rỗng if (wp2DTO == null || string.IsNullOrEmpty(wp2DTO.TeacherReviewParagraph)) { this.NotifyError("You must correct paragraph for your student"); return; } // Điểm cho bài thi if (wp2DTO.Scores < 0 || wp2DTO.Scores > Config.SCORES_FULL_WRITING_PART_2) { this.NotifyError("Score invalid"); return; } // Lấy dữ liệu gốc var constWtp = JsonConvert.DeserializeObject <WritingTestPaper>(pot.ResultOfUserJson) as WritingTestPaper; // Cập nhật điểm số mới pot.Scores = constWtp.WritingPartOnes.Scores + wp2DTO.Scores; // Cập nhật điểm số constWtp.WritingPartTwos.Scores = wp2DTO.Scores; constWtp.WritingPartTwos.TeacherReviewParagraph = wp2DTO.TeacherReviewParagraph; // Lưu lại json pot.ResultOfUserJson = JsonConvert.SerializeObject(constWtp); }
public IActionResult LoadInstructorComments(int id) { if (id <= 0) { return(Content(string.Empty)); } // Lấy bài thi theo mã PieceOfTest piece = _PieceOfTestManager.Get(id); // Nếu không có, trả về if (piece == null) { return(Content(string.Empty)); } // Nếu không có nội dung đánh giá if (string.IsNullOrEmpty(piece.InstructorComments)) { return(Content(string.Empty)); } // Trả về nội dung đánh giá return(Content(piece.InstructorComments)); }
public IActionResult SubmitToolResult(PieceOfTest pot, WritingTestPaper.WritingPartTwoDTO wp2) { // Định nghĩa đích đến var dest = RedirectToAction(nameof(TestPaperController.ReviewHandler), NameUtils.ControllerName <TestPaperController>(), new { id = pot.Id }); // Nếu không xác định được bài thi if (pot == null || pot.Id <= 0) { this.NotifyError("Cannot determine the test"); return(dest); } // Nếu nội dung đánh giá rỗng if (string.IsNullOrEmpty(pot.InstructorComments)) { this.NotifyError("Please leave your rating for this test."); return(dest); } // Nếu chưa cung cấp điểm cho bài nói của sinh viên if (pot.Scores < 0) { this.NotifyError("Please give the student a score."); return(dest); } // Nếu điểm quá lớn, thông báo if (pot.Scores > Config.SCORES_FULL_SPEAKING) { this.NotifyError("Cannot cheat student scores."); return(dest); } // Nếu tất cả đã hợp lệ, tiến hành lấy bản ghi var potRaw = _PieceOfTestManager.Get(pot.Id); // Cập nhật dữ liệu mới potRaw.InstructorComments = pot.InstructorComments; // Nếu là bài nói, Cập nhật điểm cho HV if (potRaw.TypeCode == TestCategory.SPEAKING) { potRaw.Scores = pot.Scores; } // Nếu là bài viết, cập nhập if (potRaw.TypeCode == TestCategory.WRITING) { SubmitToolResultForWriting(potRaw, wp2); } // Cập nhật vào CSDL _PieceOfTestManager.Update(potRaw); // Gửi thông báo thành công this.NotifySuccess("Update your evaluate success!"); // Về điểm đích đã khai báo return(dest); }
public static int GenerateListeningTestPaper( this TestCategoryManager _TestCategoryManager, ListeningMediaManager _ListeningMediaManager, ListeningBaseQuestionManager _ListeningBaseQuestionManager, PieceOfTestManager _PieceOfTestManager, int UserId, int?InstructorId) { // Kiến tạo danh sách câu hỏi và câu trả lời, đồng thời xáo trộn câu trả lời var paper = new ListeningTestPaper { ListeningPartOnes = ListeningTestPaper.Generate(1, _TestCategoryManager, _ListeningMediaManager, _ListeningBaseQuestionManager), ListeningPartTwos = ListeningTestPaper.Generate(2, _TestCategoryManager, _ListeningMediaManager, _ListeningBaseQuestionManager), }; // Khởi tạo đối tượng lưu trữ bài kiểm tra này và lưu paper mặc định có đáp án đúng vào var piceOfTest = new PieceOfTest { UserId = UserId, InstructorId = InstructorId, TypeCode = TestCategory.LISTENING, PartId = -1, ResultOfTestJson = JsonConvert.SerializeObject(paper), }; // Lưu trữ bài thi vào database trước khi bắt đầu _PieceOfTestManager.Add(piceOfTest); // Xóa đáp án đúng trong paper return(piceOfTest.Id); }
public IActionResult ListeningReview(int id) { if (id <= 0) { return(NotFoundTest()); } ViewBag.Title = "LISTENING TESTING"; ViewBag.IsReviewMode = true; // Sau khi hoàn tất lọc các lỗi, tiến hành lấy PieceOfTest piece = _PieceOfTestManager.Get(id); if (piece == null) { return(NotFoundTest()); } if (piece.InstructorId != User.Id() && piece.UserId != User.Id()) { this.NotifyError("You are not authorized to view or manipulate this test"); return(RedirectToAction(nameof(HomeController.Index), NameUtils.ControllerName <HomeController>())); } // Lấy chủ sở hữu của bài kiểm tra User owner = _UserManager.Get(piece.UserId); ViewData["Owner"] = new User { Avatar = owner.Avatar, FirstName = owner.FirstName, LastName = owner.LastName }; // Thời gian làm bài ViewBag.Timer = piece.TimeToFinished; // Điểm của bài thi ViewBag.Scores = piece.Scores; // Bài thi của học viên ListeningTestPaper userPaper = JsonConvert.DeserializeObject <ListeningTestPaper>(piece.ResultOfUserJson ?? ""); // Bài thi mẫu (Được tạo khi thi, của học viên) ListeningTestPaper resultPaper = JsonConvert.DeserializeObject <ListeningTestPaper>(piece.ResultOfTestJson ?? ""); bool isReviewOfFailTest = piece.ResultOfUserJson == null || piece.ResultOfUserJson.Length <= 0 || piece.UpdatedTime == null; ViewBag.IsReviewOfFailTest = isReviewOfFailTest; ViewBag.ResultPaper = resultPaper; if (isReviewOfFailTest) { userPaper = resultPaper; } return(View(nameof(Listening), userPaper)); }
public IActionResult General(int id) { ViewBag.Title = "GENERAL TESTING"; if (id <= 0) { return(NotFoundTest()); } // Sau khi hoàn tất lọc các lỗi, tiến hành xử lý, đếm số câu đúng PieceOfTest piece = _PieceOfTestManager.Get(id); // Nếu tìm không thấy bài Test if (piece == null) { return(NotFoundTest()); } if (piece.InstructorId != User.Id() && piece.UserId != User.Id()) { this.NotifyError("You are not authorized to view or manipulate this test"); return(RedirectToAction(nameof(HomeController.Index), NameUtils.ControllerName <HomeController>())); } // Lấy chủ sở hữu của bài kiểm tra User owner = _UserManager.Get(piece.UserId); ViewData["Owner"] = new User { Avatar = owner.Avatar, FirstName = owner.FirstName, LastName = owner.LastName }; // Nếu bài thi đã hoàn thành, thì chuyển sang màn hình review if (piece.ResultOfUserJson != null && piece.ResultOfUserJson.Length > 0 && piece.UpdatedTime != null) { return(RedirectToAction(nameof(GeneralReview), new { id })); } // Tránh timer bị reset if (piece.CreatedTime != null) { ViewBag.Timer = DateTime.UtcNow.Subtract((DateTime)piece.CreatedTime).TotalSeconds; } // Giải mã thành giữ liệu bài thi GeneralTestPaper paper = JsonConvert.DeserializeObject <GeneralTestPaper>(piece.ResultOfTestJson); // Gắn mã dữ liệu paper.PieceOfTestId = piece.Id; // Xóa đáp án của bài thi paper.ClearTrueAnswers(); this.NotifySuccess("Try your best, Good Luck!"); return(View(paper)); }
public IActionResult Speaking(int id) { ViewBag.Title = "SPEAKING TESTING"; if (id <= 0) { return(NotFoundTest()); } PieceOfTest piece = _PieceOfTestManager.Get(id); // Nếu tìm không thấy bài Test if (piece == null) { return(NotFoundTest()); } if (piece.InstructorId != User.Id() && piece.UserId != User.Id()) { this.NotifyError("You are not authorized to view or manipulate this test"); return(RedirectToAction(nameof(HomeController.Index), NameUtils.ControllerName <HomeController>())); } // Lấy chủ sở hữu của bài kiểm tra User owner = _UserManager.Get(piece.UserId); ViewData["Owner"] = new User { Avatar = owner.Avatar, FirstName = owner.FirstName, LastName = owner.LastName }; // Nếu bài thi đã hoàn thành, thì chuyển sang màn hình review if (piece.ResultOfUserJson != null && piece.ResultOfUserJson.Length > 0 && piece.UpdatedTime != null) { return(RedirectToAction(nameof(SpeakingReview), new { id })); } // Tránh timer bị reset if (piece.CreatedTime != null) { ViewBag.Timer = DateTime.UtcNow.Subtract((DateTime)piece.CreatedTime).TotalSeconds; } SpeakingTestPaper paper = JsonConvert.DeserializeObject <SpeakingTestPaper>(piece.ResultOfTestJson); paper.PiceOfTestId = piece.Id; this.NotifySuccess("Try your best, Good Luck!"); return(View(paper)); }
public IActionResult Listening(ListeningTestPaper paper) { if (paper == null) { this.NotifyError("Not found yor test"); return(Json(new { status = false, message = string.Empty, location = "/" })); } if (paper.PiceOfTestId <= 0) { this.NotifyError("Not found yor test"); return(Json(new { status = false, message = string.Empty, location = "/" })); } // Sau khi hoàn tất lọc các lỗi, tiến hành xử lý, đếm số câu đúng PieceOfTest piece = _PieceOfTestManager.Get(paper.PiceOfTestId); if (piece == null) { this.NotifyError("Not found yor test"); return(Json(new { status = false, message = string.Empty, location = "/" })); } if (piece.InstructorId != User.Id() && piece.UserId != User.Id()) { this.NotifyError("You are not authorized to view or manipulate this test"); return(Json(new { status = false, message = string.Empty, location = "/" })); } int total = paper.TotalQuestions(); // Tổng số câu hỏi if (total <= 0) { return(Json(new { status = false, message = "The test does not have any questions", location = string.Empty })); } // Tính toán số điểm float scores = paper.ScoreCalculate(piece.ResultOfTestJson); // Thời gian kết thúc bài thi float timeToFinished = DateTime.UtcNow.Subtract((DateTime)piece.CreatedTime).TotalSeconds.ToFloat(); // Cập nhật dữ liệu piece.ResultOfUserJson = JsonConvert.SerializeObject(paper); piece.Scores = scores; piece.TimeToFinished = timeToFinished; _PieceOfTestManager.Update(piece); // Chuyển đến trang kết quả return(Json(new { status = true, message = "Successful submission of exams", location = $"{Url.Action(nameof(Result), NameUtils.ControllerName<TestPaperController>())}/{piece.Id}" })); }
/// <summary> /// Phương thức tạo bài thi tổng quát /// </summary> public static GeneralTestPaper Generate( TestCategoryManager _TestCategoryManager, ReadingPartOneManager _ReadingPartOneManager, ReadingPartTwoManager _ReadingPartTwoManager, ListeningBaseQuestionManager _ListeningBaseQuestionManager, ListeningMediaManager _ListeningMediaManager, WritingPartTwoManager _WritingPartTwoManager, SpeakingEmbedManager _SpeakingEmbedManager, PieceOfTestManager _PieceOfTestManager, int UserId, int?InstructorId) { GeneralTestPaper generateTestPaper = new GeneralTestPaper { // Tạo bài thi Listening ListeningTestPaper = new ListeningTestPaper { ListeningPartOnes = ListeningTestPaper.Generate(1, _TestCategoryManager, _ListeningMediaManager, _ListeningBaseQuestionManager), ListeningPartTwos = ListeningTestPaper.Generate(2, _TestCategoryManager, _ListeningMediaManager, _ListeningBaseQuestionManager), }, // Kiến tạo danh sách câu hỏi và câu trả lời, đồng thời xáo trộn câu trả lời ReadingTestPaper = _TestCategoryManager.GenerateReadingTestPaper(_ReadingPartOneManager, _ReadingPartTwoManager), // Kiến tạo danh sách câu hỏi và câu trả lời, đồng thời xáo trộn câu trả lời WritingTestPaper = _TestCategoryManager.GenerateWritingTestPaper(_WritingPartTwoManager), // Kiến tạo danh sách câu hỏi và câu trả lời, đồng thời xáo trộn câu trả lời SpeakingTestPaper = _TestCategoryManager.GenerateSpeakingTestPaper(_SpeakingEmbedManager) }; // Khởi tạo đối tượng lưu trữ bài kiểm tra này và lưu paper mặc định có đáp án đúng vào var piceOfTest = new PieceOfTest { UserId = UserId, InstructorId = InstructorId, TypeCode = TestCategory.TEST_ALL, PartId = -1, ResultOfTestJson = JsonConvert.SerializeObject(generateTestPaper), Scores = -1 }; // Lưu trữ bài thi vào database trước khi bắt đầu _PieceOfTestManager.Add(piceOfTest); // Lưu mã bài thi vào generateTestPaper.PieceOfTestId = piceOfTest.Id; return(generateTestPaper); }
public IViewComponentResult InvokeForGeneralTest(int pieceOfTestId) { // Lấy bài thi theo mã cho trước PieceOfTest pot = _PieceOfTestManager.Get(pieceOfTestId); // Nếu đây là bài hỏng của học viên if (string.IsNullOrEmpty(pot.ResultOfUserJson)) { return(View("GeneralTools")); } // Lấy đối tượng bài thi chung GeneralTestPaper gtp = JsonConvert.DeserializeObject <GeneralTestPaper>(pot.ResultOfUserJson); // Gắn bài thi vô đối tượng biến tạm ViewBag.POT = _PieceOfTestManager.GetForInstructorTool(pieceOfTestId);; // Khởi tạo đoạn văn chấm cho GV nếu chưa có if (string.IsNullOrEmpty(gtp.WritingTestPaper.WritingPartTwos.TeacherReviewParagraph)) { gtp.WritingTestPaper.WritingPartTwos.TeacherReviewParagraph = gtp.WritingTestPaper.WritingPartTwos.UserParagraph; } return(View("GeneralTools", new GeneralTestPaper { PieceOfTestId = gtp.PieceOfTestId, WritingTestPaper = new WritingTestPaper { WritingPartTwos = new WritingTestPaper.WritingPartTwoDTO { TeacherReviewParagraph = gtp.WritingTestPaper.WritingPartTwos.TeacherReviewParagraph, Scores = gtp.WritingTestPaper.WritingPartTwos.Scores } }, SpeakingTestPaper = new SpeakingTestPaper { SpeakingPart = new SpeakingDTO { Scores = gtp.SpeakingTestPaper.SpeakingPart.Scores } } })); }
public IActionResult LoadTranscript([FromQuery] int id, [FromQuery] int mediaId) { if (id <= 0 || mediaId <= 0) { return(Content(string.Empty)); } // Lấy bài thi theo mã PieceOfTest piece = _PieceOfTestManager.Get(id); // Nếu không có, trả về if (piece == null) { return(Content(string.Empty)); } if (piece.TypeCode == TestCategory.TEST_ALL) { // Lấy trang giấy thi GeneralTestPaper paper = JsonConvert.DeserializeObject <GeneralTestPaper>(piece.ResultOfTestJson); // Nếu trang giấy rỗng if (paper == null) { return(Content(string.Empty)); } // Cố gắng tìm kiếm transcript ở part 1 if (paper.ListeningTestPaper.ListeningPartOnes != null && paper.ListeningTestPaper.ListeningPartOnes.Any(x => x.ListeningMedia.Id == mediaId)) { return(Content(paper.ListeningTestPaper.ListeningPartOnes.Where(x => x.ListeningMedia.Id == mediaId).FirstOrDefault()?.ListeningMedia?.Transcript ?? "")); } // Cố gắng tìm kiếm transcript ở part 2 if (paper.ListeningTestPaper.ListeningPartTwos != null && paper.ListeningTestPaper.ListeningPartTwos.Any(x => x.ListeningMedia.Id == mediaId)) { return(Content(paper.ListeningTestPaper.ListeningPartTwos.Where(x => x.ListeningMedia.Id == mediaId).FirstOrDefault()?.ListeningMedia?.Transcript ?? "")); } } else { // Lấy trang giấy thi ListeningTestPaper paper = JsonConvert.DeserializeObject <ListeningTestPaper>(piece.ResultOfTestJson); // Nếu trang giấy rỗng if (paper == null) { return(Content(string.Empty)); } // Cố gắng tìm kiếm transcript ở part 1 if (paper.ListeningPartOnes != null && paper.ListeningPartOnes.Any(x => x.ListeningMedia.Id == mediaId)) { return(Content(paper.ListeningPartOnes.Where(x => x.ListeningMedia.Id == mediaId).FirstOrDefault()?.ListeningMedia?.Transcript ?? "")); } // Cố gắng tìm kiếm transcript ở part 2 if (paper.ListeningPartTwos != null && paper.ListeningPartTwos.Any(x => x.ListeningMedia.Id == mediaId)) { return(Content(paper.ListeningPartTwos.Where(x => x.ListeningMedia.Id == mediaId).FirstOrDefault()?.ListeningMedia?.Transcript ?? "")); } } // Nếu cũng không có thì trả về rỗng return(Content(string.Empty)); }
public async Task <IActionResult> General(GeneralTestPaper paper, string audioBase64) { if (paper == null) { this.NotifyError("Not found yor test"); return(Json(new { status = false, message = string.Empty, location = "/" })); } if (paper.PieceOfTestId <= 0) { this.NotifyError("Not found yor test"); return(Json(new { status = false, message = string.Empty, location = "/" })); } // Lấy bài thi từ mã số PieceOfTest piece = _PieceOfTestManager.Get(paper.PieceOfTestId); if (piece == null) { this.NotifyError("Not found yor test"); return(Json(new { status = false, message = string.Empty, location = "/" })); } if (piece.InstructorId != User.Id() && piece.UserId != User.Id()) { this.NotifyError("You are not authorized to view or manipulate this test"); return(Json(new { status = false, message = string.Empty, location = "/" })); } // Lấy chủ sở hữu của bài kiểm tra User owner = _UserManager.Get(piece.UserId); string fileName = $"{owner.Username.ToLower()}_{piece.TypeCode}_{piece.Id}"; if (!string.IsNullOrEmpty(audioBase64)) { // Chuyển base64 thành stream var bytes = Convert.FromBase64String(audioBase64.Replace("data:audio/mpeg;base64,", "")); var memoryStream = new MemoryStream(bytes); // Tạo tệp tin IFormFile file = new FormFile(memoryStream, 0, bytes.Length, null, $"{fileName}.mp3") { Headers = new HeaderDictionary(), ContentType = "audio/mpeg" }; // Nếu file null if (file == null) { return(Json(new { status = false, message = "Can not upload your audio, please try again!", location = "/" })); } // Tiến hành lưu tệp tin cho người dùng string path = await host.UploadForUserAudio(file, owner); // Nếu path không đúng if (string.IsNullOrEmpty(path)) { return(Json(new { status = false, message = "Can not upload your audio, please try again!", location = "/" })); } // Cập nhật đường dẫn bài nói của HV cho bài thi paper.SpeakingTestPaper.SpeakingPart.UserAudioPath = path; } // Tính toán số điểm paper.ScoreCalculate(piece.ResultOfTestJson); // Thời gian kết thúc bài thi float timeToFinished = DateTime.UtcNow.Subtract((DateTime)piece.CreatedTime).TotalSeconds.ToFloat(); // Cập nhật dữ liệu piece.ResultOfUserJson = JsonConvert.SerializeObject(paper); piece.TimeToFinished = timeToFinished; _PieceOfTestManager.Update(piece); // Chuyển đến trang kết quả return(Json(new { status = true, message = "Successful submission of exams", location = $"{Url.Action(nameof(Result), NameUtils.ControllerName<TestPaperController>())}/{piece.Id}" })); }