/// <summary> ///Checks to see if a unit has been selected then submit the survey information to the database. /// </summary> /// <param name="sender">Contains a reference to the control/object that raised the event.</param> /// <param name="e">Contains the event data of the event that triggered the method.</param> protected void Submit_Click(object sender, EventArgs e) { if (int.Parse(CPUnitDDL.SelectedValue) == 0) { MessageUserControl.ShowInfo("Must select a unit to submit a survey."); } else { MessageUserControl.TryRun(() => { //Utility for checking for special characters Utility utility = new Utility(); utility.checkValidString(Q5TextBox.Text); //create response Response newResponse = new Response(); newResponse.UnitId = int.Parse(CPUnitDDL.SelectedValue); newResponse.Age = AgeDDL.SelectedItem.Value; newResponse.Gender = GenderDDL.SelectedValue; newResponse.Date = DateTime.Now; newResponse.Comment = Q5TextBox.Text; //Add the new response to the database ResponseController sysmgr = new ResponseController(); sysmgr.Add_NewResponse(newResponse); // List of all the user's answers from all questions List <int> questionAnswers = new List <int>(); questionAnswers.Add(int.Parse(Q1ADDL.SelectedValue)); questionAnswers.Add(int.Parse(Q1BDDL.SelectedValue)); questionAnswers.Add(int.Parse(Q1CDDL.SelectedValue)); questionAnswers.Add(int.Parse(Q1DDDL.SelectedValue)); questionAnswers.Add(int.Parse(Q1EDDL.SelectedValue)); questionAnswers.Add(int.Parse(Q2DDL.SelectedValue)); questionAnswers.Add(int.Parse(Q3DDL.SelectedValue)); questionAnswers.Add(int.Parse(Q4DDL.SelectedValue)); //Loops through questionAnswers list and inserts response individually QuestionResponseController QRsysmgr = new QuestionResponseController(); for (int questionnumber = 1; questionnumber <= questionAnswers.Count(); questionnumber++) { QRsysmgr.Add_QuestionResponse(newResponse.ResponseId, questionnumber, questionAnswers[questionnumber - 1]); } Response.Redirect("SurveySuccess.aspx?rid=" + newResponse.ResponseId); }, "Success", "Survey has been submitted."); } }