public int Score(SurveyTemplate pstTemplate, SurveyScoreCard sscScoreCard)
        {
            int intAnswerCount = 0;
            int intAnswerTotal = 0;
            int intReturnScore = 0;

            TemplateID = pstTemplate.TemplateID;
            ScoreCard = sscScoreCard;

            foreach (SurveyAnswer ansThis in ResponseData)
            {
                if (ansThis.Type == QuestionType.Radio || ansThis.Type == QuestionType.DropDown)
                {
                    int? intValue = pstTemplate.GetResponseValue(ansThis.ResponseID);

                    if (intValue != null)
                    {
                        intAnswerCount++;
                        Guid[] strReversibleAnswers = { };                        

                        if (AlternateScore && strReversibleAnswers.Contains(ansThis.ID))
                        {
                            intAnswerTotal += 10 - intValue.Value;
                        }
                        else
                        {
                            intAnswerTotal += intValue.Value;
                        }

                    }

                }
            }

            if (intAnswerCount != 0)
            {
                intReturnScore = intAnswerTotal / intAnswerCount;
            }
            else
            {
                intReturnScore = 0;
            }



            PopulateScoreDisplay(intReturnScore, sscScoreCard);

            return intReturnScore;

        }
        public ResultSet Main(SurveyTemplate st, SurveyResponse rs)
        {
            ResultSet rsReturn = new ResultSet(0, "");

            StringBuilder sbMessage = new StringBuilder();
            int intScore = 0;

            double dblDamage;            
            
            if (Double.TryParse(rs.GetAnswerText(st.GetQuestionFromNumber("Q1").ID), out dblDamage))
            {

                if (dblDamage <= 2000)
                {
                    sbMessage.AppendLine("Small Claims Track");  
                }
                
                             
            }

            double dblScale;

            

            if (Double.TryParse(rs.GetAnswerText(st.GetQuestionFromNumber("Q2").ID), out dblScale))
            {

                if (dblScale < 100)
                {
                    sbMessage.AppendLine("Outside the portal");    
                }
                
                
            }

            rsReturn.Message = sbMessage.ToString();
            rsReturn.Score = intScore;
            return rsReturn;

        }
        private SurveyTemplate CreateTestTemplate(string strTitle, Guid guidID)
        {
            //JavaScriptSerializer ser = new JavaScriptSerializer();
            SurveyTemplate stThis = new SurveyTemplate();
            stThis.Title = strTitle;
            stThis.TemplateID = guidID;



            List<SurveyQuestionResponse> resp = new List<SurveyQuestionResponse>();

            SurveyQuestionResponse rs = new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "Yes", Value = 10 };

            resp.Add(rs);

            rs = new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "No", Value = 0 };

            resp.Add(rs);

            rs = new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "N/A" };

            resp.Add(rs);

            List<SurveyQuestion> lstQ = new List<SurveyQuestion>();

            QText qt = new QText { ID = Guid.NewGuid(), Lines = 1, Width = InputWidth.Small, Type = QuestionType.Text, Number = "Q1", Order = 0, Text = "Value of Damages", ToolTip = "This is interlinked with the sliding scale" };

            lstQ.Add(qt);

            qt = new QText { ID = Guid.NewGuid(), Lines = 1, Width = InputWidth.Small, Type = QuestionType.Text, Number = "Q2", Order = 0, Text = "Sliding Scale", ToolTip = "Indicator of how much responsibility to admit" };

            lstQ.Add(qt);

            List<SurveyQuestionResponse> respToC = new List<SurveyQuestionResponse>();

            rs = new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "Motor", Value = 1 };

            respToC.Add(rs);

            rs = new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "Employer's Liability", Value = 2 };

            respToC.Add(rs);

            rs = new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "Public Liability", Value = 3 };

            respToC.Add(rs);

            QRadio qr = new QRadio { ID = Guid.NewGuid(), Inline = true, Number = "Q3", Order = 1, Text = "Type of Claim", Type = QuestionType.Radio, ToolTip = "Type of Claim", Responses = respToC };

            lstQ.Add(qr);

            qt = new QText { ID = Guid.NewGuid(), Lines = 1, Width = InputWidth.Small, Type = QuestionType.Text, Number = "Q4", Order = 0, Text = "Date of Event", ToolTip = "Date of Event" };

            lstQ.Add(qt);

            qt = new QText { ID = Guid.NewGuid(), Lines = 1, Width = InputWidth.Small, Type = QuestionType.Text, Number = "Q5", Order = 0, Text = "Date of Claim", ToolTip = "Date of Claim" };

            lstQ.Add(qt);

            resp = new List<SurveyQuestionResponse>();

            resp.Add(new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "Yes", Value = 1 });
            resp.Add(new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "No", Value = 0 });

            QDropDownList qd = new QDropDownList { ID = Guid.NewGuid(), Width = InputWidth.Small, Number = "Q6", Order = 2, Text = "Is there a London uplift?", Type = QuestionType.DropDown, ToolTip = "Is there a London uplift?", Responses = resp };

            lstQ.Add(qd);

            resp = new List<SurveyQuestionResponse>();

            resp.Add(new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "CFA", Value = 1 });
            resp.Add(new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "Non-CFA", Value = 0 });

            qd = new QDropDownList { ID = Guid.NewGuid(), Width = InputWidth.Small, Number = "Q7", Order = 2, Text = "Type of Funding", Type = QuestionType.DropDown, ToolTip = "Type of Funding", Responses = resp };

            lstQ.Add(qd);

            resp = new List<SurveyQuestionResponse>();

            resp.Add(new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "Yes", Value = 1 });
            resp.Add(new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "No", Value = 0 });

            qd = new QDropDownList { ID = Guid.NewGuid(), Width = InputWidth.Small, Number = "Q8", Order = 2, Text = "Is there an ATE premium", Type = QuestionType.DropDown, ToolTip = "Is there an ATE premium", Responses = resp };

            lstQ.Add(qd);

            resp = new List<SurveyQuestionResponse>();

            resp.Add(new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "Case Litigated", Value = 1 });
            resp.Add(new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "Pre-Litigated", Value = 0 });

            qd = new QDropDownList { ID = Guid.NewGuid(), Width = InputWidth.Small, Number = "Q9", Order = 2, Text = "Is the Case Litigated or Pre-Litigated", Type = QuestionType.DropDown, ToolTip = "Is the Case Litigated or Pre-Litigated", Responses = resp };

            lstQ.Add(qd);

            resp = new List<SurveyQuestionResponse>();

            resp.Add(new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "Yes", Value = 1 });
            resp.Add(new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "No", Value = 0 });

            qd = new QDropDownList { ID = Guid.NewGuid(), Width = InputWidth.Small, Number = "Q10", Order = 2, Text = "Did the claim start in the portal?", Type = QuestionType.DropDown, ToolTip = "Did the claim start in the portal?", Responses = resp };

            lstQ.Add(qd);

            resp = new List<SurveyQuestionResponse>();

            resp.Add(new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "Pre-allocation", Value = 1 });
            resp.Add(new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "Post-allocation/Pre-listing", Value = 2 });
            resp.Add(new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "Post-listing/Pre-trial", Value = 3 });

            qd = new QDropDownList { ID = Guid.NewGuid(), Width = InputWidth.Small, Number = "Q11", Order = 2, Text = "State of Litigation?", Type = QuestionType.DropDown, ToolTip = "State of Litigation?" , Responses = resp };

            lstQ.Add(qd);

            resp = new List<SurveyQuestionResponse>();

            resp.Add(new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "Yes", Value = 1 });
            resp.Add(new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "No", Value = 0 });

            qd = new QDropDownList { ID = Guid.NewGuid(), Width = InputWidth.Small, Number = "Q12", Order = 2, Text = "Is the case going through to trial?", Type = QuestionType.DropDown, ToolTip = "Is the case going through to trial?", Responses = resp };

            lstQ.Add(qd);

            resp = new List<SurveyQuestionResponse>();

            resp.Add(new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "Yes", Value = 1 });
            resp.Add(new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "No", Value = 0 });

            qd = new QDropDownList { ID = Guid.NewGuid(), Width = InputWidth.Small, Number = "Q13", Order = 2, Text = "Admitted failure to wear a seatbelt?", Type = QuestionType.DropDown, ToolTip = "Admitted failure to wear a seatbelt?", Responses = resp };

            lstQ.Add(qd);

            resp = new List<SurveyQuestionResponse>();

            resp.Add(new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "Yes", Value = 1 });
            resp.Add(new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "No", Value = 0 });

            qd = new QDropDownList { ID = Guid.NewGuid(), Width = InputWidth.Small, Number = "Q14", Order = 2, Text = "Date of settlement > 01/04/2013?", Type = QuestionType.DropDown, ToolTip = "Date of settlement > 01/04/2013?", Responses = resp };

            lstQ.Add(qd);

            resp = new List<SurveyQuestionResponse>();

            resp.Add(new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "Yes", Value = 1 });
            resp.Add(new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "No", Value = 0 });

            qd = new QDropDownList { ID = Guid.NewGuid(), Width = InputWidth.Small, Number = "Q15", Order = 2, Text = "Was the ATE purchased < 01/04/2013?", Type = QuestionType.DropDown, ToolTip = "Was the ATE purchased < 01/04/2013?", Responses = resp };

            lstQ.Add(qd);


            resp = new List<SurveyQuestionResponse>();

            resp.Add(new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "Yes", Value = 1 });
            resp.Add(new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "No", Value = 0 });

            qd = new QDropDownList { ID = Guid.NewGuid(), Width = InputWidth.Small, Number = "Q16", Order = 2, Text = "Date of CFA < 01/04/2013?", Type = QuestionType.DropDown, ToolTip = "Date of CFA < 01/04/2013?", Responses = resp };

            lstQ.Add(qd);

            resp = new List<SurveyQuestionResponse>();

            resp.Add(new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "Yes", Value = 1 });
            resp.Add(new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "No", Value = 0 });

            qd = new QDropDownList { ID = Guid.NewGuid(), Width = InputWidth.Small, Number = "Q17", Order = 2, Text = "Has the case settled within stages 1&2?", Type = QuestionType.DropDown, ToolTip = "Has the case settled within stages 1&2?", Responses = resp };

            lstQ.Add(qd);

            resp = new List<SurveyQuestionResponse>();

            resp.Add(new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "Yes", Value = 1 });
            resp.Add(new SurveyQuestionResponse { ID = Guid.NewGuid(), Text = "No", Value = 0 });

            qd = new QDropDownList { ID = Guid.NewGuid(), Width = InputWidth.Small, Number = "Q18", Order = 2, Text = "Does the user want to stay within the portal?", Type = QuestionType.DropDown, ToolTip = "Does the user want to stay within the portal?", Responses = resp };

            lstQ.Add(qd);

            qt = new QText { ID = Guid.NewGuid(), Lines = 1, Width = InputWidth.Small, Type = QuestionType.Text, Number = "Q19", Order = 0, Text = "Disbursements including VAT", ToolTip = "Disbursements including VAT" };

            lstQ.Add(qt);
          
            List<SurveyGroup> grps = new List<SurveyGroup>();

            grps.Add(new SurveyGroup { ID = Guid.NewGuid(), Name = "IDTheRegime", Order = 0, Questions = lstQ, ToolTip = "ID The Regime"});
            
            stThis.Groups = grps;

            return stThis;

        }
        public static SurveyTemplate GetTemplate(string pstrList, Guid pguidTemplate)
        {

            SurveyTemplate stThis = null;

            SPWeb web = SPContext.Current.Web;
            {
                try
                {
                    SPList lst = web.Lists.TryGetList(pstrList);

                    if (lst != null)
                    {

                        SPListItem lsi = lst.GetItemByUniqueId(pguidTemplate);



                        JavaScriptSerializer ser = new JavaScriptSerializer(new SimpleTypeResolver());
                        stThis = new SurveyTemplate();
                        stThis.Title = lsi.Title;
                        stThis.TemplateID = lsi.UniqueId;
                        stThis = ser.Deserialize<SurveyTemplate>(lsi["QuestionData"].ToString());

                    }

                }
                catch (Exception ex)
                {
                    throw ex;
                }

            }

            return stThis;
        }
        public int Score(SurveyTemplate pstTemplate)
        {

            return 0;

        }