private void SaveKillerQuestions(int jobApplicationId) { var questions = new List<KillerQuestion>(); foreach (RepeaterItem item in rptKillerQuestions.Items) { var lblQuestionid = item.FindControl("lblQuestionId") as Label; if (lblQuestionid != null) { var questionId = Convert.ToInt32(lblQuestionid.Text); var question = new KillerQuestions().GetKillerQuestion(questionId); if (question != null) { question.CandidateAnswers = new List<KillerQuestionCandidateAnswer>(); if (question.Answers == null || question.Answers.Count == 0) { //open question - show text box var txtOpenQuestion = item.FindControl("txtOpenQuestion") as TextBox; if (txtOpenQuestion != null) { var answer = new KillerQuestionCandidateAnswer { OpenQuestionAnswer = txtOpenQuestion.Text, JobApplicationId = jobApplicationId }; var txtScore = item.FindControl("txtScore") as TextBox; int score; if (txtScore != null && !question.ExcludeFromScoring && int.TryParse(txtScore.Text, out score)) { answer.AdditionalScore = score; } question.CandidateAnswers.Add(answer); } } else { if (question.SingleChoice) { // single choice - radio buttons var rbtLstKillerQuestion = item.FindControl("rbtLstKillerQuestion") as RadioButtonList; if (rbtLstKillerQuestion != null) { var ans = rbtLstKillerQuestion.SelectedItem.Value; question.CandidateAnswers.Add(new KillerQuestionCandidateAnswer { AnswerId = Convert.ToInt32(ans), JobApplicationId = jobApplicationId }); } } else { //multiple choice - check boxes var chkMultichoice = item.FindControl("chkMultichoice") as CheckBoxList; if (chkMultichoice != null) { var answers = chkMultichoice.Items.Cast<ListItem>() .Where(li => li.Selected) .Select(t => new KillerQuestionCandidateAnswer { AnswerId = Convert.ToInt32(t.Value), JobApplicationId = jobApplicationId }); question.CandidateAnswers.AddRange(answers); } } } } questions.Add(question); } } //save the answers and calculate the score var kqFinalScore = new JobApplications().SaveKillerQuestionAnswersForJob(jobApplicationId, questions); lblKillerQuestionScore.Text = kqFinalScore.ToString(CultureInfo.InvariantCulture); }