Esempio n. 1
0
        public List <Survey> GetAllSurveys(bool?Online)
        {
            string Request = " ";

            if (Online != null)
            {
                Request = " WHERE Online = '1' ";
            }
            List <Survey> surveys = new List <Survey>();
            IDbCommand    command = new SqlCommand("SELECT * FROM Surveys" + Request + "ORDER BY DateCreation DESC", (SqlConnection)ConnectionSurveys.Instance);

            ConnectionSurveys.Instance.Open();
            SqlDataReader reader = (SqlDataReader)command.ExecuteReader();

            while (reader.Read())
            {
                Survey s = new Survey();
                s.Titre        = reader.GetString(1);
                s.Id           = reader.GetInt32(0);
                s.IdCreateur   = reader.GetInt32(2);
                s.Online       = ConvertIntBool.ConvertIntToBool(reader.GetInt32(3));
                s.DateCreation = reader.GetDateTime(4);
                surveys.Add(s);
            }
            reader.Close();
            command.Dispose();

            foreach (Survey s in surveys)
            {
                s.Answers    = GetAnswersById(s.Id);
                s.CountVotes = GetCountVoteByIdSurvey(s.Id);
            }
            ConnectionSurveys.Instance.Close();
            return(surveys);
        }
        public void GivenBool1_WhenCallConvertIntToBool_ThenReturnTrue()
        {
            //Arrange
            var entry = 1;

            //Act
            var actualValue   = ConvertIntBool.ConvertIntToBool(entry);
            var expectedValue = true;

            //Assert
            Assert.Equal(expectedValue, actualValue);
        }
Esempio n. 3
0
        private List <Answer> GetAnswersById(int IdSurvey)
        {
            List <Answer> answers = new List <Answer>();
            IDbCommand    command = new SqlCommand("SELECT * FROM Answers WHERE IdSurvey = @IdSurvey", (SqlConnection)ConnectionSurveys.Instance);

            command.Parameters.Add(new SqlParameter("@IdSurvey", SqlDbType.Int)
            {
                Value = IdSurvey
            });
            SqlDataReader reader = (SqlDataReader)command.ExecuteReader();

            while (reader.Read())
            {
                Answer a = new Answer();
                a.Id       = reader.GetInt32(0);
                a.Label    = reader.GetString(1);
                a.IdSurvey = reader.GetInt32(2);
                try
                {
                    a.GoodAnswer = ConvertIntBool.ConvertIntToBool(reader.GetInt32(3));
                }
                catch
                {
                    a.GoodAnswer = false;
                }
                answers.Add(a);
            }
            reader.Close();
            command.Dispose();

            foreach (Answer a in answers)
            {
                command = new SqlCommand("SELECT COUNT (*) FROM AnswerUsers WHERE IdAnswer = @IdAnswer", (SqlConnection)ConnectionSurveys.Instance);
                command.Parameters.Add(new SqlParameter("@IdAnswer", SqlDbType.Int)
                {
                    Value = a.Id
                });
                a.NbreVote = (int)command.ExecuteScalar();
            }
            command.Dispose();

            return(answers);
        }