/// <summary> /// 更新课程分类 /// </summary> /// <param name="courseId">课程id</param> /// <param name="courseCategoryIds">分类id数组</param> /// <returns></returns> public async Task UpdateCourseToCategory(long courseId, params long[] courseCategoryIds) { await this.RemoveAllByCourseId(courseId); foreach (var courseCategoryId in courseCategoryIds) { await EntityRepo.InsertAsync(new CourseToCourseCategory { CourseId = courseId, CourseCategoryId = courseCategoryId }); } }
/// <summary> /// 添加课程到分类 /// </summary> /// <param name="courseCategoryId">分类id</param> /// <param name="courseId">课程id</param> /// <returns></returns> public async Task AddCourseToCategory(long courseCategoryId, long courseId) { if (await IsExist(courseId, courseCategoryId)) { return; } await EntityRepo.InsertAsync(new CourseToCourseCategory { CourseId = courseId, CourseCategoryId = courseCategoryId }); }
/// <summary> /// 添加课程到分类 - 批量 /// </summary> /// <param name="courseCategoryId">分类id</param> /// <param name="courseIds">课程id集合</param> /// <returns></returns> public async Task BatchAddCourseToCategory(long courseCategoryId, List <long> courseIds) { if (courseIds == null || courseIds.Count == 0) { return; } var createCourseIds = courseIds.Except(this.GetCateCourses(courseCategoryId)); if (createCourseIds.Count() == 0) { return; } foreach (var courseId in createCourseIds) { await EntityRepo.InsertAsync(new CourseToCourseCategory { CourseId = courseId, CourseCategoryId = courseCategoryId }); } }
/// <summary> /// 更加旧数据,添加新数据到数据库中 /// </summary> public async Task SychronousVideoInsertToData(List <VideoResource> newVideoInfos) { var newVideoIds = newVideoInfos.Select(a => a.VideoId).ToList(); //已经存在的数据, var dataVideoInfos = await QueryAsNoTracking .Where(a => newVideoIds.Contains(a.VideoId)).ToListAsync(); //已经存在的数据,做数据更新处理 var updateVideos = newVideoInfos.Where(a => dataVideoInfos.Exists(d => d.VideoId == a.VideoId)).ToList(); updateVideos.ForEach(o => newVideoInfos.Remove(o)); foreach (var newVideoInfo in newVideoInfos) { await EntityRepo.InsertAsync(newVideoInfo); } foreach (var entity in updateVideos) { //更新数据中的数据 var tempEntity = dataVideoInfos.Find(o => o.VideoId == entity.VideoId); if (tempEntity == null) { continue; } var id = tempEntity.Id; tempEntity = entity; tempEntity.Id = id; await UpdateAsync(tempEntity); } }