Exemplo n.º 1
0
        private VoteAnswersEntity PopulateEntity(IDataReader reader)
        {
            //Create a new VoteAnswers object
            VoteAnswersEntity voteAnswers = new VoteAnswersEntity();

            //Fill the object with data
            //AnswerId
            if (reader["AnswerId"] != DBNull.Value)
            {
                voteAnswers.AnswerId = (int)reader["AnswerId"];
            }
            //QuesID
            if (reader["QuesID"] != DBNull.Value)
            {
                voteAnswers.QuesID = (int)reader["QuesID"];
            }
            //AnswerText
            if (reader["AnswerText"] != DBNull.Value)
            {
                voteAnswers.AnswerText = (string)reader["AnswerText"];
            }
            //HitsCount
            if (reader["HitsCount"] != DBNull.Value)
            {
                voteAnswers.HitsCount = (int)reader["HitsCount"];
            }
            //Return the populated object
            return(voteAnswers);
        }
Exemplo n.º 2
0
        //----------------------------------------------------------
        #endregion


        #region ----------------InsertTestingDataForVoteModule---------------
        //----------------------------------------------------------
        //InsertTestingDataForVoteModule
        //----------------------------------------------------------
        public void InsertTestingDataForVoteModule()
        {
            //---------------------------------------------------------------------
            VoteQuestionsEntity ArVoteQuestions = new VoteQuestionsEntity();
            string ArQuestionText = "سؤال تجريبي {0} ؟";

            ArVoteQuestions.AnswersCount = 4;
            ArVoteQuestions.IsMain       = true;
            ArVoteQuestions.LangID       = Languages.Ar;
            //---------------------------------------------------------------------
            string            ArAnswer     = "إجابة رقم ";
            VoteAnswersEntity ArVoteAnswer = new VoteAnswersEntity();
            //---------------------------------------------------------------------
            //---------------------------------------------------------------------
            VoteQuestionsEntity EnVoteQuestions = new VoteQuestionsEntity();
            string EnQuestionText = "Testing Question {0} ?";

            EnVoteQuestions.AnswersCount = 4;
            EnVoteQuestions.IsMain       = true;
            EnVoteQuestions.LangID       = Languages.En;
            //---------------------------------------------------------------------
            string            EnAnswer     = "Answer no ";
            VoteAnswersEntity EnVoteAnswer = new VoteAnswersEntity();

            //---------------------------------------------------------------------
            for (int i = 1; i <= 2; i++)
            {
                if (SiteSettings.Languages_HasArabicLanguages)
                {
                    ArVoteQuestions.QuestionText = string.Format(ArQuestionText, i.ToString());
                    bool ArResult = VoteQuestionsFactory.Save(ArVoteQuestions, SPOperation.Insert);
                    if (ArResult)
                    {
                        for (int b = 1; b <= 4; b++)
                        {
                            ArVoteAnswer.QuesID     = ArVoteQuestions.QuesID;
                            ArVoteAnswer.AnswerText = ArAnswer + b.ToString();
                            VoteAnswersFactory.Create(ArVoteAnswer);
                        }
                    }
                }
                if (SiteSettings.Languages_HasEnglishLanguages)
                {
                    EnVoteQuestions.QuestionText = string.Format(EnQuestionText, i.ToString());
                    bool EnResult = VoteQuestionsFactory.Save(EnVoteQuestions, SPOperation.Insert);
                    if (EnResult)
                    {
                        for (int b = 1; b <= 4; b++)
                        {
                            EnVoteAnswer.QuesID     = EnVoteQuestions.QuesID;
                            EnVoteAnswer.AnswerText = EnAnswer + b.ToString();
                            VoteAnswersFactory.Create(EnVoteAnswer);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        //------------------------------------------
        #endregion

        #region --------------Create--------------
        /// <summary>
        /// Converts the VoteAnswers object properties to SQL paramters and executes the create VoteAnswers procedure
        /// and updates the VoteAnswers object with the SQL data by reference.
        /// <example>[Example]bool status=VoteAnswersSqlDataPrvider.Instance.Create(voteAnswers);.</example>
        /// </summary>
        /// <param name="voteAnswers">The VoteAnswers object.</param>
        /// <returns>The status of create query.</returns>
        public bool Create(VoteAnswersEntity voteAnswers)
        {
            using (SqlConnection myConnection = GetSqlConnection())
            {
                SqlCommand myCommand = new SqlCommand("VoteAnswers_Create", myConnection);
                myCommand.CommandType = CommandType.StoredProcedure;
                // Set the parameters
                myCommand.Parameters.Add("@AnswerId", SqlDbType.Int, 4).Direction      = ParameterDirection.Output;
                myCommand.Parameters.Add("@QuesID", SqlDbType.Int, 4).Value            = voteAnswers.QuesID;
                myCommand.Parameters.Add("@AnswerText", SqlDbType.NVarChar, 128).Value = voteAnswers.AnswerText;
                // Execute the command
                bool status = false;
                myConnection.Open();
                if (myCommand.ExecuteNonQuery() > 0)
                {
                    status = true;
                    //Get ID value from database and set it in object
                    voteAnswers.AnswerId = (int)myCommand.Parameters["@AnswerId"].Value;
                }
                myConnection.Close();
                return(status);
            }
        }
Exemplo n.º 4
0
 public static bool Create(VoteAnswersEntity voteAnswers)
 {
     return(VoteAnswersSqlDataPrvider.Instance.Create(voteAnswers));
 }