Example #1
0
        public ResponseMessageExt QuestionBankImport()
        {
            int qbid;

            if (!int.TryParse(_request.Form["QuestionBank_Id"], out qbid))
            {
                return(Framework.ExtJs.ResponseMessageExt.Failed("参数错误!"));
            }
            QuestionBank qbank = _questionBankService.GetQuestionBankById(qbid);

            if (qbank == null || _request.Files.Count == 0)
            {
                return(Framework.ExtJs.ResponseMessageExt.Failed("数据错误!"));
            }
            var         file    = _request.Files[0];
            ExcelReader ereader = new ExcelReader(file.InputStream);

            string msg;
            var    questionlist     = ereader.Read <Question>("题目", "Q_Question", out msg);
            var    questionitemlist = ereader.Read <QuestionItem>("选择题选项", "Q_QuestionItem", out msg);
            var    answerlist       = ereader.Read <QuestionAnswer>("答案关联", "Q_QuestionAnswer", out msg);

            foreach (var q in questionlist)
            {
                q.QuestionBank_Id    = qbid;
                q.QType              = default(QuestionType).ToString();
                q.AType              = CommonHelper.GetEnumValueByDesc <AnswerType>(q.AType).ToString();
                q.MType              = CommonHelper.GetEnumValueByDesc <MatchingType>(q.MType).ToString();
                q.QuestionAnswerList = answerlist.Where(x => x.Sort == q.Sort).ToList();
                q.QuestionItemList   = questionitemlist.Where(x => x.Sort == q.Sort).ToList();
            }
            _questionBankService.ImportQuestion(questionlist);
            return(Wei.Web.Framework.ExtJs.ResponseMessageExt.Success());
        }