Example #1
0
        /// <summary>
        /// 单个校区课程授权数据构造
        /// <para>作    者: Huang GaoLiang </para>
        /// <para>创建时间: 2018-10-19</para>
        /// </summary>
        /// <param name="courseIds">课程编号集合</param>
        /// <returns>返回校区课程数据集合</returns>
        private List <TblDatSchoolCourse> SchoolCouseDataConstructe(ref List <long> courseIds)
        {
            List <TblDatSchoolCourse> schoolCourseList = new List <TblDatSchoolCourse>();

            // 1、查询有已经授权过的课程编号
            List <TblDatSchoolCourse> usedCorseList = _schoolCourseRepository.Value.GetSchoolCourseByWhere(_schoolId, courseIds).Result.ToList();

            schoolCourseList.AddRange(usedCorseList);

            // 2、将UpdateTime 更新到当前的时间
            foreach (TblDatSchoolCourse item in schoolCourseList)
            {
                item.UpdateTime = DateTime.Now;
            }

            // 3、求差集(过滤掉数据库里面的课程编号)
            List <long> dbCourseId = usedCorseList.Select(m => m.CourseId).Distinct().ToList();

            courseIds = courseIds.Except(dbCourseId).ToList();

            foreach (long courseId in courseIds)
            {
                TblDatSchoolCourse schoolCourse = new TblDatSchoolCourse
                {
                    CreateTime     = DateTime.Now,
                    SchoolCourseId = IdGenerator.NextId(),
                    CourseId       = courseId,
                    SchoolId       = _schoolId,
                    UpdateTime     = DateTime.Now
                };
                schoolCourseList.Add(schoolCourse);
            }

            return(schoolCourseList);
        }
Example #2
0
        /// <summary>
        /// 覆盖保存,数据不存在时添加,存在时则忽略
        /// <para>作    者: Huang GaoLiang </para>
        /// <para>创建时间: 2018-10-18</para>
        /// </summary>
        /// <param name="courses">课程编号</param>
        public async Task SaveCoverAsync(List <long> courses)
        {
            List <long> courseIds = courses;

            // 1、根据校区编号和课程编号查询授权
            if (courses != null && courses.Any())
            {
                List <long> ids = _schoolCourseRepository.Value.GetSchoolCourseByWhere(_schoolId, courseIds).Result.Select(m => m.CourseId).Distinct().ToList();
                courseIds = courseIds.Except(ids).ToList();
            }
            // 2、批量添加
            List <TblDatSchoolCourse> schoolCourseList = new List <TblDatSchoolCourse>();

            if (courseIds != null)
            {
                foreach (long item in courseIds)
                {
                    TblDatSchoolCourse schoolCourse = new TblDatSchoolCourse
                    {
                        SchoolCourseId = IdGenerator.NextId(),
                        SchoolId       = _schoolId,
                        CourseId       = item,
                        CreateTime     = DateTime.Now,
                        UpdateTime     = DateTime.Now
                    };
                    schoolCourseList.Add(schoolCourse);
                }
                await _schoolCourseRepository.Value.AddTask(schoolCourseList);
            }
        }