Example #1
0
        public async Task GetPageAsync_Test()
        {
            FilterCondition condition = new FilterCondition();
            QueryFilter     filter    = new QueryFilter();
            //condition.Field = "Name";
            //condition.Value = "大黄瓜18CM";
            //filter.Conditions.Add(condition);
            var exp = FilterHelp.GetExpression <TestDB>(filter);

            OrderCondition[] orderConditions = new OrderCondition[] {
                new OrderCondition("Name", Sukt.Module.Core.Enums.SortDirectionEnum.Descending),
                new OrderCondition("CreatedTime")
            };
            PagedRequest pagedRequest = new PagedRequest();

            pagedRequest.OrderConditions = orderConditions;
            var page = await _mongoDBRepository.Collection.ToPageAsync(exp, pagedRequest);

            Assert.True(page.Data.Count == 10);
            var page1 = await _mongoDBRepository.Collection.ToPageAsync(exp, pagedRequest, o => new TestDto
            {
                Id   = o.Id,
                Name = o.Name
            });

            Assert.True(page1.Data.Count == 10);
        }
Example #2
0
        /// <summary>
        /// 异步得到用户分页
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <PageResult <UserOutputPageListDto> > GetUserPageAsync(PageRequest request)
        {
            request.NotNull(nameof(request));
            var expression = FilterHelp.GetExpression <User>(request.Filters);

            return(await _userManager.Users.AsNoTracking().ToPageAsync <User, UserOutputPageListDto>(expression, request.PageParameters));
        }
Example #3
0
        public async Task <PageResult <MenuTableOutDto> > GetMenuTableAsync(PageRequest requst)
        {
            requst.NotNull(nameof(requst));
            var expression = FilterHelp.GetExpression <MenuEntity>(requst.FilterJson);

            return(await _menuRepository.TrackEntities.ToPageAsync <MenuEntity, MenuTableOutDto>(expression, requst));
        }
Example #4
0
        public async Task <PageResult <DataDictionaryOutPageListDto> > GetDictionnnaryPageAsync(PageRequest request)
        {
            request.NotNull(nameof(request));
            var expression = FilterHelp.GetExpression <DataDictionaryEntity>(request.Filters);

            return(await _dataDictionnaryRepository.TrackEntities.ToPageAsync <DataDictionaryEntity, DataDictionaryOutPageListDto>(expression, request.PageParameters));
        }
Example #5
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public async Task <IPageResult <AuditLogOutputPageDto> > GetAuditLogPageAsync(PageRequest request)
        {
            var exp = FilterHelp.GetExpression <AuditLog>(request.queryFilter);

            return(await _auditLogRepository.Collection.ToPageAsync(exp, request, x => new AuditLogOutputPageDto
            {
                BrowserInformation = x.BrowserInformation,
                Ip = x.Ip,
                FunctionName = x.FunctionName,
                Action = x.Action,
                ExecutionDuration = x.ExecutionDuration,
                Id = x.Id
            }));
        }
        public async Task <PageResult <DataDictionaryOutDto> > GetResultAsync(BaseQuery query)
        {
            var param = new PageParameters(query.PageIndex, query.PageRow);

            param.OrderConditions = new OrderCondition[]
            {
                new OrderCondition(query.SortName, query.SortDirection)
            };
            QueryFilter queryFilter = new QueryFilter(query.FilterConnect, query.Filters);
            var         expression  = FilterHelp.GetExpression <DataDictionaryEntity>(queryFilter);
            var         result      = await _dataDictionary.NoTrackEntities.ToPageAsync <DataDictionaryEntity, DataDictionaryOutDto>(expression, param);

            return(result);
        }
        /// <summary>
        /// 从集合中查询指定输出DTO的分页信息
        /// </summary>
        /// <typeparam name="TEntity">动态实体类型</typeparam>
        /// <typeparam name="TOutputDto">输出DTO数据类型</typeparam>
        /// <param name="source">数据源</param>
        /// <param name="predicate">查询条件表达式</param>
        /// <param name="pageParameters">分页参数</param>
        /// <returns></returns>
        public static async Task <PageResult <TEntity> > ToPageAsync <TEntity>(this IQueryable <TEntity> source, IPagedRequest request)
        {
            request.NotNull(nameof(request));
            var isFiltered = request is IFilteredPagedRequest;
            Expression <Func <TEntity, bool> > expression = null;

            if (isFiltered)
            {
                var filter = (request as IFilteredPagedRequest).queryFilter;
                expression = filter == null ? null : FilterHelp.GetExpression <TEntity>(filter);
            }
            var result = await source.WhereAsync(request.PageIndex, request.PageRow, expression, request.OrderConditions);

            var list = await result.data.ToArrayAsync();

            var total = result.totalNumber;

            return(new PageResult <TEntity>(list, total));
        }
Example #8
0
        ///// <summary>
        ///// 从集合中查询指定输出DTO的分页信息
        ///// </summary>
        ///// <typeparam name="TEntity">动态实体类型</typeparam>
        ///// <typeparam name="TOutputDto">输出DTO数据类型</typeparam>
        ///// <param name="source">数据源</param>
        ///// <param name="pageParameters">分页参数</param>
        ///// <returns></returns>
        public static async Task <IPagedResult <TOutputDto> > ToPageAsync <TEntity, TOutputDto>(this IQueryable <TEntity> source, IPagedRequest request)
            where TOutputDto : IOutputDto
        {
            request.NotNull(nameof(request));
            var isFiltered = request is IFilteredPagedRequest;
            Expression <Func <TEntity, bool> > expression = null;

            if (isFiltered)
            {
                var filters = (request as IFilteredPagedRequest).Filters;
                expression = FilterHelp.GetExpression <TEntity>(filters);
            }
            var result = await source.WhereAsync(request.PageIndex, request.PageSize, expression, request.OrderConditions);

            var list = await result.data.ToOutput <TOutputDto>().ToArrayAsync();

            var total = result.totalNumber;

            return(new PageResult <TOutputDto>(list, total));
        }