diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Ratings/EfCoreRatingRepository.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Ratings/EfCoreRatingRepository.cs index b9f210cdcf..577f2e3a7d 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Ratings/EfCoreRatingRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Ratings/EfCoreRatingRepository.cs @@ -18,7 +18,8 @@ namespace Volo.CmsKit.Ratings { } - public async Task> GetListAsync(string entityType, string entityId, CancellationToken cancellationToken = default) + public async Task> GetListAsync(string entityType, string entityId, + CancellationToken cancellationToken = default) { Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); @@ -29,31 +30,36 @@ namespace Volo.CmsKit.Ratings return ratings; } - public async Task GetCurrentUserRatingAsync(string entityType, string entityId, Guid userId, CancellationToken cancellationToken = default) + public async Task GetCurrentUserRatingAsync(string entityType, string entityId, Guid userId, + CancellationToken cancellationToken = default) { Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); - var rating = await DbSet.FirstOrDefaultAsync(r => r.EntityType == entityType && r.EntityId == entityId && r.CreatorId == userId, GetCancellationToken(cancellationToken)); + var rating = await DbSet.FirstOrDefaultAsync( + r => r.EntityType == entityType && r.EntityId == entityId && r.CreatorId == userId, + GetCancellationToken(cancellationToken)); return rating; } - public async Task> GetGroupedStarCountsAsync(string entityType, string entityId, CancellationToken cancellationToken = default) + public async Task> GetGroupedStarCountsAsync(string entityType, + string entityId, CancellationToken cancellationToken = default) { Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); - var query = from rating in DbSet + var query = ( + from rating in DbSet where rating.EntityType == entityType && rating.EntityId == entityId - orderby rating.StarCount descending group rating by rating.StarCount into g select new RatingWithStarCountQueryResultItem { StarCount = g.Key, Count = g.Count() - }; + } + ).OrderByDescending(r => r.StarCount); var ratings = await query.ToListAsync(GetCancellationToken(cancellationToken)); diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Ratings/MongoRatingRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Ratings/MongoRatingRepository.cs index a58b0517f4..ecf389cde7 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Ratings/MongoRatingRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Ratings/MongoRatingRepository.cs @@ -14,11 +14,13 @@ namespace Volo.CmsKit.MongoDB.Ratings { public class MongoRatingRepository : MongoDbRepository, IRatingRepository { - public MongoRatingRepository(IMongoDbContextProvider dbContextProvider) : base(dbContextProvider) + public MongoRatingRepository(IMongoDbContextProvider dbContextProvider) : base( + dbContextProvider) { } - public async Task> GetListAsync(string entityType, string entityId, CancellationToken cancellationToken = default) + public async Task> GetListAsync(string entityType, string entityId, + CancellationToken cancellationToken = default) { Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); @@ -38,7 +40,7 @@ namespace Volo.CmsKit.MongoDB.Ratings var rating = await GetMongoQueryable() .FirstOrDefaultAsync(r => r.EntityType == entityType && r.EntityId == entityId && r.CreatorId == userId, GetCancellationToken(cancellationToken)); - + return rating; } @@ -48,16 +50,17 @@ namespace Volo.CmsKit.MongoDB.Ratings Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); - var query = from rating in GetMongoQueryable() + var query = ( + from rating in GetMongoQueryable() where rating.EntityType == entityType && rating.EntityId == entityId - orderby rating.StarCount descending group rating by rating.StarCount into g select new RatingWithStarCountQueryResultItem { StarCount = g.Key, Count = g.Count() - }; + } + ).OrderByDescending(r => r.StarCount); var ratings = await query.ToListAsync(GetCancellationToken(cancellationToken));