public List <QuestionSessionDTO> GetAllQuestionSessions()
        {
            List <QuestionSessionDTO> questionList = new List <QuestionSessionDTO>();

            using (SqlConnection con = new SqlConnection(connectionString))
            {
                SqlCommand cmd = new SqlCommand("SP_GetAllQuestionSessions", con);
                cmd.CommandType = CommandType.StoredProcedure;
                con.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    QuestionSessionDTO questionSession = new QuestionSessionDTO();

                    questionSession.ID            = Convert.ToInt32(dr["ID"].ToString());
                    questionSession.UserID        = Convert.ToInt32(dr["UserId"].ToString());
                    questionSession.AmountCorrect = Convert.ToInt32(dr["AmountCorrect"].ToString());
                    questionSession.AmountWrong   = Convert.ToInt32(dr["AmountWrong"].ToString());
                    questionSession.DateFinished  = Convert.ToDateTime(dr["DateFinished"]);

                    questionList.Add(questionSession);
                }
            }

            return(questionList);
        }
示例#2
0
        }                            // Default constructor

        public QuestionSession(QuestionSessionDTO questionSessionDTO)
        {
            ID            = questionSessionDTO.ID;
            UserID        = questionSessionDTO.UserID;
            AmountCorrect = questionSessionDTO.AmountCorrect;
            AmountWrong   = questionSessionDTO.AmountWrong;
            DateFinished  = questionSessionDTO.DateFinished;
        }
        public void AddQuestionSession(QuestionSessionDTO questionSession)
        {
            using (SqlConnection con = new SqlConnection(connectionString))
            {
                SqlCommand cmd = new SqlCommand("SP_InsertQuestionSession", con);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@UserId", 2);
                cmd.Parameters.AddWithValue("@AmountCorrect", questionSession.AmountCorrect);
                cmd.Parameters.AddWithValue("@AmountWrong", questionSession.AmountWrong);
                cmd.Parameters.AddWithValue("@DateFinished", questionSession.DateFinished);

                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
            }
        }
示例#4
0
        public void VerifyInitializingQuestionSession()
        {
            // Arrange
            QuestionSessionDTO questionSessionDTO = new QuestionSessionDTO();

            questionSessionDTO.ID            = 6;
            questionSessionDTO.AmountCorrect = 0;
            questionSessionDTO.AmountWrong   = 0;
            questionSessionDTO.UserID        = 2;
            questionSessionDTO.DateFinished  = DateTime.Today;

            // Act
            QuestionSession questionSession = new QuestionSession(questionSessionDTO);

            // Assert
            Assert.IsNotNull(questionSessionDTO);
            Assert.IsNotNull(questionSession);
            Assert.AreEqual(questionSession.ID, questionSessionDTO.ID);
            Assert.AreEqual(questionSession.UserID, questionSessionDTO.UserID);
            Assert.AreEqual(questionSession.AmountCorrect, 0);
            Assert.AreEqual(questionSession.AmountWrong, 0);
            Assert.AreEqual(questionSession.DateFinished, questionSessionDTO.DateFinished);
        }
        public QuestionSessionDTO GetQuestionSessionById(int?questionId)
        {
            QuestionSessionDTO questionSession = new QuestionSessionDTO();

            using (SqlConnection con = new SqlConnection(connectionString))
            {
                SqlCommand cmd = new SqlCommand("SP_GetQuestionById", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@QuestionId", questionId);
                con.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    questionSession.ID            = Convert.ToInt32(dr["QuestionId"].ToString());
                    questionSession.UserID        = Convert.ToInt32(dr["UserId"].ToString());
                    questionSession.AmountCorrect = Convert.ToInt32(dr["AmountCorrect"].ToString());
                    questionSession.AmountWrong   = Convert.ToInt32(dr["AmountWrong"].ToString());
                    questionSession.DateFinished  = Convert.ToDateTime(dr["DateFinished"]);
                }
                con.Close();
            }

            return(questionSession);
        }