public IActionResult Index() { long userId = User.Id(); if (userId < 0) { return(NotFound()); } ViewBag.CompletedTests = _PieceOfTestManager.CompletedTestsCount(userId); ViewBag.PassedTests = _PieceOfTestManager.PassedTestsCount(userId); ViewBag.FaildTests = _PieceOfTestManager.FaildTestsCount(userId); float ListeningGPA = _PieceOfTestManager.CalculateGPA(userId, TestCategory.LISTENING); float ReadingGPA = _PieceOfTestManager.CalculateGPA(userId, TestCategory.READING); float WritingGPA = _PieceOfTestManager.CalculateGPA(userId, TestCategory.WRITING); float SpeakingGPA = _PieceOfTestManager.CalculateGPA(userId, TestCategory.SPEAKING); ViewBag.ListeningGPA = ListeningGPA.ToScores(); ViewBag.ReadingGPA = ReadingGPA.ToScores(); ViewBag.WritingGPA = WritingGPA.ToScores(); ViewBag.SpeakingGPA = SpeakingGPA.ToScores(); ViewBag.GFailed = _PieceOfTestManager.FaildTestsCount(userId, TestCategory.TEST_ALL); ViewBag.GSuccess = _PieceOfTestManager.PassedTestsCount(userId, TestCategory.TEST_ALL); ViewBag.GHighest = _PieceOfTestManager.HightestScore(userId, TestCategory.TEST_ALL); ViewBag.YourGPA = (ListeningGPA + ReadingGPA + WritingGPA + SpeakingGPA).ToScores(); return(View()); }
public IActionResult Index(string type = "ALL", int page = 1, string searchKey = "", int instructorId = -1) { // Truyền gửi tên bảng if (type.ToUpper() == TestCategory.TEST_ALL) { ViewBag.TableName = "GENERAL"; } else { ViewBag.TableName = type.ToUpper(); } ViewBag.SearchKey = searchKey; // Lấy các đếm chuẩn ViewBag.UserTestCountOfAll = _PieceOfTestManager.UserTestCountOfType(User.Id(), "ALL", string.Empty, instructorId); ViewBag.UserTestCountOfListening = _PieceOfTestManager.UserTestCountOfType(User.Id(), TestCategory.LISTENING, string.Empty, instructorId); ViewBag.UserTestCountOfReading = _PieceOfTestManager.UserTestCountOfType(User.Id(), TestCategory.READING, string.Empty, instructorId); ViewBag.UserTestCountOfSpeaking = _PieceOfTestManager.UserTestCountOfType(User.Id(), TestCategory.SPEAKING, string.Empty, instructorId); ViewBag.UserTestCountOfWriting = _PieceOfTestManager.UserTestCountOfType(User.Id(), TestCategory.WRITING, string.Empty, instructorId); ViewBag.UserTestCountOfGeneral = _PieceOfTestManager.UserTestCountOfType(User.Id(), TestCategory.TEST_ALL, string.Empty, instructorId); // Tiến hành cấu hình phân trang int start = (page - 1) * Config.PAGE_PAGINATION_LIMIT; // Lấy danh sách IEnumerable <PieceOfTest> PieceOfTests = _PieceOfTestManager.GetByPagination(User.Id(), type, start, Config.PAGE_PAGINATION_LIMIT, searchKey, instructorId); // Tạo đối tượng phân trang ViewBag.Pagination = new Pagination(nameof(Index), NameUtils.ControllerName <TestController>()) { PageCurrent = page, Type = type, NumberPage = PaginationUtils.TotalPageCount( _PieceOfTestManager.UserTestCountOfType( User.Id(), type.ToUpper().Trim(), searchKey, instructorId ).ToInt(), Config.PAGE_PAGINATION_LIMIT ), Offset = Config.PAGE_PAGINATION_LIMIT }; // Lấy GVHD nếu có if (instructorId > 0) { ViewBag.Instructor = _UserManager.Get(instructorId); } if (type == "ALL") { type = string.Empty; } // Thực hiện phần thống kê nho nhỏ ViewBag.Passed = _PieceOfTestManager.PassedTestsCount(User.Id(), type); ViewBag.Failed = _PieceOfTestManager.FaildTestsCount(User.Id(), type); ViewBag.HighestScore = _PieceOfTestManager.HightestScore(User.Id(), type).ToScores(); return(View(PieceOfTests)); }