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); } } }
private Dictionary <int, int[]> GetGroupDictionary(List <int> subjectIds) { SubjectGroupBll groupBll = new SubjectGroupBll(); IList <Yw_SubjectGroup> groups = groupBll.GetBySubjectIds(subjectIds); Dictionary <int, int[]> dic = new Dictionary <int, int[]>(); foreach (Yw_SubjectGroup g in groups) { if (!string.IsNullOrEmpty(g.Ysg_RelSubjectId)) { string[] tempIdStrs = g.Ysg_RelSubjectId.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); int[] tempIds = tempIdStrs.Select(x => Convert.ToInt32(x)).ToArray(); dic[g.Ysg_SubjectId] = tempIds; } } return(dic); }