public async Task <PagedResultDto <QueryCourseStatisticsDto> > GetPagedCourseStatisticsAsync(QueryCourseStatisticsInput input) { var courseIdList = new List <long>(); if (input.CatetoryId.HasValue && input.CatetoryId.Value > 0) { var category = await _courseCategoryManager.FindByIdAsync(input.CatetoryId.Value); if (category != null) { courseIdList = _courseToCourseCategoryManager .QueryAsNoTracking .Include(e => e.CourseCategory) .Where(x => x.CourseCategory.Code.StartsWith(category.Code)).Select(x => x.CourseId).ToList(); } } var isHaveAdminRole = await _userManager.IsHaveAdminRole(AbpSession.UserId.Value); var query = _courseManager.QueryAsNoTracking .WhereIf(!string.IsNullOrEmpty(input.FilterText), x => x.Title.Contains(input.FilterText)) .WhereIf(input.CourseVideoType.HasValue, x => x.CourseVideoType == input.CourseVideoType) .WhereIf(input.CatetoryId.HasValue && input.CatetoryId.Value > 0, x => courseIdList.Contains(x.Id)) .WhereIf(!isHaveAdminRole, e => e.CourseToTeacher.Any(x => x.TeacherId == AbpSession.UserId.Value)); var courseCount = await query.CountAsync(); var course = await query.PageBy(input) .Select(e => new QueryCourseStatisticsDto() { Id = e.Id, Title = e.Title, StudentCount = 0, TotalMoney = 0, CourseState = e.CourseState, CourseVideoType = e.CourseVideoType, //TotalTime = e.CourseSections.Sum(a => // a.CourseSection.VideoResources.Sum(d => d.VideoResource.Duration.Value) // ) }).ToListAsync(); //var ids = course.Select(e => e.Id).ToList(); return(new PagedResultDto <QueryCourseStatisticsDto>( courseCount, course )); }