public static IList <Yw_SubjectKnowledge> Fetch(
            QuestionInputModel subject,
            SubjectBll bll,
            int currentUser,
            out IEnumerable <int> toDelete)
        {
            Check.IfNull(subject, nameof(subject));
            Check.IfNull(bll, nameof(bll));
            if (currentUser < 10000)
            {
                throw new ArgumentException(
                          "当前登录用户的ID不能小于10000",
                          nameof(currentUser));
            }
            DateTime now = DateTime.Now;
            IEnumerable <Yw_SubjectKnowledge> knowledgeEntities =
                bll.GetKnowledgesBySubject(subject.Id);
            IEnumerable <Yw_SubjectKnowledge> secondaryKnowledgeEntities =
                knowledgeEntities.Where(k => !k.Ysw_IsMain);
            //前台传过来的次级知识点
            IList <int> knowledges = new List <int>();

            if (subject.Knowledges.HasValue())
            {
                knowledges = subject.Knowledges.Split(',').Select(k => int.Parse(k)).ToList();
            }
            //需要添加的次级知识点
            IEnumerable <Yw_SubjectKnowledge> knowledgesToAdd = null;
            //需要删除的次级知识点
            IEnumerable <int> idsOfknowledgeToDelete = null;
            //数据库的次级知识点
            var knowledgesInDb =
                secondaryKnowledgeEntities.Select(k => k.Ysw_KnowledgeId);

            knowledgesToAdd = knowledges.Except(knowledgesInDb)
                              .Select(k => new Yw_SubjectKnowledge
            {
                Ysw_KnowledgeId = k,
                Ysw_IsMain      = false,
                Ysw_CreateTime  = now,
                Ysw_Creator     = currentUser,
                Ysw_UpdateTime  = now,
                Ysw_Editor      = currentUser
            });
            var knowledgesToDelete = knowledgesInDb.Except(knowledges);

            idsOfknowledgeToDelete =
                secondaryKnowledgeEntities
                .Where(k => knowledgesToDelete.Contains(k.Ysw_KnowledgeId))
                .Select(k => k.Ysw_Id);
            toDelete = idsOfknowledgeToDelete;

            return(knowledgesToAdd.ToList());
        }
        public static Action<Yw_SubjectKnowledge> Fetch(
            QuestionInputModel subject,
            SubjectBll bll,
            int currentUser,
            out Yw_SubjectKnowledge entity)
        {
            Check.IfNull(subject, nameof(subject));
            Check.IfNull(bll, nameof(bll));
            if (currentUser < 10000)
            {
                throw new ArgumentException(
                    "当前登录用户的ID不能小于10000",
                    nameof(currentUser));
            }

            DateTime now = DateTime.Now;
            Action<Yw_SubjectKnowledge> saveKnowledge = null;
            IEnumerable<Yw_SubjectKnowledge> knowledgeEntities =
                bll.GetKnowledgesBySubject(subject.Id);
            Yw_SubjectKnowledge mainKnowledgeEntity =
                knowledgeEntities.FirstOrDefault(k => k.Ysw_IsMain);
            if (subject.Knowledge == 0)//不在指定主知识点
            {
                saveKnowledge = bll.DeleteKnowledge;
            }
            else
            {
                if (mainKnowledgeEntity == null)
                {
                    mainKnowledgeEntity = new Yw_SubjectKnowledge();
                    mainKnowledgeEntity.Ysw_IsMain = true;
                    mainKnowledgeEntity.Ysw_CreateTime = now;
                    mainKnowledgeEntity.Ysw_Creator = currentUser;
                    saveKnowledge = bll.InsertMainKnowledge;
                }
                else
                {
                    mainKnowledgeEntity.EnableAudit();
                    saveKnowledge = bll.UpdateMainKnowledge;
                }
                mainKnowledgeEntity.Ysw_Editor = currentUser;
                mainKnowledgeEntity.Ysw_KnowledgeId = subject.Knowledge;
                mainKnowledgeEntity.Ysw_UpdateTime = now;
            }

            entity = mainKnowledgeEntity;
            return saveKnowledge;
        }