public virtual async Task <int> GetCountAsync(
        string filter = null,
        Guid?blogId   = null,
        Guid?authorId = null,
        Guid?tagId    = null,
        BlogPostStatus?statusFilter         = null,
        CancellationToken cancellationToken = default)
    {
        cancellationToken = GetCancellationToken(cancellationToken);

        List <string> entityIdFilters = null;

        if (tagId.HasValue)
        {
            entityIdFilters = await _entityTagManager.GetEntityIdsFilteredByTagAsync(tagId.Value, CurrentTenant.Id, cancellationToken);
        }

        return(await(await GetMongoQueryableAsync(cancellationToken))
               .WhereIf <BlogPost, IMongoQueryable <BlogPost> >(entityIdFilters != null, x => entityIdFilters.Contains(x.Id.ToString()))
               .WhereIf <BlogPost, IMongoQueryable <BlogPost> >(!string.IsNullOrWhiteSpace(filter), x => x.Title.Contains(filter) || x.Slug.Contains(filter))
               .WhereIf <BlogPost, IMongoQueryable <BlogPost> >(blogId.HasValue, x => x.BlogId == blogId)
               .WhereIf <BlogPost, IMongoQueryable <BlogPost> >(authorId.HasValue, x => x.AuthorId == authorId)
               .WhereIf <BlogPost, IMongoQueryable <BlogPost> >(statusFilter.HasValue, x => x.Status == statusFilter)
               .CountAsync(cancellationToken));
    }
Exemple #2
0
    public virtual async Task <int> GetCountAsync(
        string filter = null,
        Guid?blogId   = null,
        Guid?authorId = null,
        Guid?tagId    = null,
        BlogPostStatus?statusFilter         = null,
        CancellationToken cancellationToken = default)
    {
        List <string> entityIdFilters = null;

        if (tagId.HasValue)
        {
            entityIdFilters = await _entityTagManager.GetEntityIdsFilteredByTagAsync(tagId.Value, CurrentTenant.Id, cancellationToken);
        }

        var queryable = (await GetDbSetAsync())
                        .WhereIf(entityIdFilters != null, x => entityIdFilters.Contains(x.Id.ToString()))
                        .WhereIf(blogId.HasValue, x => x.BlogId == blogId)
                        .WhereIf(authorId.HasValue, x => x.AuthorId == authorId)
                        .WhereIf(statusFilter.HasValue, x => x.Status == statusFilter)
                        .WhereIf(!string.IsNullOrEmpty(filter), x => x.Title.Contains(filter) || x.Slug.Contains(filter));

        var count = await queryable.CountAsync(GetCancellationToken(cancellationToken));

        return(count);
    }