public IActionResult GeneralNewTest(int?id)
        {
            // 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
            int PiceOfTestId = GeneralTestPaper.Generate(
                _TestCategoryManager,
                _ReadingPartOneManager,
                _ReadingPartTwoManager,
                _ListeningBaseQuestionManager,
                _ListeningMediaManager,
                _WritingPartTwoManager,
                _SpeakingEmbedManager,
                _PieceOfTestManager,
                User.Id(),
                id).PieceOfTestId;

            if (PiceOfTestId > 0)
            {
                // Nếu lưu trữ thành công, thì tiến hành cho thí sinh làm
                return(RedirectToAction(nameof(General), new { id = PiceOfTestId }));
            }
            else
            {
                // Không thì trả về trang Index
                return(RedirectToAction(nameof(Index)));
            }
        }
        public IActionResult GeneralReview(int id)
        {
            if (id <= 0)
            {
                return(NotFoundTest());
            }

            ViewBag.Title = "GENERAL 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
            GeneralTestPaper userPaper = JsonConvert.DeserializeObject <GeneralTestPaper>(piece.ResultOfUserJson ?? "");
            // Bài thi mẫu (Được tạo khi thi, của học viên)
            GeneralTestPaper resultPaper = JsonConvert.DeserializeObject <GeneralTestPaper>(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(General), 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));
        }
예제 #4
0
        public IActionResult CheckFullGeneral(GeneralTestPaper paper, string audioBase64)
        {
            string message = paper.IsFullAnswers();

            bool status = string.IsNullOrEmpty(message);

            if (string.IsNullOrEmpty(audioBase64))
            {
                message = "\r\nYou have not recorded the audio yet";
                status  = false;
            }

            return(Json(new { status, message }));
        }
예제 #5
0
        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}" }));
        }
예제 #8
0
        public IActionResult SubmitToolResultForGeneral(GeneralTestPaper gtp, string InstructorComments = "")
        {
            // Định nghĩa đích đến
            var dest = RedirectToAction(nameof(TestPaperController.ReviewHandler), NameUtils.ControllerName <TestPaperController>(), new { id = gtp.PieceOfTestId });

            // Nếu không xác định được bài thi
            if (gtp == null || gtp.PieceOfTestId <= 0)
            {
                this.NotifyError("Cannot determine the test");
                return(dest);
            }

            // Nếu nội dung đánh giá cho writing rỗng
            if (gtp.WritingTestPaper == null || gtp.WritingTestPaper.WritingPartTwos == null || string.IsNullOrEmpty(gtp.WritingTestPaper.WritingPartTwos.TeacherReviewParagraph))
            {
                this.NotifyError("You must correct paragraph for your student");
                return(dest);
            }

            // Nếu chưa cho điểm bài thi viết
            if (gtp.WritingTestPaper.WritingPartTwos.Scores < 0 || gtp.WritingTestPaper.WritingPartTwos.Scores > Config.SCORES_FULL_WRITING_PART_2)
            {
                this.NotifyError("Writing part 2 Score invalid");
                return(dest);
            }

            // Nếu chưa cho điểm bài thi nói
            if (gtp.SpeakingTestPaper.SpeakingPart.Scores < 0 || gtp.SpeakingTestPaper.SpeakingPart.Scores > Config.SCORES_FULL_SPEAKING)
            {
                this.NotifyError("Speaking Score invalid");
                return(dest);
            }

            // Nếu tất cả đã hợp lệ, tiến hành lấy bản ghi dữ liệu bài thi
            var pot = _PieceOfTestManager.Get(gtp.PieceOfTestId);

            // Lấy dữ liệu gốc của bài thi
            GeneralTestPaper _gtp = JsonConvert.DeserializeObject <GeneralTestPaper>(pot.ResultOfUserJson);

            // Cập nhật điểm và review part 2 của writing
            _gtp.WritingTestPaper.WritingPartTwos.TeacherReviewParagraph = gtp.WritingTestPaper.WritingPartTwos.TeacherReviewParagraph;
            _gtp.WritingTestPaper.WritingPartTwos.Scores = gtp.WritingTestPaper.WritingPartTwos.Scores;

            // Cập nhật điểm cho speaking
            _gtp.SpeakingTestPaper.SpeakingPart.Scores = gtp.SpeakingTestPaper.SpeakingPart.Scores;

            // Lưu lại json
            pot.ResultOfUserJson = JsonConvert.SerializeObject(_gtp);

            // Cập nhật lại comment nếu có
            if (!string.IsNullOrEmpty(InstructorComments))
            {
                pot.InstructorComments = InstructorComments;
            }

            // Tổng điểm lại
            pot.Scores = 0;
            if (_gtp.ListeningTestPaper.Part1Scores >= 0)
            {
                pot.Scores += _gtp.ListeningTestPaper.Part1Scores;
            }

            if (_gtp.ListeningTestPaper.Part2Scores >= 0)
            {
                pot.Scores += _gtp.ListeningTestPaper.Part2Scores;
            }

            if (_gtp.ReadingTestPaper.ReadingPartOnes.Scores >= 0)
            {
                pot.Scores += _gtp.ReadingTestPaper.ReadingPartOnes.Scores;
            }

            if (_gtp.ReadingTestPaper.ReadingPartTwos.Scores >= 0)
            {
                pot.Scores += _gtp.ReadingTestPaper.ReadingPartTwos.Scores;
            }

            if (_gtp.ReadingTestPaper.ReadingPartThrees.Scores >= 0)
            {
                pot.Scores += _gtp.ReadingTestPaper.ReadingPartThrees.Scores;
            }

            if (_gtp.ReadingTestPaper.ReadingPartFours.Scores >= 0)
            {
                pot.Scores += _gtp.ReadingTestPaper.ReadingPartFours.Scores;
            }

            if (_gtp.WritingTestPaper.WritingPartOnes.Scores >= 0)
            {
                pot.Scores += _gtp.WritingTestPaper.WritingPartOnes.Scores;
            }

            if (_gtp.WritingTestPaper.WritingPartTwos.Scores >= 0)
            {
                pot.Scores += _gtp.WritingTestPaper.WritingPartTwos.Scores;
            }

            if (_gtp.SpeakingTestPaper.SpeakingPart.Scores >= 0)
            {
                pot.Scores += _gtp.SpeakingTestPaper.SpeakingPart.Scores;
            }

            // Cập nhật vào CSDL
            _PieceOfTestManager.Update(pot);

            // Gửi thông báo thành công
            this.NotifySuccess("Update your review to student success!");

            // Về điểm đích đã khai báo
            return(dest);
        }