Ejemplo n.º 1
0
        public JsonResult GetExamFileList()
        {
            var examFilesBll = new ExamFilesBll();
            var list         = examFilesBll.QueryList("IsDelete=0");

            return(Json(ErrorModel.GetDataSuccess(list)));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 将试题文件及问题集合插入数据库中
        /// </summary>
        private static object InsertQuestionsToDb(ExamFiles examFiles, List <KeyValuePair <ExamQuestion, List <ExamAnswers> > > list)
        {
            var examFilesBll = new ExamFilesBll();

            examFilesBll.Insert(examFiles);

            if (examFiles.Id > 0)
            {
                DataUpdateLog.SingleUpdate(typeof(ExamFiles).Name, examFiles.Id, DataUpdateType.Insert);

                var questionBll = new ExamQuestionBll();
                var answerBll   = new ExamAnswersBll();

                // 在插入之前获取两表的最大id,以便在插入完成之后做数据库更新记录
                var maxQuestionId = (int)questionBll.GetMaxId();
                var maxAnswerId   = (int)answerBll.GetMaxId();

                try
                {
                    foreach (var keyPair in list)
                    {
                        var question = keyPair.Key;
                        var answers  = keyPair.Value;
                        question.ExamFileId = examFiles.Id;

                        // 将问题与答案放到事务中一起插入,保证数据的准确性
                        questionBll.ExecuteTransation(() => {
                            questionBll.Insert(question);
                            if (question.Id > 0)
                            {
                                answers.ForEach(answer => answer.QuestionId = question.Id);
                                answerBll.BulkInsert(answers);

                                return(true);
                            }

                            return(false);
                        });
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                // 数据库更新记录上传
                DataUpdateLog.BulkUpdate(typeof(ExamQuestion).Name, maxQuestionId, DataUpdateType.Insert);
                DataUpdateLog.BulkUpdate(typeof(ExamAnswers).Name, maxAnswerId, DataUpdateType.Insert);

                return(ErrorModel.OperateSuccess);
            }

            return(ErrorModel.OperateFailed);
        }