private void AddQuestionBtn_Click(object sender, EventArgs e) { Question newQuestion = new Question(); int type = (int)QuestionType.SelectedValue; newQuestion.Type = type; switch (type) { case 1: if (!choiceA.Checked && !choiceB.Checked && !choiceC.Checked && !choiceD.Checked) { MessageBox.Show("Please choose the correct answer"); } else { QuestionAnswer answer1 = new QuestionAnswer(); QuestionAnswer answer2 = new QuestionAnswer(); QuestionAnswer answer3 = new QuestionAnswer(); QuestionAnswer answer4 = new QuestionAnswer(); answer1.Answer = choiceALabel.Text; answer2.Answer = choiceBLabel.Text; answer3.Answer = choiceCLabel.Text; answer4.Answer = choiceDLabel.Text; newQuestion.Answers = new List <QuestionAnswer>(); newQuestion.Answers.Add(answer1); newQuestion.Answers.Add(answer2); newQuestion.Answers.Add(answer3); newQuestion.Answers.Add(answer4); newQuestion.Modelanswer = new QuestionAnswer(); if (choiceA.Checked) { newQuestion.Modelanswer.Answer = choiceALabel.Text; } else if (choiceB.Checked) { newQuestion.Modelanswer.Answer = choiceBLabel.Text; } else if (choiceC.Checked) { newQuestion.Modelanswer.Answer = choiceCLabel.Text; } else { newQuestion.Modelanswer.Answer = choiceDLabel.Text; } } break; case 2: if (!checkTrue.Checked && !checkFalse.Checked) { MessageBox.Show("Please choose the correct answer"); } else { QuestionAnswer trueAnswer = new QuestionAnswer(); QuestionAnswer falseAnswer = new QuestionAnswer(); trueAnswer.Answer = checkTrueLabel.Text; falseAnswer.Answer = checkFalseLabel.Text; newQuestion.Answers = new List <QuestionAnswer>(); newQuestion.Answers.Add(trueAnswer); newQuestion.Answers.Add(falseAnswer); newQuestion.Modelanswer = new QuestionAnswer(); if (checkTrue.Checked) { newQuestion.Modelanswer.Answer = checkTrueLabel.Text; } else if (checkFalse.Checked) { newQuestion.Modelanswer.Answer = checkFalseLabel.Text; } } break; case 3: if (String.IsNullOrEmpty(questionAnswer.Text)) { MessageBox.Show("Please add the answer"); } else { QuestionAnswer essayAnswer = new QuestionAnswer(); essayAnswer.Answer = questionAnswer.Text; newQuestion.Answers = new List <QuestionAnswer>(); newQuestion.Modelanswer = new QuestionAnswer(); newQuestion.Answers.Add(essayAnswer); newQuestion.Modelanswer.Answer = ""; } break; } newQuestion.Course = new Course(); newQuestion.Course.Id = (int)QuestionCourse.SelectedValue; QuestionDAL.Add(newQuestion); }