public void SaveMatrix()
        {
            int SRPK = int.Parse(SRID);
            var ds   = SQChoices.GetAll(int.Parse(QID));

            foreach (RepeaterItem rLine in rptrMRows.Items)
            {
                var obj1 = SurveyResults.FetchObject(SRPK);
                var obj2 = new SurveyAnswers();

                obj2.SRID  = obj1.SRID;
                obj2.TenID = obj1.TenID;
                obj2.PID   = obj1.PID;
                obj2.SID   = obj1.SID;

                obj2.QID          = int.Parse(QID);
                obj2.DateAnswered = DateTime.Now;
                obj2.QType        = 4;

                var SQMLID = rLine.FindControl("SQMLID") as Label;
                obj2.SQMLID = int.Parse(SQMLID.Text);

                if (DisplayControl == "1")
                {
                    var rptrCheckCols = rLine.FindControl("rptrCheckCols") as Repeater;
                    foreach (RepeaterItem rChkI in rptrCheckCols.Items)
                    {
                        var SQCID       = rChkI.FindControl("SQCID") as Label;
                        var chkAns      = rChkI.FindControl("rbChoice") as CheckBox;
                        var ChoiceOrder = rChkI.FindControl("ChoiceOrder") as Label;
                        var AnsText     = ds.Tables[0].Rows[int.Parse(ChoiceOrder.Text) - 1]["ChoiceText"].ToString();
                        if (chkAns.Checked)
                        {
                            obj2.ChoiceAnswerIDs = string.Format("{0}{1}{2}",
                                                                 (obj2.ChoiceAnswerIDs.Length > 0 ? obj2.ChoiceAnswerIDs : ""),
                                                                 (obj2.ChoiceAnswerIDs.Length > 0 ? "," : ""), SQCID.Text);


                            obj2.ChoiceAnswerText = string.Format("{0}{1}{2}",
                                                                  (obj2.ChoiceAnswerText.Length > 0 ? obj2.ChoiceAnswerText : ""),
                                                                  (obj2.ChoiceAnswerText.Length > 0 ? "~|~" : ""), AnsText);
                        }
                    }
                }
                if (DisplayControl == "2")
                {
                    var rptrRadioCols = rLine.FindControl("rptrRadioCols") as Repeater;
                    foreach (RepeaterItem rRdoI in rptrRadioCols.Items)
                    {
                        var SQCID       = rRdoI.FindControl("SQCID") as Label;
                        var rbAns       = rRdoI.FindControl("rbChoice") as RadioButton;
                        var ChoiceOrder = rRdoI.FindControl("ChoiceOrder") as Label;
                        var AnsText     = ds.Tables[0].Rows[int.Parse(ChoiceOrder.Text) - 1]["ChoiceText"].ToString();


                        if (rbAns.Checked)
                        {
                            obj2.ChoiceAnswerIDs = string.Format("{0}{1}{2}",
                                                                 (obj2.ChoiceAnswerIDs.Length > 0 ? obj2.ChoiceAnswerIDs : ""),
                                                                 (obj2.ChoiceAnswerIDs.Length > 0 ? "," : ""), SQCID.Text);
                            obj2.ChoiceAnswerText = string.Format("{0}{1}{2}",
                                                                  (obj2.ChoiceAnswerText.Length > 0 ? obj2.ChoiceAnswerText : ""),
                                                                  (obj2.ChoiceAnswerText.Length > 0 ? "~|~" : ""), AnsText);
                        }
                    }
                }

                obj2.Insert();
            }
        }
        public void SaveMultiChoice()
        {
            int SRPK = int.Parse(SRID);
            var obj1 = SurveyResults.FetchObject(SRPK);
            var obj2 = new SurveyAnswers();

            obj2.SRID  = obj1.SRID;
            obj2.TenID = obj1.TenID;
            obj2.PID   = obj1.PID;
            obj2.SID   = obj1.SID;

            obj2.QID          = int.Parse(QID);
            obj2.DateAnswered = DateTime.Now;
            obj2.QType        = 2;

            if (DisplayControl == "1")
            {
                foreach (RepeaterItem rChkI in rptrChk.Items)
                {
                    var SQCID   = rChkI.FindControl("SQCID") as Label;
                    var chkAns  = rChkI.FindControl("chkAns") as CheckBox;
                    var chkClar = rChkI.FindControl("txtChkClarification") as TextBox;

                    if (chkAns.Checked)
                    {
                        obj2.ChoiceAnswerIDs = string.Format("{0}{1}{2}",
                                                             (obj2.ChoiceAnswerIDs.Length > 0 ? obj2.ChoiceAnswerIDs : ""),
                                                             (obj2.ChoiceAnswerIDs.Length > 0 ? "," : ""), SQCID.Text);
                        obj2.ClarificationText = string.Format("{0}{1}{2}",
                                                               (obj2.ClarificationText.Length > 0 ? obj2.ClarificationText : ""),
                                                               (obj2.ClarificationText.Length > 0 ? "~|~" : ""), chkClar.Text);
                        obj2.ChoiceAnswerText = string.Format("{0}{1}{2}",
                                                              (obj2.ChoiceAnswerText.Length > 0 ? obj2.ChoiceAnswerText : ""),
                                                              (obj2.ChoiceAnswerText.Length > 0 ? "~|~" : ""), chkAns.Text);
                    }
                }
            }
            if (DisplayControl == "2")
            {
                foreach (RepeaterItem rRdoI in rptrRadio.Items)
                {
                    var SQCID  = rRdoI.FindControl("SQCID") as Label;
                    var rbAns  = rRdoI.FindControl("rbAns") as RadioButton;
                    var rbClar = rRdoI.FindControl("txtRBClarification") as TextBox;

                    if (rbAns.Checked)
                    {
                        obj2.ChoiceAnswerIDs = string.Format("{0}{1}{2}",
                                                             (obj2.ChoiceAnswerIDs.Length > 0 ? obj2.ChoiceAnswerIDs : ""),
                                                             (obj2.ChoiceAnswerIDs.Length > 0 ? "," : ""), SQCID.Text);
                        obj2.ClarificationText = string.Format("{0}{1}{2}",
                                                               (obj2.ClarificationText.Length > 0 ? obj2.ClarificationText : ""),
                                                               (obj2.ClarificationText.Length > 0 ? "~|~" : ""), rbClar.Text);
                        obj2.ChoiceAnswerText = string.Format("{0}{1}{2}",
                                                              (obj2.ChoiceAnswerText.Length > 0 ? obj2.ChoiceAnswerText : ""),
                                                              (obj2.ChoiceAnswerText.Length > 0 ? "~|~" : ""), rbAns.Text);
                    }
                }
            }
            if (DisplayControl == "3")
            {
                obj2.ChoiceAnswerIDs = ddMultipleChoice.SelectedValue;
                var ch  = SQChoices.FetchObject(int.Parse(ddMultipleChoice.SelectedValue));
                var ans = "N/A";
                if (ch != null)
                {
                    ans = ch.ChoiceText;
                }
                obj2.ChoiceAnswerText  = ans;
                obj2.ClarificationText = txtDDClarification.Text;
            }

            obj2.Insert();
        }
        /// <summary>
        /// This method gets a list of franchises filtered by the user's survey results
        /// </summary>
        /// <param name="surveyAnswers"></param>
        /// <returns> List of franchises </returns>
        public List <Franchise> GetFranchiseListFromSurveyResults(SurveyAnswers surveyAnswers)
        {
            List <Franchise> returnList = new List <Franchise>();
            string           queryText  = "";

            if (surveyAnswers.hasOwnedBusiness == "True" && surveyAnswers.industry == "Any")
            {
                queryText = SQL_GetFranchiseListFromSurveyResultsExperiencedInBusinessNoIndustryPreference;
            }
            else if (surveyAnswers.hasOwnedBusiness == "True")
            {
                queryText = SQL_GetFranchiseListFromSurveyResultsExperiencedInBusiness;
            }
            else if (surveyAnswers.hasOwnedBusiness == "False" && surveyAnswers.industry == "Any")
            {
                queryText = SQL_GetFranchiseListFromSurveyResultsNewToBusinessNoIndustryPreference;
            }
            else
            {
                queryText = SQL_GetFranchiseListFromSurveyResultsNewToBusiness;
            }

            try
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();
                    var command = new SqlCommand(queryText);
                    command.Parameters.AddWithValue("@NetWorth", surveyAnswers.netWorth);
                    //command.Parameters.AddWithValue("@staff", surveyAnswers.staff);
                    command.Parameters.AddWithValue("@industry", surveyAnswers.industry);
                    command.Parameters.AddWithValue("@state", surveyAnswers.state);
                    command.Connection = connection;
                    SqlDataReader reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        Franchise franchise = new Franchise();

                        franchise.FranchiseId          = Convert.ToInt32(reader["franchiseId"]);
                        franchise.FranchiseName        = Convert.ToString(reader["franchiseName"]);
                        franchise.YelpTerm             = Convert.ToString(reader["yelpTerm"]);
                        franchise.FirstTimeFriendly    = Convert.ToBoolean(reader["firstTimeFriendly"]);
                        franchise.StaffSize            = Convert.ToString(reader["staffSize"]);
                        franchise.Category             = Convert.ToString(reader["category"]);
                        franchise.NetWorth             = Convert.ToInt32(reader["netWorth"]);
                        franchise.FranchiseFee         = Convert.ToInt32(reader["franchiseFee"]);
                        franchise.TotalInvestment      = Convert.ToInt32(reader["totalInvestment"]);
                        franchise.RoyaltyFee           = Convert.ToInt32(reader["royaltyFee"]);
                        franchise.AdvertisingFee       = Convert.ToInt32(reader["advertisingFee"]);
                        franchise.Heading              = Convert.ToString(reader["heading"]);
                        franchise.FranchiseDescription = Convert.ToString(reader["franchiseDescription"]);
                        franchise.LogoURL              = Convert.ToString(reader["logoUrl"]);
                        franchise.PicURL = Convert.ToString(reader["picUrl"]);

                        returnList.Add(franchise);
                    }
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }

            return(returnList);
        }
 public async Task <int> AnswerTransaction(SurveyAnswers data, char action)
 {
     return(await _survey.AnswerTransaction(data, action));
 }
 public async Task <int> AnswerTransaction(SurveyAnswers data, char action)
 {
     return(await _adapterPattern.SingleTransaction <SurveyAnswers, int>(data, "usp_SurveyAnswers_Transaction", action, DataConfiguration.instanceCore));
 }