public void RecruitmentSrcTest() { Survey target = new Survey(); RecruitmentSrc val = null; target.RecruitmentSrc = val; }
protected void btnConfidentialSurveyAccept_Click(object sender, EventArgs e) { int genderID = 0; string ethnicity = null; List<SurveyXRecruitmentSrc> RecruitmentSources = new List<SurveyXRecruitmentSrc>(); foreach (ListItem item in rbtnConfidentialSurveySex.Items) { if (item.Selected) //Find the selected gender and set the genderID to that value genderID = int.Parse(item.Value); } //Instead of grabbing each radio button individually, loop through the control tree of the current view and look for radio buttons foreach (Control c in viewConfidentialSurvey.Controls) { if (c is RadioButton) { RadioButton ethnicityButton = (RadioButton)c; if (ethnicityButton.Checked && ethnicityButton.GroupName == "Ethnicity") { ethnicity = ethnicityButton.Text; break; } } } //Look through each item in the recruitment source repeater foreach (RepeaterItem item in rptRecruitmentSource.Items) { CheckBox cbox = item.FindControl("chkRecruitmentSource") as CheckBox; if (cbox != null && cbox.Checked) //if we found a checked checkbox { SurveyXRecruitmentSrc recruitmentSource = new SurveyXRecruitmentSrc(); RecruitmentSrc example = new RecruitmentSrc(); Label source = item.FindControl("lblRecruitmentSource") as Label; TextBox specific = item.FindControl("txtSpecify") as TextBox; if (source != null) //Make sure we have a valid source { example.RecruitmentSource = source.Text; //Grab the matching recruitment source out (ignore the allow specify field) recruitmentSource.RecruitmentSrc = RecruitmentSrcBLL.GetUniqueByExample(example, "AllowSpecify"); recruitmentSource.RecruitmentSrcOther = string.IsNullOrEmpty(specific.Text) ? null : specific.Text; RecruitmentSources.Add(recruitmentSource); } } } //Save ethnicity, gender, and all of the recruitment sources Application application = currentApplication; using (var ts = new TransactionScope()) { //First make sure we have a survey if (application.Surveys.Count == 0) { Survey newSurvey = new Survey(); newSurvey.AssociatedApplication = application; application.Surveys.Add(newSurvey); } Survey currentSurvey = application.Surveys[0]; //Save the gender if the ID was set (non-zero), else save that is was null if (genderID > 0) { currentSurvey.Gender = GenderBLL.GetByID(genderID); } else { currentSurvey.Gender = null; } //Save the ethnicity if (ethnicity != null) { Ethnicity chosenEthnicity = new Ethnicity(); chosenEthnicity.EthnicityValue = ethnicity; currentSurvey.Ethnicity = EthnicityBLL.GetUniqueByExample(chosenEthnicity); currentSurvey.TribalAffiliation = string.IsNullOrEmpty(txtAmericanIndian.Text) ? null : txtAmericanIndian.Text; } else { currentSurvey.Ethnicity = null; currentSurvey.TribalAffiliation = null; } //Save each recruitment source & clear out existing sources if (currentSurvey.RecruitmentSources == null) currentSurvey.RecruitmentSources = new List<SurveyXRecruitmentSrc>(); currentSurvey.RecruitmentSources.Clear(); foreach (SurveyXRecruitmentSrc chosenRecruitmentSource in RecruitmentSources) { chosenRecruitmentSource.AssociatedSurvey = currentSurvey; currentSurvey.RecruitmentSources.Add(chosenRecruitmentSource); //Trace.Write(string.Format("Checked the source {0} with additional info {1}", s.RecruitmentSrc.RecruitmentSource, s.RecruitmentSrcOther) + Environment.NewLine); } //Finally, set this step to complete currentSurvey.Complete = true; currentSurvey.AssociatedApplication = application; ApplicationBLL.EnsurePersistent(application); ts.CommitTransaction(); } ReloadStepListAndSelectHome(STR_ConfidentialSurvey, true); }