예제 #1
0
        /// <summary>
        /// 分页列表
        /// </summary>
        /// <param name="search"></param>
        /// <returns></returns>
        public async Task <AppSrvResult <PageModelDto <CustomerDto> > > GetPagedAsync(CustomerSearchPagedDto search)
        {
            var whereCondition = ExpressionCreator
                                 .New <Customer>()
                                 .AndIf(search.Id > 0, x => x.Id == search.Id)
                                 .AndIf(search.Account.IsNotNullOrEmpty(), x => x.Account == search.Account);

            var count = await _customerRepo.CountAsync(whereCondition);

            if (count == 0)
            {
                return(new PageModelDto <CustomerDto>(search));
            }

            var customers = await _customerRepo
                            .Where(whereCondition)
                            .Select(x => new CustomerDto
            {
                Id                 = x.Id,
                Account            = x.Account,
                Nickname           = x.Nickname,
                Realname           = x.Realname,
                CreateBy           = x.CreateBy,
                CreateTime         = x.CreateTime,
                FinanceInfoBalance = x.FinanceInfo.Balance
            })
                            .Skip(search.SkipRows())
                            .Take(search.PageSize)
                            .OrderByDescending(x => x.Id)
                            .ToListAsync();

            return(new PageModelDto <CustomerDto>(search, customers, count));
        }
예제 #2
0
        /// <summary>
        /// 分页列表
        /// </summary>
        /// <param name="search"></param>
        /// <returns></returns>
        public async Task <AppSrvResult <PageModelDto <CustomerDto> > > GetPagedAsync(CustomerSearchPagedDto search)
        {
            Expression <Func <Customer, bool> > whereCondition = x => true;

            if (search.Id.ToLong() > 0)
            {
                whereCondition = whereCondition.And(x => x.Id == search.Id.ToLong());
            }
            if (search.Account.IsNotNullOrEmpty())
            {
                whereCondition = whereCondition.And(x => x.Account == search.Account);
            }

            var count = await _customerRepo.CountAsync(whereCondition);

            if (count == 0)
            {
                return(new PageModelDto <CustomerDto>(search));
            }

            //这里用直接用dapper更方便_customerRepo.QueryAsync(sql)
            var customers = await _customerRepo
                            .Where(whereCondition)
                            .Select(x => new CustomerDto
            {
                Id = x.Id.ToString()
                ,
                Account = x.Account
                ,
                Nickname = x.Nickname
                ,
                Realname = x.Realname
                ,
                CreateBy = x.CreateBy
                ,
                CreateTime = x.CreateTime
                ,
                FinanceInfoBalance = x.FinanceInfo.Balance
            })
                            .Skip(search.SkipRows())
                            .Take(search.PageSize)
                            .OrderByDescending(x => x.Id)
                            .ToListAsync();

            return(new PageModelDto <CustomerDto>(search, customers, count));
        }