Beispiel #1
0
        public static void AddScheduleQuestions(int scheduleId, RequestProfile requestProfile)
        {
            // get all questions
            var questionData = QuestionDataManager.GetList(requestProfile);

            // filter question records using Question Category 'EOD Questions'
            questionData.DefaultView.RowFilter = "QuestionCategory = 'EOD Questions'";
            questionData = questionData.DefaultView.ToTable();

            var scheduleQuestionData = new ScheduleQuestionDataModel();

            // for loop for entering default answers for all questions
            for (var i = 0; i < questionData.Rows.Count; i++)
            {
                var questionid = int.Parse(questionData.Rows[i][QuestionDataModel.DataColumns.QuestionId].ToString());

                scheduleQuestionData = new ScheduleQuestionDataModel();

                scheduleQuestionData.ScheduleId = scheduleId;
                scheduleQuestionData.QuestionId = int.Parse(questionid.ToString());
                scheduleQuestionData.Answer     = "No";

                ScheduleQuestionDataManager.Create(scheduleQuestionData, requestProfile);
            }
        }
Beispiel #2
0
        public override int?Save(string action)
        {
            var data = new ScheduleQuestionDataModel();

            data.ScheduleQuestionId = ScheduleQuestionId;
            data.ScheduleId         = ScheduleId;
            data.QuestionId         = QuestionId;
            data.Answer             = Answer;

            if (action == "Insert")
            {
                var dtScheduleQuestion = ScheduleQuestionDataManager.DoesExist(data, SessionVariables.RequestProfile);

                if (dtScheduleQuestion.Rows.Count == 0)
                {
                    ScheduleQuestionDataManager.Create(data, SessionVariables.RequestProfile);
                }
                else
                {
                    throw new Exception("Record with given ID already exists.");
                }
            }
            else
            {
                ScheduleQuestionDataManager.Update(data, SessionVariables.RequestProfile);
            }

            // not correct ... when doing insert, we didn't get/change the value of ScheduleID ?
            return(ScheduleQuestionId);
        }
Beispiel #3
0
        public static void SyncQuestions(int scheduleId, RequestProfile requestProfile)
        {
            // Get all ScheduleId related records from ScheduleQuestion
            var dtScheduleQuestion = ScheduleQuestionDataManager.GetBySchedule(scheduleId, requestProfile);

            // Get all Question Records
            var questionData = QuestionDataManager.GetList(requestProfile);

            // filter question records using Question Category 'EOD Questions'
            questionData.DefaultView.RowFilter = "QuestionCategory = 'EOD Questions'";
            questionData = questionData.DefaultView.ToTable();

            var scheduleQuestionData = new ScheduleQuestionDataModel();

            // for loop for entering default answers for all questions
            for (var i = 0; i < questionData.Rows.Count; i++)
            {
                var questionid = int.Parse(questionData.Rows[i][QuestionDataModel.DataColumns.QuestionId].ToString());

                var filterExpression = QuestionDataModel.DataColumns.QuestionId + " = " + questionid;

                // find if record for this question id exists in ScheduleQuestion for the particular ScheduleId
                var rows = dtScheduleQuestion.Select(filterExpression);

                // insert if no record found
                if (rows.Length == 0)
                {
                    scheduleQuestionData = new ScheduleQuestionDataModel();

                    scheduleQuestionData.ScheduleId = scheduleId;
                    scheduleQuestionData.QuestionId = int.Parse(questionid.ToString());
                    scheduleQuestionData.Answer     = "No";

                    ScheduleQuestionDataManager.Create(scheduleQuestionData, requestProfile);
                }
            }
            // refresh data table with newly added records
            dtScheduleQuestion = ScheduleQuestionDataManager.GetBySchedule(scheduleId, requestProfile);

            // for removing invalid category schedule questions
            for (var i = 0; i < dtScheduleQuestion.Rows.Count; i++)
            {
                var questionid = int.Parse(dtScheduleQuestion.Rows[i][ScheduleQuestionDataModel.DataColumns.QuestionId].ToString());

                var filterExpression = ScheduleQuestionDataModel.DataColumns.QuestionId + " = " + questionid;

                // find if record for this question id exists in ScheduleQuestion for the particular ScheduleId
                var rows = questionData.Select(filterExpression);

                // insert if no record found, so it is invalid
                if (rows.Length == 0)
                {
                    scheduleQuestionData = new ScheduleQuestionDataModel();
                    scheduleQuestionData.ScheduleQuestionId = int.Parse(dtScheduleQuestion.Rows[i][ScheduleQuestionDataModel.DataColumns.ScheduleQuestionId].ToString());
                    ScheduleQuestionDataManager.Delete(scheduleQuestionData, requestProfile);
                }
            }
        }