/// <summary>
        /// 任务详情
        /// </summary>
        /// <returns></returns>
        public ActionResult TaskDetail(int taskId, bool?revert)
        {
            var model = new EntryExaminationModel();
            var task  = _bookWorkTaskService.GetBookWorkTask(taskId);

            model.AllTaskChapterList = task.BookWorkTaskItems.Select(d => d.BookChapter).ToList();
            var bookChapterList = new List <BookChapter>();

            foreach (var titem in task.BookWorkTaskItems)
            {
                var itemchapter = titem.BookChapter;
                if (itemchapter != null)
                {
                    while (itemchapter.BookChapterParent != null)
                    {
                        itemchapter = itemchapter.BookChapterParent;
                    }
                    if (!bookChapterList.Contains(itemchapter))
                    {
                        bookChapterList.Add(itemchapter);
                    }
                }
            }
            model.BookChapterList = bookChapterList.OrderBy(p => p.Id).ToList();
            model.TaskId          = taskId;
            model.IsRevert        = revert.HasValue ? revert.Value : false;
            return(View(model));
        }
        private void PrepareTopic(EntryExaminationModel model, TiMu timu)
        {
            //根据科目id获取所以子孙知识点集合
            var knowledegs      = _knowledgeService.GetChildPoints(timu.SubjectId, null);
            var knowledgeSource = new List <KnowledgePiont>();

            knowledegs.ForEach(d =>
            {
                knowledgeSource.Add(new KnowledgePiont()
                {
                    Id        = d.Id,
                    Kpid      = d.Id,
                    Name      = d.Name,
                    ParentId  = d.ParentId,
                    SubjectId = d.SubjectId
                });
            });
            var revertPage = new RevertPage();

            revertPage.Tmid            = timu.Id.ToString();
            revertPage.KnowledgeSource = knowledgeSource;
            //获取本题目主知识点
            var maink = _knowledgeService.GetMainKnowledgeByTiMu(timu.Id, timu.SubjectId);
            //获取本题目相关知识点
            var minors    = _knowledgeService.GetMinorTiMuKnowledgeByTiMu(timu.Id, timu.SubjectId);
            var minorList = new List <KnowledgePiont>();

            revertPage.Diff         = timu.Difficult;
            revertPage.VideoId      = timu.VideoCode;
            revertPage.Teacher      = "";
            revertPage.ErrorMessage = timu.BookTiMu.ErrorInfo;
            if (maink != null)
            {
                revertPage.MainTiMuKnowledge = new KnowledgePiont()
                {
                    Id        = maink.Id,
                    Kpid      = maink.Id,
                    Name      = maink.Name,
                    ParentId  = maink.ParentId,
                    SubjectId = maink.SubjectId
                };
            }
            else
            {
                revertPage.MainTiMuKnowledge = null;
            }
            minors.ForEach(d =>
            {
                minorList.Add(new KnowledgePiont()
                {
                    Id        = d.Id,
                    Kpid      = d.Id,
                    Name      = d.Name,
                    ParentId  = d.ParentId,
                    SubjectId = d.SubjectId
                });
            });
            revertPage.MinorTiMuKnowledge = minorList;
            model.RevertPage = revertPage;
        }
        /// <summary>
        /// 属性标定
        /// </summary>
        /// <param name="tmid">The tmid.</param>
        /// <param name="timuStatus">The timu status.</param>
        /// <returns></returns>
        public ActionResult TopicMark(Guid tmid, BookTiMu.TimuStatus?timuStatus)
        {
            var model = new EntryExaminationModel();
            var timu  = _tiMuService.EntryGeTiMuFormatById(tmid);

            TiMuConvert(model, timu);
            PrepareTopic(model, timu);
            model.TmTypeList = _tiMuService.GetAllTypes(timu.SubjectId);
            model.TimuStatus = timuStatus;
            return(PartialView(model));
        }
        /// <summary>
        /// 题目编辑
        /// </summary>
        /// <returns></returns>
        public ActionResult TopicEdit(Guid tmid, int?order, int?cycles)
        {
            var model = new EntryExaminationModel();
            var timu  = _tiMuService.EntryGeTiMuFormatById(tmid);

            TiMuConvert(model, timu);
            PrepareTopic(model, timu);
            model.TmTypeList       = _tiMuService.GetAllTypes(timu.SubjectId);
            model.BookWorkTaskItem = _bookWorkTaskItemService.GetBookTiMuById(tmid).TaskItem;
            model.Order            = order;
            model.Cycles           = cycles;
            return(PartialView(model));
        }
 /// <summary>
 /// 创建题目
 /// </summary>
 /// <param name="taskItemId">The task item identifier.</param>
 /// <param name="tmid">The tmid.</param>
 /// <param name="order">The order.</param>
 /// <param name="cycles">The cycles.</param>
 /// <returns></returns>
 public ActionResult TopicCreate(int taskItemId, string tmid, int?order)
 {
     if (tmid != null)
     {
         return(RedirectToAction("TopicEdit", new { tmid = tmid, order = order }));
     }
     else
     {
         var model    = new EntryExaminationModel();
         var taskitem = _bookWorkTaskItemService.GetBookWorkTaskItemsById(taskItemId);
         model.BookWorkTaskItem = taskitem;
         var subject = taskitem.BookWorkTask.Book.Subject;
         TiMuCreateEmpty(model, subject, order);
         model.TmTypeList = subject.TiMuTypes.ToList();
         model.TimuId     = tmid;
         model.Order      = order;
         return(PartialView(model));
     }
 }
        private void TiMuCreateEmpty(EntryExaminationModel model, Subject subject, int?order)
        {
            var inputs  = new List <JsonInput>();
            var choices = new List <JsonInputChoice>();
            var timuId  = Guid.NewGuid();

            //答案
            inputs.Add(new JsonInput()
            {
                Id          = Guid.NewGuid(),
                TmId        = timuId,
                InputCode   = timuId.ToString(),
                BaseType    = "text",
                InputType   = "long-input",
                Order       = 1,
                InputAnswer = string.Empty,
                InputChoice = choices
            });
            model.Timu = new JsonTiMu()
            {
                Id         = timuId,
                SubjectId  = subject.Id,
                TiMuTypeId = subject.TiMuTypes.First().Id,
                Trunk      = string.Empty,
                Analysis   = string.Empty,
                Answer     = string.Empty,
                Comment    = string.Empty,
                Order      = order,
                Subject    = new JsonSubject()
                {
                    Id         = subject.Id,
                    Name       = subject.Name,
                    SystemCode = subject.SystemCode,
                    DegreeId   = subject.DegreeId,
                    ParentId   = subject.ParentId,
                    Order      = subject.Order,
                    Active     = subject.Active
                },
                Inputs = inputs
            };
        }
        // GET: EntryExamination
        public ActionResult Index(EntryExaminationModel model, EntryExaminationListPagingModel command)
        {
            if (command.PageNumber <= 0)
            {
                command.PageNumber = 1;
            }
            if (null == model)
            {
                model = new EntryExaminationModel();
            }
            var subject    = _subjectService.GetSubjectList();
            var selectList = new List <SelectListItem>()
            {
                new SelectListItem()
                {
                    Text = "请选择", Value = string.Empty
                }
            };

            subject.ForEach(d =>
            {
                selectList.Add(new SelectListItem()
                {
                    Text = d.Name, Value = d.Id.ToString()
                });
            });
            model.SubjectList = selectList;
            int?userid = null;

            if (!_workContext.CurrentCustomer.IsAdmin())
            {
                userid = _workContext.CurrentCustomer.Id;
            }
            var bookTasks = _bookWorkTaskService.GetAllTasks(userId: userid, taskStatus: TaskStatus.Entry, subjectId: model.SubjectId, pageIndex: command.PageNumber - 1,
                                                             pageSize: command.PageSize);

            model.BookTaskInfoList = bookTasks;
            model.EntryExaminationListPagingModel.LoadPagedList(bookTasks);
            return(View(model));
        }
        /// <summary>
        /// 录入试题(跳转编辑或者创建页面)
        /// </summary>
        /// <param name="viewmodel">The viewmodel.</param>
        /// <returns></returns>
        public ActionResult EntryTopic(EntryTopicModel viewmodel)
        {
            var model    = new EntryExaminationModel();
            var taskitem = _bookWorkTaskItemService.GetBookWorkTaskItemsById(viewmodel.taskItemId);

            //获取当前章节的父题目
            model.TiMuList         = _bookWorkTaskItemService.GetBookTiMus(viewmodel.taskItemId).Where(d => d.Timu.ParentId == null).ToList();
            model.BookWorkTaskItem = taskitem;
            model.TaskId           = viewmodel.taskId;
            model.IsRevert         = viewmodel.revert.HasValue ? viewmodel.revert.Value : false;
            model.TimuId           = viewmodel.timuId;
            model.IsEdit           = viewmodel.isEdit;
            model.Order            = viewmodel.order;
            if ((viewmodel.order != null && viewmodel.cycles != null) || (viewmodel.order == null && viewmodel.cycles != null))
            {
                model.Cycles = viewmodel.cycles;
            }
            model.TimuStatus = viewmodel.timuStatus;
            model.ChildCycle = viewmodel.childCycle;
            model.RevertType = viewmodel.revertType;
            return(View(model));
        }
        /// <summary>
        /// 被撤回任务
        /// </summary>
        /// <returns></returns>
        public ActionResult Revocation(EntryExaminationModel model, EntryExaminationListPagingModel command)
        {
            if (command.PageNumber <= 0)
            {
                command.PageNumber = 1;
            }
            if (null == model)
            {
                model = new EntryExaminationModel();
            }
            int?userid = null;

            if (!_workContext.CurrentCustomer.IsAdmin())
            {
                userid = _workContext.CurrentCustomer.Id;
            }
            var bookTasks = _bookWorkTaskService.GetAllTasks(userId: userid, taskStatus: TaskStatus.Revert, pageIndex: command.PageNumber - 1,
                                                             pageSize: command.PageSize);

            model.BookTaskInfoList = bookTasks;
            model.EntryExaminationListPagingModel.LoadPagedList(bookTasks);
            return(View(model));
        }
        private void TiMuConvert(EntryExaminationModel model, TiMu timu)
        {
            var inputs  = new List <JsonInput>();
            var choices = new List <JsonInputChoice>();

            foreach (Input input in timu.Inputs.OrderBy(d => d.Order))
            {
                //选项
                foreach (InputChoice choice in input.InputChoice.OrderBy(d => d.Order))
                {
                    choices.Add(new JsonInputChoice()
                    {
                        Id            = choice.Id,
                        InputId       = choice.InputId,
                        ChoiceContent = choice.ChoiceContent,
                        Score         = choice.Score,
                        Order         = choice.Order
                    });
                }
                //答案
                inputs.Add(new JsonInput()
                {
                    Id          = input.Id,
                    TmId        = input.TmId,
                    InputCode   = input.InputCode,
                    BaseType    = input.BaseType,
                    InputType   = input.InputType,
                    Score       = input.Score,
                    Order       = input.Order,
                    InputAnswer = input.InputAnswer,
                    InputChoice = choices
                });
            }
            model.Timu = new JsonTiMu()
            {
                Id            = timu.Id,
                SubjectId     = timu.SubjectId,
                TiMuTypeId    = timu.TiMuTypeId,
                Trunk         = timu.Trunk,
                Analysis      = timu.Analysis,
                Answer        = timu.Answer,
                Comment       = timu.Comment,
                Difficult     = timu.Difficult,
                Discriminate  = timu.Discriminate,
                StandardTime  = timu.StandardTime,
                StanderdScroe = timu.StanderdScroe,
                AbilityId     = timu.AbilityId,
                GradeId       = timu.GradeId,
                Year          = timu.Year,
                Soure         = timu.Soure,
                QualityId     = timu.QualityId,
                Price         = timu.Price,
                Inputs        = inputs,
                LargeNumber   = timu.BookTiMu.LargeNumber,
                SmallNumber   = timu.BookTiMu.SmallNumber,
                PageNumber    = timu.BookTiMu.PageNumber
            };
            if (timu.Subject != null)
            {
                model.Timu.Subject = new JsonSubject()
                {
                    Id         = timu.Subject.Id,
                    Name       = timu.Subject.Name,
                    SystemCode = timu.Subject.SystemCode,
                    DegreeId   = timu.Subject.DegreeId,
                    ParentId   = timu.Subject.ParentId,
                    Order      = timu.Subject.Order,
                    Active     = timu.Subject.Active
                };
            }
        }