Example #1
0
        public CandidateExamQuestionLogModel FindByQuestionIdAndCandidateExamId(int QuestionId, int CandidateExamId)
        {
            string connectionString             = "server=localhost;uid=root;password=Reset1234;database=OnlineTestManagement;";
            CandidateExamQuestionLogModel model = new CandidateExamQuestionLogModel();
            string queryString =
                "select * from OnlineTestManagement.CandidateExamQuestionsLog where QuestionId=" + QuestionId + " AND CandidateExamId=" + CandidateExamId + "; ";

            using (MySqlConnection connection =
                       new MySqlConnection(connectionString))
            {
                MySqlCommand command =
                    new MySqlCommand(queryString, connection);
                connection.Open();

                MySqlDataReader reader = command.ExecuteReader();

                // Call Read before accessing data.
                while (reader.Read())
                {
                    model.Id              = (int)reader[0];
                    model.Question        = reader[1].ToString();
                    model.SelectedAnswer  = reader[2].ToString();
                    model.IsAnswerCorrect = (Boolean)reader[3];
                    model.CandidateExamId = (int)reader[4];
                    model.QuestionId      = (int)reader[5];
                }

                // Call Close when done reading.
                connection.Close();
            }

            return(model);
        }
        public void SubmitAnswer(int QuestionId, string SelectedAnswer, int CandidateExamId)
        {
            QuestionViewModel             record = _questionRepository.GetQuestionForEdit(QuestionId);
            CandidateExamQuestionLogModel obj    = new CandidateExamQuestionLogModel();

            obj = _candidateExamQuestionLogRepository.FindByQuestionIdAndCandidateExamId(QuestionId, CandidateExamId);
            CandidateExamQuestionLogModel model = new CandidateExamQuestionLogModel()
            {
                Question        = record.Question,
                SelectedAnswer  = SelectedAnswer,
                CandidateExamId = CandidateExamId,
                QuestionId      = QuestionId
            };

            if (SelectedAnswer == record.CorrectAnswer)
            {
                model.IsAnswerCorrect = true;
            }
            else
            {
                model.IsAnswerCorrect = false;
            }
            if (obj.Id == 0)
            {
                _candidateExamQuestionLogRepository.AddLog(model);
            }
            else
            {
                _candidateExamQuestionLogRepository.UpdateLog(model);
            }
            return;
        }
        public CandidateExamModel GetCandidateExamDetails(int id)
        {
            CandidateExamModel model = new CandidateExamModel();

            model = _candidateExamRepository.GetExamDetails(id);
            CandidateDetailsViewModel candidate = _candidateRepository.GetCandidateDetails(model.CandidateId);

            model.CandidateName = candidate.Name;
            TestDetailsViewModel test = _testRepository.GetTestDetails(model.TestId);

            model.TestName = test.Name;
            model.list     = new List <CandidateExamQuestionLogModel>();
            model.list     = _candidateExamQuestionLogRepository.FindByCandidateExamId(id);
            int CorrectAnswers = 0;
            int TotalQuestions = test.QuestionList.Count();

            foreach (var obj in model.list)
            {
                if (obj.IsAnswerCorrect == true)
                {
                    CorrectAnswers = CorrectAnswers + 1;
                }
            }
            model.Score = CorrectAnswers + "/" + TotalQuestions;
            model.TotalNumberOfQuestions = TotalQuestions;
            model.AttemptedQuestions     = model.list.Count();
            model.CorrectAnswers         = CorrectAnswers;
            model.WrongAnswers           = model.list.Count() - CorrectAnswers;

            foreach (var que in test.QuestionList)
            {
                bool IsPresent = false;
                foreach (var item in model.list)
                {
                    if (que.Id == item.QuestionId)
                    {
                        IsPresent = true;
                    }
                }
                if (IsPresent == false)
                {
                    CandidateExamQuestionLogModel rec = new CandidateExamQuestionLogModel();
                    rec.Question        = que.Question;
                    rec.SelectedAnswer  = "NA";
                    rec.IsAnswerCorrect = false;
                    model.list.Add(rec);
                }
            }
            return(model);
        }
Example #4
0
        public void UpdateLog(CandidateExamQuestionLogModel model)
        {
            string connectionString = "server=localhost;uid=root;password=Reset1234;database=OnlineTestManagement;";
            string queryString      =
                "UPDATE OnlineTestManagement.CandidateExamQuestionsLog SET SelectedAnswer = '" + model.SelectedAnswer + "', IsAnswerCorrect = " + model.IsAnswerCorrect + " WHERE QuestionId = " + model.QuestionId + " && CandidateExamId = " + model.CandidateExamId + ";";

            using (MySqlConnection connection =
                       new MySqlConnection(connectionString))
            {
                MySqlCommand command =
                    new MySqlCommand(queryString, connection);
                connection.Open();

                command.ExecuteNonQuery();

                // Call Close when done reading.
                connection.Close();
            }

            return;
        }
Example #5
0
        public void AddLog(CandidateExamQuestionLogModel model)
        {
            string connectionString = "server=localhost;uid=root;password=Reset1234;database=OnlineTestManagement;";
            string queryString      =
                "INSERT INTO OnlineTestManagement.CandidateExamQuestionsLog(Question, SelectedAnswer, IsAnswerCorrect, CandidateExamId, QuestionId) " +
                "VALUES ('" + model.Question + "', '" + model.SelectedAnswer + "', " + model.IsAnswerCorrect + ", " + model.CandidateExamId + ", " + model.QuestionId + ") ";

            using (MySqlConnection connection =
                       new MySqlConnection(connectionString))
            {
                MySqlCommand command =
                    new MySqlCommand(queryString, connection);
                connection.Open();

                command.ExecuteNonQuery();

                // Call Close when done reading.
                connection.Close();
            }

            return;
        }