public CandidateExamWrapperModel GetAllSubmittedTests() { string connectionString = "server=localhost;uid=root;password=Reset1234;database=OnlineTestManagement;"; string querryString = "select * from OnlineTestManagement.CandidateExam where IsTestEnded = true"; CandidateExamWrapperModel model = new CandidateExamWrapperModel(); model.CandidateExamList = new List <CandidateExamModel>(); using (MySqlConnection connection = new MySqlConnection(connectionString)) { MySqlCommand command = new MySqlCommand(querryString, connection); connection.Open(); MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { CandidateExamModel obj = new CandidateExamModel(); obj.Id = (int)reader[0]; obj.StartedTime = (DateTime)reader[1]; obj.SubmittedTime = (DateTime)reader[2]; obj.IsTestEnded = (bool)reader[3]; obj.TestId = (int)reader[4]; obj.CandidateId = (int)reader[5]; model.CandidateExamList.Add(obj); } connection.Close(); } return(model); }
public CandidateExamWrapperModel GetCandidateExamList() { CandidateExamWrapperModel model = new CandidateExamWrapperModel(); model = _candidateExamRepository.GetAllSubmittedTests(); foreach (var rec in model.CandidateExamList) { CandidateDetailsViewModel candidate = _candidateRepository.GetCandidateDetails(rec.CandidateId); rec.CandidateName = candidate.Name; TestDetailsViewModel test = _testRepository.GetTestDetails(rec.TestId); rec.TestName = test.Name; List <CandidateExamQuestionLogModel> list = _candidateExamQuestionLogRepository.FindByCandidateExamId(rec.Id); int CorrectAnswers = 0; int TotalQuestions = test.QuestionList.Count(); foreach (var obj in list) { if (obj.IsAnswerCorrect == true) { CorrectAnswers = CorrectAnswers + 1; } } rec.Score = CorrectAnswers + "/" + TotalQuestions; } return(model); }
public IActionResult Index() { CandidateExamWrapperModel model = _resultService.GetCandidateExamList(); return(View(model)); }