/// <summary>
 /// 审核标记题目错误与否.
 /// </summary>
 /// <param name="bookTiMu">The tmid.</param>
 /// <exception cref="System.ArgumentNullException"></exception>
 public void SignTmWrong(BookTiMu bookTiMu)
 {
     if (bookTiMu == null)
     {
         throw new ArgumentNullException(nameof(bookTiMu));
     }
     _bookTiMuRepository.Update(bookTiMu);
 }
Пример #2
0
        /// <summary>
        /// 解析题目(选项、分析、解答、点评等)并且保存到相应的表
        /// </summary>
        /// <param name="timuStr">The timu string.</param>
        /// <param name="taskItemId">The task item identifier.</param>
        /// <param name="parentTmId">The parent tm identifier.</param>
        /// <param name="property">The property.</param>
        /// <returns></returns>
        public string SaveTiMu(string timuStr, int?taskItemId, Guid?parentTmId, string property = null)
        {
            var    question     = "";
            string callbackTmid = string.Empty;

            try
            {
                //序列化前端页面题目对象
                var timuEntity = timuStr.Json2Obj <TimuJsonModel>();
                var timu       = _tiMuRepository.GetById(timuEntity.TiMuId);
                callbackTmid = timuEntity.TiMuId.ToString();
                if (timu == null)
                {
                    timu = new TiMu()
                    {
                        Id = timuEntity.TiMuId, SubjectId = timuEntity.SubjectId, ParentId = parentTmId
                    };
                    InsertTiMu(timu);
                    //把题目归属到对应的章节下面
                    var taskItem = _bookWorkTaskItemRepository.GetById(taskItemId);
                    var bookTimu = new BookTiMu()
                    {
                        TaskItemId = taskItem.Id,
                        Id         = timu.Id,
                        BookId     = taskItem.BookChapter.BookId,
                        Status     = BookTiMu.TimuStatus.Valid,
                        Order      = timuEntity.TimuBookOrder ?? 1
                    };
                    _bookTiMuRepository.Insert(bookTimu);
                    //保存一个空的答案数据到数据库,用于页面编辑前端js使用
                    var input = new Input()
                    {
                        Id          = Guid.NewGuid(),
                        TmId        = timu.Id,
                        InputCode   = timu.Id + "_a",
                        BaseType    = "text",
                        InputType   = "",
                        InputAnswer = "",
                        Score       = 0,
                        Order       = 1,
                    };
                    callbackTmid = timu.Id.ToString();
                    _inputRepository.Insert(input);
                }
                var tiMuEntry = new TiMuEntry(timuEntity, timu);
                var result    = tiMuEntry.TiMuFormat();
                //更新题目
                _tiMuRepository.Update(result.TiMu);
                //如果有答案则更新,没有就添加
                foreach (Input d in result.InputList)
                {
                    var input = _inputRepository.GetById(d.Id);
                    if (input != null)
                    {
                        _inputRepository.Update(d);
                    }
                    else
                    {
                        _inputRepository.Insert(d);
                    }
                }
                //如果有选项则更行,没有就添加
                foreach (InputChoice d in result.InputChoiceList)
                {
                    var choice = _inputChoiceRepository.GetById(d.Id);
                    if (choice != null)
                    {
                        _inputChoiceRepository.Update(d);
                    }
                    else
                    {
                        _inputChoiceRepository.Insert(d);
                    }
                }
                //删除答案
                if (result.DeleteInputs != null && result.DeleteInputs.Any())
                {
                    _inputRepository.Delete(result.DeleteInputs);
                }
                //更新booktimu相關信息
                var booktimu = timu.BookTiMu;
                if (booktimu != null)
                {
                    booktimu.LargeNumber = timuEntity.LargeNumber;
                    booktimu.SmallNumber = timuEntity.SmallNumber;
                    booktimu.PageNumber  = timuEntity.PageNumber;
                    _bookTiMuRepository.Update(booktimu);
                }
                question = "保存成功!";
                if (property != null)
                {
                    question = SaveTiMuMark(property);
                }
            }
            catch (Exception e)
            {
                question = "保存失败:" + e.Message;
            }
            var obj = new { info = question, tmid = callbackTmid };

            return(obj.Obj2Json());
        }