Пример #1
0
        public JsonResult Edit(Chapter model)
        {
            try
            {
                if (model.ChapterId > 0)
                {
                    var entity = _ChapterService.GetById(model.ChapterId);
                    //修改
                    entity.ChapterId = model.ChapterId;
                    entity.Title     = model.Title;
                    entity.UTime     = DateTime.Now;
                    entity.Sort      = model.Sort;
                    _ChapterService.Update(entity);
                }
                else
                {
                    if (_ChapterService.IsExistName(model.Title))
                    {
                        return(Json(new { Status = Successed.Repeat }, JsonRequestBehavior.AllowGet));
                    }
                    //添加
                    model.CTime = DateTime.Now;
                    model.UTime = DateTime.Now;

                    _ChapterService.Insert(model);
                }
                return(Json(new { Status = Successed.Ok }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(new { Status = Successed.Error }, JsonRequestBehavior.AllowGet));
            }
        }
Пример #2
0
        private void NewMethod(int belongId)
        {
            if (belongId <= 0)
            {
                return;
            }

            //获取题目类型
            var qtypelist = _ProblemCategoryService.GetAll().ToList();
            //章节列表
            var chapterlist = _ChapterService.GetAll().ToList();
            //题目类别(注会、初级、中级等)
            var belonglist = _BelongService.GetAll().ToList();
            //subject
            var subjectlist = _SubjectInfoService.GetAll().ToList();

            int  pageNum  = 1;
            int  pageSize = 500;
            bool isOver   = false;

            while (!isOver)
            {
                //注会数据(临时表) pageNum不自增 每次取500条未处理的
                var fromList = _ProblemLibraryService.GetAllByPage(belongId, pageNum, pageSize);

                if (fromList != null && fromList.Count > 0)
                {
                    foreach (var item in fromList)
                    {
                        //switch (item.c_qustiontype)
                        //{
                        //    //目前判断了单选和多选,判断和回答
                        //    case 4://单选
                        //    case 5://多选
                        //    case 6://判断
                        //    case 11://回答
                        //    case 12://回答
                        //    case 13://回答
                        Problem pitem = new Problem();
                        pitem.Title    = item.Title;
                        pitem.Analysis = item.c_tips;
                        pitem.BelongId = item.BelongId;

                        if (!subjectlist.Any(p => p.Title == item.SubjectInfoTitle && p.BelongId == item.BelongId))
                        {
                            subjectlist.Add(_SubjectInfoService.Insert(new SubjectInfo
                            {
                                CTime    = DateTime.Now,
                                Title    = item.SubjectInfoTitle,
                                Sort     = 1,
                                UTime    = DateTime.Now,
                                BelongId = item.BelongId
                            }));
                        }
                        pitem.SubjectInfoId = subjectlist.Where(p => p.Title == item.SubjectInfoTitle && p.BelongId == item.BelongId).FirstOrDefault().SubjectInfoId;

                        if (!chapterlist.Any(p => p.Title == item.c_sctname && p.SubjectInfoId == pitem.SubjectInfoId))
                        {
                            chapterlist.Add(_ChapterService.Insert(new Chapter
                            {
                                CTime         = DateTime.Now,
                                Title         = item.c_sctname,
                                Sort          = 1,
                                UTime         = DateTime.Now,
                                SubjectInfoId = pitem.SubjectInfoId
                            }));
                        }
                        pitem.ChapterId = chapterlist.Where(p => p.Title == item.c_sctname && p.SubjectInfoId == pitem.SubjectInfoId).FirstOrDefault().ChapterId;

                        if (item.c_qustiontype == 4)
                        {
                            pitem.ProblemCategoryId = 1000;//等于4 单选
                        }
                        else if (item.c_qustiontype == 5)
                        {
                            pitem.ProblemCategoryId = 1001;//等于5 多选
                        }
                        else if (item.c_qustiontype == 6)
                        {
                            pitem.ProblemCategoryId = 1002;//等于6 判断
                        }
                        else// if (item.c_qustiontype == 11 || item.c_qustiontype == 12 || item.c_qustiontype == 13 || item.c_qustiontype == 15)
                        {
                            pitem.ProblemCategoryId = 1003;//等于11,12,13,15 计算回答
                        }
                        pitem.Score       = decimal.Parse(item.c_score);
                        pitem.Sort        = 1;
                        pitem.IsHot       = 0;
                        pitem.IsImportant = 0;
                        pitem.CTime       = DateTime.Now;
                        pitem.UTime       = DateTime.Now;

                        //写入题目
                        //if (!_ProblemService.IsExistName(pitem.Title, pitem.ChapterId))
                        //{
                        var returnProblemModel = _ProblemService.Insert(pitem);
                        //单选,多选
                        if (item.c_qustiontype == 4 || item.c_qustiontype == 5)
                        {
                            var _options = item.c_options;
                            var _answer  = item.c_answer;

                            if (!string.IsNullOrWhiteSpace(_answer))
                            {
                                var _correctlist = _answer.Split('|');
                                var _optionlist  = _options.Split('|');
                                for (int i = 0; i < _optionlist.Length; i++)
                                {
                                    Answer _answermodel = new Answer();
                                    _answermodel.ProblemId = returnProblemModel.ProblemId;
                                    _answermodel.Title     = _optionlist[i];
                                    _answermodel.IsCorrect = _correctlist.Contains((i + 1).ToString()) ? 1 : 0;
                                    //添加答案
                                    _AnswerService.Insert(_answermodel);
                                }
                            }
                        }
                        //判断
                        else if (item.c_qustiontype == 6)
                        {
                            Answer _answermodel = new Answer();
                            _answermodel.ProblemId = returnProblemModel.ProblemId;
                            _answermodel.Title     = item.c_tips;
                            _answermodel.IsCorrect = item.c_answer == "1" ? 1 : 0;
                            //添加答案
                            _AnswerService.Insert(_answermodel);
                        }
                        //回答
                        else if (item.c_qustiontype == 11 || item.c_qustiontype == 12 || item.c_qustiontype == 13)
                        {
                            //计算题,回答题。 没有答案选项。忽略
                        }
                        //}

                        //更新标识状态
                        item.IsUse = 1;
                        _ProblemLibraryService.Update(item);


                        //    break;
                        //default:
                        //    break;
                        //}
                    }
                }
                else
                {
                    isOver = true;
                }
            }
        }