Пример #1
0
        public void AddSubjectToLesson(Yw_CourseLesson lesson, int subjectId)
        {
            Yw_CourseSubjectRelation rel = Repository.GetDirectRelation(lesson.Ycl_Id, subjectId);

            if (rel == null)
            {
                SubjectBll subjectBll = new SubjectBll();
                Yw_Subject subject    = subjectBll.GetSubject(subjectId);

                rel = new Yw_CourseSubjectRelation();
                rel.Ysr_CourseId        = lesson.Ycl_CourseId;
                rel.Ysr_CreateTime      = DateTime.Now;
                rel.Ysr_DirectSubjectId = 0;
                rel.Ysr_IsDirect        = true;
                rel.Ysr_LessonId        = lesson.Ycl_Id;
                rel.Ysr_LessonIndex     = lesson.Ycl_Index;
                rel.Ysr_SubjectId       = subjectId;
                rel.Ysr_SubjectType     = subject.Ysj_SubjectType;
                Repository.Add(rel);

                SubjectGroupBll groupBll = new SubjectGroupBll();
                Yw_SubjectGroup group    = groupBll.GetBySubjectId(subjectId);
                if (group != null && !string.IsNullOrEmpty(group.Ysg_RelSubjectId))
                {
                    int[] subjectIds = group.Ysg_RelSubjectId.Split(',').Select(x => Convert.ToInt32(x)).ToArray();
                    Repository.CreateInDirectRelation(rel.Ysr_Id, subjectIds);
                }
            }
        }
        public void AddSubjectToLessonTestMethod()
        {
            CourseSubjectRelBll bll       = new CourseSubjectRelBll();
            LessonBll           lessonBll = new LessonBll();
            Yw_CourseLesson     lesson    = lessonBll.GetLesson(10023);

            bll.AddSubjectToLesson(lesson, 10005);
        }
        public void AddSubjectToLessonTest()
        {
            LessonBll           lessonBll = new LessonBll();
            Yw_CourseLesson     lesson    = lessonBll.GetLesson(10022);
            CourseSubjectRelBll bll       = new CourseSubjectRelBll();

            bll.AddSubjectToLesson(lesson, new List <int> {
                10042, 10043
            });
        }
Пример #4
0
        public void AddSubjectToLessonTest()
        {
            Yw_CourseLesson lesson = new Yw_CourseLesson();

            lesson.Ycl_Id       = 20000;
            lesson.Ycl_CourseId = 20000;
            lesson.Ycl_Index    = 1;

            CourseSubjectRelBll bll = new CourseSubjectRelBll();

            bll.AddSubjectToLesson(lesson, 10000);
        }
Пример #5
0
        /// <summary>
        /// 将一组题目加入到课时,题目与课时建立直接关系,题目的关联题目与课时建立间接关系
        /// </summary>
        /// <param name="lesson"></param>
        /// <param name="subjectId"></param>
        public void AddSubjectToLesson(Yw_CourseLesson lesson, List <int> subjectIds)
        {
            List <int> newSubjectIds = subjectIds.Distinct().ToList();
            List <Yw_CourseSubjectRelation> existingRel = Repository.GetDirectRelationsOfLesson(lesson.Ycl_Id);

            List <int> existingSubIds = existingRel.Select(x => x.Ysr_SubjectId).ToList();
            List <int> deletedIds     = existingSubIds.Except(newSubjectIds).ToList();
            List <int> addIds         = newSubjectIds.Except(existingSubIds).ToList();

            if (addIds.Count > 0)
            {
                Dictionary <int, int[]> dic            = GetGroupDictionary(addIds);
                IEnumerable <int>       tempSubjectIds = GetAllItemOfDictionary(dic);

                SubjectBll                   bll      = new SubjectBll();
                List <Yw_Subject>            subjects = bll.GetByIds(tempSubjectIds.ToList());
                Dictionary <int, Yw_Subject> subDic   = subjects.ToDictionary(x => x.Ysj_Id, x => x);

                DataTable table = BuildBulkTable();

                foreach (KeyValuePair <int, int[]> pair in dic)
                {
                    if (subDic.ContainsKey(pair.Key))
                    {
                        BuildBulkRow(table, lesson.Ycl_CourseId, lesson.Ycl_Id, lesson.Ycl_Index, pair.Key, subDic[pair.Key].Ysj_SubjectType, true, pair.Key);
                    }
                    foreach (int id in pair.Value)
                    {
                        if (subDic.ContainsKey(id))
                        {
                            BuildBulkRow(table, lesson.Ycl_CourseId, lesson.Ycl_Id, lesson.Ycl_Index, id, subDic[id].Ysj_SubjectType, false, pair.Key);
                        }
                    }
                }

                Repository.AddBatch(table);
            }

            if (deletedIds.Count > 0)
            {
                Repository.DeleteDirectRelationOfLesson(lesson.Ycl_Id, deletedIds);
            }
        }