Exemplo n.º 1
0
        /// <summary>
        /// 生成课程编码
        /// 规则: 来源(2位)-支付方式(2位)-时间戳(秒级)-属于用户当日订单数量+1(3位)
        /// </summary>
        /// <param name="sourceType">订单来源</param>
        /// <param name="time">属于用户当日订单数量</param>
        /// <returns></returns>
        public string GetCourseMaxCode(OrderSourceType sourceType, DateTime?time = null)
        {
            var precode = RandomHelper.GetRandom(1, 9) + Convert.ToInt32(sourceType).ToString();

            var date          = time ?? DateTime.Now;
            var codeStateWith = precode + date.ToString("yyyyMMdd"); //截取数据格式:年-月-日 20191021

            var code = codeStateWith;

            var list = QueryAsNoTracking.Where(e => e.CourseCode.StartsWith(codeStateWith))
                       .ToList();
            var model = list.Select(e => new { Number = e.CourseCode.Substring(code.Length).CastTo(0) })
                        .OrderByDescending(e => e.Number).FirstOrDefault(); //返回订单的最后一位

            if (model != null)
            {
                code += (model.Number + 1).ToString().PadLeft(2, '0');
            }
            else
            {
                code += "01";
            }

            return(code);
        }
        /// <summary>
        /// 判断课程是否关联学员
        /// </summary>
        /// <param name="courseId">课程id</param>
        /// <param name="studentId">学员id</param>
        /// <returns></returns>
        public async Task <bool> IsExist(long courseId, long studentId)
        {
            var count = await QueryAsNoTracking
                        .Where(o => o.CourseId == courseId && o.StudentId == studentId)
                        .CountAsync();

            return(count > 0);
        }
        /// <summary>
        /// 判断课程是否存在分类中
        /// </summary>
        /// <param name="courseId">课程id</param>
        /// <param name="courseCategoryId">课程分类id</param>
        /// <returns></returns>
        protected virtual async Task <bool> IsExist(long courseId, long courseCategoryId)
        {
            var result = await QueryAsNoTracking.CountAsync(
                ccate => ccate.CourseId == courseId && ccate.CourseCategoryId == courseCategoryId
                );

            return(result > 0);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 根据章节获取课时集合
        /// </summary>
        /// <param name="courseSectionId">课时章节id</param>
        /// <returns></returns>

        public virtual async Task <List <CourseClassHour> > GetBySectionId(long courseSectionId)
        {
            var entityList = await
                             QueryAsNoTracking
                             .Where(o => o.CourseSectionId == courseSectionId)
                             .ToListAsync();

            return(entityList);
        }
Exemplo n.º 5
0
 public async Task <Order> GetUserFirstOrderByStatus(long?userId, OrderStatusEnum orderStatusEnum)
 {
     try
     {
         return(await QueryAsNoTracking
                .Where(o => o.CreatorUserId == userId.Value && o.Status == orderStatusEnum)
                .FirstOrDefaultAsync());
     }
     catch
     {
         return(null);
     }
 }
Exemplo n.º 6
0
        // TODO:编写领域业务代码



        public async Task <Order> GetById(Guid orderId)
        {
            try
            {
                return(await QueryAsNoTracking
                       .Where(o => o.Id == orderId)
                       .FirstOrDefaultAsync());
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 根据章节获取课时集合
        /// </summary>
        /// <param name="courseSectionIdList">课时章节id集合</param>
        /// <returns></returns>
        public virtual async Task <List <CourseClassHour> > GetCourseClassHoursBySectionIdList(List <long> courseSectionIdList)
        {
            if (courseSectionIdList == null || courseSectionIdList.Count == 0)
            {
                return(null);
            }

            var entityList = await QueryAsNoTracking
                             .Where(o => courseSectionIdList.Contains(o.CourseSectionId))
                             .ToListAsync();


            return(entityList);
        }
        /// <summary>
        /// 查询分类对应的课程数量
        /// </summary>
        /// <returns></returns>
        public async Task <Dictionary <long, int> > CateCourseCounts()
        {
            var result = new Dictionary <long, int>();

            var queryResult = await QueryAsNoTracking.GroupBy(x => x.CourseCategoryId)
                              .Select(groupCourses => new { cateId = groupCourses.Key, count = groupCourses.Count() })
                              .ToListAsync();

            foreach (var item in queryResult)
            {
                result[item.cateId] = item.count;
            }

            return(result);
        }
        /// <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);
            }
        }
 /// <summary>
 /// 查询课程对应的学员关联信息
 /// </summary>
 /// <param name="courseId"></param>
 /// <returns></returns>
 public IQueryable <CourseToStudent> GetCourseToStudents(long courseId)
 {
     return(QueryAsNoTracking.Where(o => o.CourseId == courseId));
 }
Exemplo n.º 11
0
 /// <summary>
 /// 查询课程对应的教师信息
 /// </summary>
 /// <param name="courseId"></param>
 /// <returns></returns>
 public IQueryable <CourseToTeacher> GetCourseToTeachers(long courseId)
 {
     return(QueryAsNoTracking.Where(o => o.CourseId == courseId));
 }
 /// <summary>
 /// 根据课程id获取所有分类id
 /// </summary>
 /// <param name="courseId">课程id</param>
 /// <returns></returns>
 public IQueryable <long> GetCateByCourseId(long courseId)
 {
     return(QueryAsNoTracking
            .Where(o => o.CourseId == courseId)
            .Select(o => o.CourseCategoryId));
 }
 /// <summary>
 /// 获取分类id拥有的课程id
 /// </summary>
 /// <param name="courseCategoryId">课程分类id</param>
 /// <returns></returns>
 public IQueryable <long> GetCateCourses(long courseCategoryId)
 {
     return(QueryAsNoTracking
            .Where(courseCate => courseCate.CourseCategoryId == courseCategoryId)
            .Select(courseCate => courseCate.CourseId));
 }
        public async Task <bool> IsExistAsync(long id)
        {
            var result = await QueryAsNoTracking.AnyAsync(a => a.Id == id);

            return(result);
        }
 public async Task <VideoResource> GetLastVideoResource()
 {
     return(await QueryAsNoTracking.LastOrDefaultAsync());
 }