Esempio n. 1
0
        public void UpToDateAnswerRightState(AnswerABC answ, string question)
        {
            base.OpenConnection();

            SqlCommand cmd = new SqlCommand("SetRightAnswerByAnswer", base._sqlConnection);

            using (cmd)
            {
                cmd.CommandType = CommandType.StoredProcedure;
                SqlParameter param = new SqlParameter();
                param.ParameterName = "@Answer";
                param.SqlDbType     = SqlDbType.VarChar;
                param.Size          = 200;
                param.Value         = answ.AnswerCurrent;
                cmd.Parameters.Add(param);

                param = new SqlParameter();
                param.ParameterName = "@isRight";
                param.SqlDbType     = SqlDbType.Bit;
                param.Value         = answ.IsRight;
                cmd.Parameters.Add(param);

                param = new SqlParameter();
                param.ParameterName = "@Question";
                param.SqlDbType     = SqlDbType.VarChar;
                param.Size          = 200;
                param.Value         = question;
                cmd.Parameters.Add(param);

                cmd.ExecuteNonQuery();
            }

            base.CloseConnection();
        }
Esempio n. 2
0
        public List <AnswerABC> GetAllAnswersByQuestion(string question)
        {
            List <AnswerABC> listAnswers = new List <AnswerABC>();
            AnswerABC        answ        = new AnswerABC();

            string connectionString = ConfigurationManager.ConnectionStrings["csABC_Tests"].ConnectionString;

            base.OpenConnection();

            SqlCommand command = new SqlCommand(string.Format("select Answers.ID, Answers.Answer, Answers.IsRight, Answers.ID_Question from ABC_Tests.dbo.Answers inner join ABC_Tests.dbo.Questions on Answers.ID_Question = Questions.ID where Questions.Question like '{0}'", question), base._sqlConnection);

            SqlDataReader reader = command.ExecuteReader();

            using (reader)
            {
                while (reader.Read())
                {
                    answ.Id            = (int)reader["ID"];
                    answ.AnswerCurrent = reader["Answer"].ToString();
                    answ.IsRight       = (bool)reader["IsRight"];
                    answ.QuestionId    = (int)reader["ID_Question"];
                    listAnswers.Add(answ);
                    answ = new AnswerABC();
                }
            }

            base.CloseConnection();

            return(listAnswers);
        }
Esempio n. 3
0
        private const string ALL_ANSWERS_QUERY = "Select * from Answers"; // put all constants as separated field

        public List <AnswerABC> GetAllAnswers()
        {
            List <AnswerABC> answers = new List <AnswerABC>();
            AnswerABC        answer  = new AnswerABC();

            var connectionString = ConfigurationManager.ConnectionStrings[CONNECTION_NAME].ConnectionString;

            OpenConnection();

            SqlCommand command = new SqlCommand(ALL_ANSWERS_QUERY, base._sqlConnection);

            SqlDataReader reader = command.ExecuteReader();

            using (reader)
            {
                while (reader.Read())
                {
                    answer.Id            = (int)reader["ID"];
                    answer.AnswerCurrent = (string)reader["Answer"] ?? "null";
                    answer.QuestionId    = (int)reader["ID_Qestion"];
                    answer.IsRight       = (bool)reader["IsRight"];

                    answers.Add(answer);
                    answer = new AnswerABC();
                }
            }

            base.CloseConnection();


            return(answers);
        }