/// <summary> /// 返回题目(获取题目难度) /// </summary> /// <param name="ids"></param> /// <returns></returns> public List <Yw_Subject> GetSubjects(List <int> ids) { List <Yw_Subject> subjects = new List <Yw_Subject>(); SubjectBll subjectBll = new SubjectBll(); subjects = subjectBll.GetByIds(ids); return(subjects); }
/// <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); } }