CapDemo.BL.QuestionBL.GetAnswerByQuestionID C# (CSharp) Méthode

GetAnswerByQuestionID() public méthode

public GetAnswerByQuestionID ( Question Question ) : List
Question CapDemo.DO.Question
Résultat List
        public List<Answer> GetAnswerByQuestionID(Question Question)
        {
            List<Answer> AnswerList = new List<Answer>();
            string query = "SELECT a.Answer_ID, a.Answer_Name, a.Question_ID, a.Correct_Answer"
                         + " FROM Answer a "
                         + " WHERE a.Question_ID='" + Question.IDQuestion + "'";
            //string query = "SELECT *"
            //            + " FROM Answer a "
            //            + " WHERE a.Question_ID='" + Question.IDQuestion + "'";
            DataTable dt = DA.SelectDatabase(query);
            if (dt != null)
            {
                foreach (DataRow item in dt.Rows)
                {
                    Answer Answer = new Answer();
                    Answer.IDAnswer = Convert.ToInt32(item["Answer_ID"]);
                    Answer.ContentAnswer = item["Answer_Name"].ToString() ;
                    Answer.IDQuestion = Convert.ToInt32(item["Question_ID"].ToString());
                    Answer.IsCorrect = (bool)item["Correct_Answer"];
                    AnswerList.Add(Answer);
                }
            }
            return AnswerList;
        }

Usage Example

        //Copy Question
        public void CopyQuestion()
        {
            Question question = new Question();
            Answer answer = new Answer();
            QuestionBL questionBL = new QuestionBL();
            foreach (DataGridViewRow row in dgv_Question.Rows)
            {
                if (row.Cells["Check"].Value != null && (bool)row.Cells["Check"].Value == true)
                {
                    question.QuestionTitle = row.Cells["QuestionTitle"].Value.ToString();
                    question.NameQuestion = row.Cells["QuestionName"].Value.ToString();
                    question.TypeQuestion = row.Cells["QuestionType"].Value.ToString();
                    question.IDCatalogue = IDCat;
                    question.Date = DateTime.Now;

                    if (questionBL.AddQuestion(question))
                    {
                        question.IDQuestion = Convert.ToInt32(row.Cells["IDQuestion"].Value);
                        List<DO.Answer> AnswerList;
                        AnswerList = questionBL.GetAnswerByQuestionID(question);
                        if (AnswerList != null)
                        {
                            for (int i = 0; i < AnswerList.Count; i++)
                            {
                                answer.ContentAnswer = AnswerList.ElementAt(i).ContentAnswer;
                                if (AnswerList.ElementAt(i).IsCorrect == true)
                                {
                                    answer.Check = 1;
                                }
                                else
                                {
                                    answer.Check = 0;
                                }
                                answer.IDQuestion = questionBL.MaxIDQuestion();
                                answer.IDCatalogue = IDCat;
                                questionBL.AddAnswer(answer);
                            }
                        }
                    }

                }
            }
        }
All Usage Examples Of CapDemo.BL.QuestionBL::GetAnswerByQuestionID