/// <summary>搜索 用户凭证 ,返回分页结果。</summary>
    public async Task <PaginatedResponseModel <AppUserTokenModel> > SearchAsync(
        AppUserTokenSearchModel model,
        string userId = ""
        )
    {
        var query = Session.Query <AppUserToken>();

        if (userId.IsNotNullOrEmpty())
        {
            query = query.Where(e => e.User.Id == userId);
        }
        var keywords = model.Keywords;

        if (keywords.IsNotNullOrEmpty())
        {
            query = query.Where(e => e.Name.Contains(keywords) || e.Value == keywords);
        }
        var total = await query.LongCountAsync();

        var data = await query.OrderByDescending(e => e.Id)
                   .Skip(model.Skip).Take(model.Take)
                   .ToListAsync();

        return(new PaginatedResponseModel <AppUserTokenModel> {
            Total = total,
            Data = Mapper.Map <IList <AppUserTokenModel> >(data),
            Skip = model.Skip,
            Take = model.Take
        });
    }
示例#2
0
        public async Task _02_CanDoSearchAsync()
        {
            var searchModel = new AppUserTokenSearchModel {
                Skip = 0,
                Take = 10
            };
            var result = await Target.SearchAsync(searchModel);

            Assert.GreaterOrEqual(result.Total, 0);
            Assert.GreaterOrEqual(result.Take, result.Data.Count);
        }
示例#3
0
        public async Task <ActionResult <PaginatedResponseModel <AppUserTokenModel> > > Search(
            [FromQuery] AppUserTokenSearchModel model
            )
        {
            try {
                var result = await repository.SearchAsync(model);

                return(result);
            }
            catch (Exception ex) {
                logger.LogError(ex, $"Can not search app_user_tokens with {model.ToJson()} .");
                return(this.InternalServerError(ex));
            }
        }
示例#4
0
        public async Task <ActionResult <PaginatedResponseModel <AppUserTokenModel> > > Search(
            [FromQuery] AppUserTokenSearchModel model
            )
        {
            try {
                var userId = this.GetUserId();
                var models = await userTokenRepo.SearchAsync(model, userId);

                return(models);
            }
            catch (Exception ex) {
                logger.LogError(ex, $"Can not get all tokens for user {User.Identity.Name} .");
                return(this.InternalServerError(ex));
            }
        }