コード例 #1
0
        //Load Raters' information from the datatable
        public static Dictionary <string, List <Rater> > GetLoadRaters(DataTable dt)
        {
            var questionList = new Dictionary <string, List <Rater> >();

            var raterObject = new Rater();

            var question = string.Empty;

            var questionRaterList = new List <Rater>();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                //Get a question from datatable row and store it to a question variable
                question = !string.IsNullOrWhiteSpace(dt.Rows[i].ItemArray[0].ToString()) ? dt.Rows[i].ItemArray[0].ToString() : string.Empty;
                //Go through all the PA Upload template spreadsheet columns except first column (Question) to get all the raters
                for (int j = 1; j < dt.Columns.Count; j++)
                {
                    //get raters' information
                    raterObject.Name = !string.IsNullOrWhiteSpace(dt.Rows[i].ItemArray[i].ToString()) ? dt.Rows[i].ItemArray[i].ToString() : string.Empty;

                    if (!string.IsNullOrWhiteSpace(raterObject.Name))
                    {
                        questionRaterList.Add(new Rater()
                        {
                            Name = raterObject.Name
                        });
                    }
                }

                //Add a question and its associated rater in the disctinery list
                questionList.Add(question, questionRaterList);
            }

            return(questionList);
        }
コード例 #2
0
        //A method to return a list of survey questions from the database
        public static List <Survey> GetSurveyQuestions(DataTable dt)
        {
            var surveyList = new List <Survey>();

            //Get a list of raters
            var employeeSurvey = GetLoadRaters(dt);

            foreach (var questionLineItem in employeeSurvey)
            {
                var surveyObject = new Survey();

                List <Rater> ratersInformation = new List <Rater>();

                var raterCounter = 0;

                //Loop through a list of raters and add each name to raters' list
                foreach (var rater in employeeSurvey)
                {
                    if (!string.IsNullOrWhiteSpace(rater.Value[raterCounter].Name))
                    {
                        var raterObject = new Rater();

                        raterObject.Name = rater.Value[raterCounter].Name;

                        ratersInformation.Add(raterObject);
                    }
                }

                raterCounter++;

                //Store a question to a question object
                surveyObject.Question = questionLineItem.Key;

                surveyObject.RaterList = new List <Rater>(ratersInformation);

                surveyList.Add(surveyObject);

                ratersInformation.Clear();
            }

            return(surveyList);
        }