Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge branch dev with rel-9.1 #22123

Merged
merged 12 commits into from
Feb 12, 2025
Prev Previous commit
Next Next commit
Fix Blog post tag filtering problem
  • Loading branch information
realLiangshiwei committed Feb 11, 2025
commit 95690651236a343a8d7c2399d68f4fcb6f2e625c
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ public virtual async Task<int> GetCountAsync(
BlogPostStatus? statusFilter = null,
CancellationToken cancellationToken = default)
{
List<string> entityIdFilters = null;
List<Guid> entityIdFilters = null;
if (tagId.HasValue)
{
entityIdFilters = await _entityTagManager.GetEntityIdsFilteredByTagAsync(tagId.Value, CurrentTenant.Id, cancellationToken);
entityIdFilters = (await _entityTagManager.GetEntityIdsFilteredByTagAsync(tagId.Value, CurrentTenant.Id, cancellationToken)).Select(Guid.Parse).ToList();
}

var queryable = (await GetDbSetAsync())
.WhereIf(entityIdFilters != null, x => entityIdFilters.Contains(x.Id.ToString()))
.WhereIf(entityIdFilters != null, x => entityIdFilters.Contains(x.Id))
.WhereIf(blogId.HasValue, x => x.BlogId == blogId)
.WhereIf(authorId.HasValue, x => x.AuthorId == authorId)
.WhereIf(statusFilter.HasValue, x => x.Status == statusFilter)
Expand All @@ -86,14 +86,14 @@ public virtual async Task<List<BlogPost>> GetListAsync(
var blogPostsDbSet = dbContext.Set<BlogPost>();
var usersDbSet = dbContext.Set<CmsUser>();

List<string> entityIdFilters = null;
List<Guid> entityIdFilters = null;
if (tagId.HasValue)
{
entityIdFilters = await _entityTagManager.GetEntityIdsFilteredByTagAsync(tagId.Value, CurrentTenant.Id, cancellationToken);
entityIdFilters = (await _entityTagManager.GetEntityIdsFilteredByTagAsync(tagId.Value, CurrentTenant.Id, cancellationToken)).Select(Guid.Parse).ToList();
}

var queryable = (await GetDbSetAsync())
.WhereIf(entityIdFilters != null, x => entityIdFilters.Contains(x.Id.ToString()))
.WhereIf(entityIdFilters != null, x => entityIdFilters.Contains(x.Id))
.WhereIf(blogId.HasValue, x => x.BlogId == blogId)
.WhereIf(!string.IsNullOrWhiteSpace(filter), x => x.Title.Contains(filter) || x.Slug.Contains(filter))
.WhereIf(authorId.HasValue, x => x.AuthorId == authorId)
Expand Down
Loading