Ejemplo 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 GivenBoolTrue_WhenCallConvertBoolToInt_ThenReturn1()
        {
            //Arrange
            var entry = true;

            //Act
            var actualValue   = ConvertIntBool.ConvertBoolToInt(entry);
            var expectedValue = 1;

            //Assert
            Assert.Equal(expectedValue, actualValue);
        }
        public void GivenBool1_WhenCallConvertIntToBool_ThenReturnTrue()
        {
            //Arrange
            var entry = 1;

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

            //Assert
            Assert.Equal(expectedValue, actualValue);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        public List <Answer> AddAnswer(Answer answer)
        {
            IDbCommand command = new SqlCommand("INSERT INTO Answers (Label, IdSurvey, GoodAnswer) VALUES (@Label, @IdSurvey, @GoodAnswer)", (SqlConnection)ConnectionSurveys.Instance);

            command.Parameters.Add(new SqlParameter("@Label", SqlDbType.VarChar)
            {
                Value = answer.Label
            });
            command.Parameters.Add(new SqlParameter("@IdSurvey", SqlDbType.Int)
            {
                Value = answer.IdSurvey
            });
            command.Parameters.Add(new SqlParameter("@GoodAnswer", SqlDbType.Int)
            {
                Value = ConvertIntBool.ConvertBoolToInt(answer.GoodAnswer)
            });
            ConnectionSurveys.Instance.Open();
            command.ExecuteNonQuery();
            command.Dispose();
            List <Answer> answers = GetAnswersById(answer.IdSurvey);

            ConnectionSurveys.Instance.Close();
            return(answers);
        }