diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Blogs/EfCoreBlogPostRepository.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Blogs/EfCoreBlogPostRepository.cs index 5a9c5d526a..e67427245e 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Blogs/EfCoreBlogPostRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Blogs/EfCoreBlogPostRepository.cs @@ -10,6 +10,8 @@ using Volo.Abp.EntityFrameworkCore; using Volo.CmsKit.EntityFrameworkCore; using System.Linq; using System.Data.Common; +using JetBrains.Annotations; +using Volo.Abp; using Volo.Abp.Domain.Entities; namespace Volo.CmsKit.Blogs @@ -20,30 +22,34 @@ namespace Volo.CmsKit.Blogs { } - public async Task GetBySlugAsync(Guid blogId, string slug, CancellationToken cancellationToken = default) + public async Task GetBySlugAsync(Guid blogId, [NotNull] string slug, + CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(slug, nameof(slug)); + var dbSet = await GetDbSetAsync(); return await dbSet - .Include(i=> i.Creator) - .Where(x => - x.BlogId == blogId && x.Slug.ToLower() == slug) - .FirstOrDefaultAsync(cancellationToken: cancellationToken) - ?? throw new EntityNotFoundException(typeof(BlogPost)); + .Include(i => i.Creator) + .Where(x => + x.BlogId == blogId && x.Slug.ToLower() == slug) + .FirstOrDefaultAsync(cancellationToken: GetCancellationToken(cancellationToken)) + ?? throw new EntityNotFoundException(typeof(BlogPost)); } public async Task GetCountAsync(Guid blogId, CancellationToken cancellationToken = default) { return await (await GetQueryableAsync()).CountAsync( - x => x.BlogId == blogId, - cancellationToken); + x => x.BlogId == blogId, + GetCancellationToken(cancellationToken)); } - public async Task> GetPagedListAsync(Guid blogId, int skipCount, int maxResultCount, string sorting, bool includeDetails = false, CancellationToken cancellationToken = default) + public async Task> GetPagedListAsync(Guid blogId, int skipCount, int maxResultCount, + string sorting, bool includeDetails = false, CancellationToken cancellationToken = default) { var queryable = (await GetQueryableAsync()) - .Include(i => i.Creator) - .Where(x => x.BlogId == blogId); + .Include(i => i.Creator) + .Where(x => x.BlogId == blogId); if (!sorting.IsNullOrWhiteSpace()) { @@ -51,16 +57,19 @@ namespace Volo.CmsKit.Blogs } return await queryable - .Skip(skipCount) - .Take(maxResultCount) - .ToListAsync(cancellationToken); + .Skip(skipCount) + .Take(maxResultCount) + .ToListAsync(GetCancellationToken()); } - public async Task SlugExistsAsync(Guid blogId, string slug, CancellationToken cancellationToken = default) + public async Task SlugExistsAsync(Guid blogId, [NotNull] string slug, + CancellationToken cancellationToken = default) { - var dbSet = await GetDbSetAsync(); + Check.NotNullOrEmpty(slug, nameof(slug)); - return await dbSet.AnyAsync(x => x.BlogId == blogId && x.Slug.ToLower() == slug, cancellationToken); + var dbSet = await GetDbSetAsync(); + return await dbSet.AnyAsync(x => x.BlogId == blogId && x.Slug.ToLower() == slug, + GetCancellationToken(cancellationToken)); } } -} +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Blogs/EfCoreBlogRepository.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Blogs/EfCoreBlogRepository.cs index f04889299c..c39dee2685 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Blogs/EfCoreBlogRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Blogs/EfCoreBlogRepository.cs @@ -3,6 +3,8 @@ using System; using System.Security.Cryptography.X509Certificates; using System.Threading; using System.Threading.Tasks; +using JetBrains.Annotations; +using Volo.Abp; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; using Volo.CmsKit.EntityFrameworkCore; @@ -17,12 +19,13 @@ namespace Volo.CmsKit.Blogs public virtual async Task ExistsAsync(Guid blogId, CancellationToken cancellationToken = default) { - return await (await GetQueryableAsync()).AnyAsync(x => x.Id == blogId, cancellationToken); + return await (await GetQueryableAsync()).AnyAsync(x => x.Id == blogId, GetCancellationToken(cancellationToken)); } - public virtual Task GetBySlugAsync(string slug, CancellationToken cancellationToken = default) + public virtual Task GetBySlugAsync([NotNull]string slug, CancellationToken cancellationToken = default) { - return GetAsync(x => x.Slug == slug, cancellationToken: cancellationToken); + Check.NotNullOrEmpty(slug, nameof(slug)); + return GetAsync(x => x.Slug == slug, cancellationToken: GetCancellationToken(cancellationToken)); } } } diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs index e8b88161ca..9a99bc5eca 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs @@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore; using System; using System.Threading; using System.Threading.Tasks; +using Volo.Abp; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; using Volo.CmsKit.EntityFrameworkCore; @@ -21,6 +22,9 @@ namespace Volo.CmsKit.Contents Guid? tenantId = null, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityType, nameof(entityType)); + Check.NotNullOrEmpty(entityId, nameof(entityId)); + return GetAsync(x => x.EntityType == entityType && x.EntityId == entityId && @@ -35,6 +39,9 @@ namespace Volo.CmsKit.Contents Guid? tenantId = null, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityType, nameof(entityType)); + Check.NotNullOrEmpty(entityId, nameof(entityId)); + return FindAsync(x => x.EntityType == entityType && x.EntityId == entityId && @@ -49,6 +56,9 @@ namespace Volo.CmsKit.Contents Guid? tenantId = null, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityType, nameof(entityType)); + Check.NotNullOrEmpty(entityId, nameof(entityId)); + return DeleteAsync(x => x.EntityType == entityType && x.EntityId == entityId && @@ -62,6 +72,9 @@ namespace Volo.CmsKit.Contents Guid? tenantId = null, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityType, nameof(entityType)); + Check.NotNullOrEmpty(entityId, nameof(entityId)); + var dbSet = await GetDbSetAsync(); return await dbSet.AnyAsync(x => x.EntityType == entityType && diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Pages/EfCorePageRepository.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Pages/EfCorePageRepository.cs index 3c213d98b3..d1d5578c02 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Pages/EfCorePageRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Pages/EfCorePageRepository.cs @@ -4,7 +4,9 @@ using System.Linq; using System.Linq.Dynamic.Core; using System.Threading; using System.Threading.Tasks; +using JetBrains.Annotations; using Microsoft.EntityFrameworkCore; +using Volo.Abp; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; using Volo.CmsKit.EntityFrameworkCore; @@ -43,18 +45,22 @@ namespace Volo.CmsKit.Pages .ToListAsync(GetCancellationToken(cancellationToken)); } - public virtual Task GetBySlugAsync(string slug, CancellationToken cancellationToken = default) + public virtual Task GetBySlugAsync([NotNull] string slug, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(slug, nameof(slug)); return GetAsync(x => x.Slug == slug, cancellationToken: GetCancellationToken(cancellationToken)); } - public virtual Task FindBySlugAsync(string slug, CancellationToken cancellationToken = default) + public virtual Task FindBySlugAsync([NotNull] string slug, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(slug, nameof(slug)); return FindAsync(x => x.Slug == slug, cancellationToken: GetCancellationToken(cancellationToken)); } - public virtual async Task ExistsAsync(string slug, CancellationToken cancellationToken = default) + public virtual async Task ExistsAsync([NotNull] string slug, + CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(slug, nameof(slug)); return await (await GetDbSetAsync()).AnyAsync(x => x.Slug == slug, GetCancellationToken(cancellationToken)); } } diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreEntityTagRepository.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreEntityTagRepository.cs index 5e1bbcebea..ae5d081b6a 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreEntityTagRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreEntityTagRepository.cs @@ -3,6 +3,7 @@ using System; using System.Linq; using System.Threading; using System.Threading.Tasks; +using Volo.Abp; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; using Volo.CmsKit.EntityFrameworkCore; @@ -30,11 +31,13 @@ namespace Volo.CmsKit.Tags [CanBeNull] Guid? tenantId, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityId, nameof(entityId)); + return base.FindAsync(x => x.TagId == tagId && x.EntityId == entityId && x.TenantId == tenantId, - cancellationToken: cancellationToken); + cancellationToken: GetCancellationToken(cancellationToken)); } } } \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreTagRepository.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreTagRepository.cs index 77c4854b8d..7325141c40 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreTagRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreTagRepository.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; +using Volo.Abp; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; using Volo.CmsKit.EntityFrameworkCore; @@ -23,6 +24,9 @@ namespace Volo.CmsKit.Tags Guid? tenantId = null, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityType, nameof(entityType)); + Check.NotNullOrEmpty(name, nameof(name)); + return await (await GetDbSetAsync()).AnyAsync(x => x.EntityType == entityType && x.Name == name && @@ -36,6 +40,9 @@ namespace Volo.CmsKit.Tags Guid? tenantId = null, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityType, nameof(entityType)); + Check.NotNullOrEmpty(name, nameof(name)); + return GetAsync(x => x.EntityType == entityType && x.Name == name && @@ -49,6 +56,9 @@ namespace Volo.CmsKit.Tags Guid? tenantId = null, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityType, nameof(entityType)); + Check.NotNullOrEmpty(name, nameof(name)); + return FindAsync(x => x.EntityType == entityType && x.Name == name && @@ -62,6 +72,9 @@ namespace Volo.CmsKit.Tags Guid? tenantId = null, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityType, nameof(entityType)); + Check.NotNullOrEmpty(entityId, nameof(entityId)); + var entityTagIds = await (await GetDbContextAsync()).Set() .Where(q => q.EntityId == entityId && q.TenantId == tenantId) .Select(q => q.TagId) diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogPostRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogPostRepository.cs index 85dc1b86e0..6c75e7fec3 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogPostRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogPostRepository.cs @@ -7,6 +7,8 @@ using System.Linq; using System.Linq.Dynamic.Core; using System.Threading; using System.Threading.Tasks; +using JetBrains.Annotations; +using Volo.Abp; using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.MongoDB; using Volo.CmsKit.Blogs; @@ -16,34 +18,40 @@ namespace Volo.CmsKit.MongoDB.Blogs { public class MongoBlogPostRepository : MongoDbRepository, IBlogPostRepository { - public MongoBlogPostRepository(IMongoDbContextProvider dbContextProvider) : base(dbContextProvider) + public MongoBlogPostRepository(IMongoDbContextProvider dbContextProvider) : base( + dbContextProvider) { } - public Task GetBySlugAsync(Guid blogId, string slug, CancellationToken cancellationToken = default) + public Task GetBySlugAsync(Guid blogId, [NotNull] string slug, + CancellationToken cancellationToken = default) { - return GetAsync(x => - x.BlogId == blogId && - x.Slug.ToLower() == slug, - includeDetails: true, - cancellationToken: cancellationToken); + Check.NotNullOrEmpty(slug, nameof(slug)); + + return GetAsync(x => + x.BlogId == blogId && + x.Slug.ToLower() == slug, + includeDetails: true, + cancellationToken: GetCancellationToken(cancellationToken)); } public async Task GetCountAsync(Guid blogId, CancellationToken cancellationToken = default) { return await AsyncExecuter.CountAsync( - await WithDetailsAsync(), - x => x.BlogId == blogId, - cancellationToken); + await WithDetailsAsync(), + x => x.BlogId == blogId, + GetCancellationToken(cancellationToken)); } - public async Task> GetPagedListAsync(Guid blogId, int skipCount, int maxResultCount, string sorting, bool includeDetails = false, CancellationToken cancellationToken = default) + public async Task> GetPagedListAsync(Guid blogId, int skipCount, int maxResultCount, + string sorting, bool includeDetails = false, CancellationToken cancellationToken = default) { - var dbContext = await GetDbContextAsync(cancellationToken); + var token = GetCancellationToken(cancellationToken); + var dbContext = await GetDbContextAsync(token); var blogPostQueryable = await WithDetailsAsync(); var queryable = blogPostQueryable - .Where(x => x.BlogId == blogId); + .Where(x => x.BlogId == blogId); if (!sorting.IsNullOrWhiteSpace()) { @@ -51,17 +59,20 @@ namespace Volo.CmsKit.MongoDB.Blogs } queryable = queryable - .Skip(skipCount) - .Take(maxResultCount); + .Skip(skipCount) + .Take(maxResultCount); - return await AsyncExecuter.ToListAsync(queryable, cancellationToken); + return await AsyncExecuter.ToListAsync(queryable, token); } - public async Task SlugExistsAsync(Guid blogId, string slug, CancellationToken cancellationToken = default) + public async Task SlugExistsAsync(Guid blogId, [NotNull] string slug, + CancellationToken cancellationToken = default) { - var queryable = await GetMongoQueryableAsync(); + Check.NotNullOrEmpty(slug, nameof(slug)); - return await queryable.AnyAsync(x => x.BlogId == blogId && x.Slug.ToLower() == slug, cancellationToken); + var token = GetCancellationToken(cancellationToken); + var queryable = await GetMongoQueryableAsync(token); + return await queryable.AnyAsync(x => x.BlogId == blogId && x.Slug.ToLower() == slug, token); } } -} +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogRepository.cs index 2b215d55c6..0cd46a130c 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogRepository.cs @@ -2,6 +2,8 @@ using System; using System.Threading; using System.Threading.Tasks; +using JetBrains.Annotations; +using Volo.Abp; using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.MongoDB; using Volo.CmsKit.Blogs; @@ -22,8 +24,9 @@ namespace Volo.CmsKit.MongoDB.Blogs cancellationToken); } - public virtual Task GetBySlugAsync(string slug, CancellationToken cancellationToken = default) + public virtual Task GetBySlugAsync([NotNull]string slug, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(slug, nameof(slug)); return GetAsync(x => x.Slug == slug, cancellationToken: cancellationToken); } } diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs index fed8fe6e2e..fded228c16 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs @@ -3,6 +3,7 @@ using MongoDB.Driver.Linq; using System; using System.Threading; using System.Threading.Tasks; +using Volo.Abp; using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.MongoDB; using Volo.CmsKit.Contents; @@ -11,7 +12,8 @@ namespace Volo.CmsKit.MongoDB.Contents { public class MongoContentRepository : MongoDbRepository, IContentRepository { - public MongoContentRepository(IMongoDbContextProvider dbContextProvider) : base(dbContextProvider) + public MongoContentRepository(IMongoDbContextProvider dbContextProvider) : base( + dbContextProvider) { } @@ -21,6 +23,9 @@ namespace Volo.CmsKit.MongoDB.Contents Guid? tenantId = null, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityType, nameof(entityType)); + Check.NotNullOrEmpty(entityId, nameof(entityId)); + return GetAsync(x => x.EntityType == entityType && x.EntityId == entityId && @@ -28,23 +33,30 @@ namespace Volo.CmsKit.MongoDB.Contents cancellationToken: GetCancellationToken(cancellationToken) ); } - + public virtual Task FindAsync( string entityType, string entityId, Guid? tenantId = null, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityType, nameof(entityType)); + Check.NotNullOrEmpty(entityId, nameof(entityId)); + return FindAsync(x => x.EntityType == entityType && x.EntityId == entityId && x.TenantId == tenantId, cancellationToken: GetCancellationToken(cancellationToken) - ); + ); } - public virtual Task DeleteAsync(string entityType, string entityId, Guid? tenantId = null, CancellationToken cancellationToken = default) + public virtual Task DeleteAsync(string entityType, string entityId, Guid? tenantId = null, + CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityType, nameof(entityType)); + Check.NotNullOrEmpty(entityId, nameof(entityId)); + return DeleteAsync(x => x.EntityType == entityType && x.EntityId == entityId && @@ -52,8 +64,12 @@ namespace Volo.CmsKit.MongoDB.Contents cancellationToken: GetCancellationToken(cancellationToken)); } - public virtual async Task ExistsAsync([NotNull] string entityType, [NotNull] string entityId, Guid? tenantId = null, CancellationToken cancellationToken = default) + public virtual async Task ExistsAsync([NotNull] string entityType, [NotNull] string entityId, + Guid? tenantId = null, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityType, nameof(entityType)); + Check.NotNullOrEmpty(entityId, nameof(entityId)); + return await (await GetMongoQueryableAsync(cancellationToken)).AnyAsync(x => x.EntityType == entityType && x.EntityId == entityId && diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Pages/MongoPageRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Pages/MongoPageRepository.cs index 66147d0e6d..ec520fe809 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Pages/MongoPageRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Pages/MongoPageRepository.cs @@ -1,10 +1,12 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Linq.Dynamic.Core; +using JetBrains.Annotations; +using MongoDB.Driver; +using Volo.Abp; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using MongoDB.Driver; using MongoDB.Driver.Linq; using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.MongoDB; @@ -14,14 +16,16 @@ namespace Volo.CmsKit.MongoDB.Pages { public class MongoPageRepository : MongoDbRepository, IPageRepository { - public MongoPageRepository(IMongoDbContextProvider dbContextProvider) : base(dbContextProvider) + public MongoPageRepository(IMongoDbContextProvider dbContextProvider) : base( + dbContextProvider) { } - public virtual async Task GetCountAsync(string filter = null, CancellationToken cancellationToken = default) + public virtual async Task GetCountAsync(string filter = null, + CancellationToken cancellationToken = default) { var cancellation = GetCancellationToken(cancellationToken); - + return await (await GetMongoQueryableAsync(cancellation)) .WhereIf>( !filter.IsNullOrWhiteSpace(), @@ -33,12 +37,12 @@ namespace Volo.CmsKit.MongoDB.Pages public virtual async Task> GetListAsync( string filter = null, int maxResultCount = int.MaxValue, - int skipCount = 0, + int skipCount = 0, string sorting = null, CancellationToken cancellationToken = default) { var cancellation = GetCancellationToken(cancellationToken); - + return await (await GetMongoQueryableAsync(cancellation)) .WhereIf>( !filter.IsNullOrWhiteSpace(), @@ -51,19 +55,23 @@ namespace Volo.CmsKit.MongoDB.Pages .ToListAsync(cancellation); } - public virtual Task GetBySlugAsync(string slug, CancellationToken cancellationToken = default) + public virtual Task GetBySlugAsync([NotNull]string slug, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(slug, nameof(slug)); return GetAsync(x => x.Slug == slug, cancellationToken: GetCancellationToken(cancellationToken)); } - public virtual Task FindBySlugAsync(string slug, CancellationToken cancellationToken = default) + public virtual Task FindBySlugAsync([NotNull]string slug, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(slug, nameof(slug)); return FindAsync(x => x.Slug == slug, cancellationToken: GetCancellationToken(cancellationToken)); } - - public virtual async Task ExistsAsync(string slug, CancellationToken cancellationToken = default) + + public virtual async Task ExistsAsync([NotNull]string slug, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)).AnyAsync(x => x.Slug == slug, GetCancellationToken(cancellationToken)); + Check.NotNullOrEmpty(slug, nameof(slug)); + return await (await GetMongoQueryableAsync(cancellationToken)).AnyAsync(x => x.Slug == slug, + GetCancellationToken(cancellationToken)); } } -} +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoEntityTagRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoEntityTagRepository.cs index c073f8206f..041b6af5a2 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoEntityTagRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoEntityTagRepository.cs @@ -4,23 +4,26 @@ using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using Volo.Abp; using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.MongoDB; using Volo.CmsKit.Tags; namespace Volo.CmsKit.MongoDB.Tags { - public class MongoEntityTagRepository: MongoDbRepository, IEntityTagRepository + public class MongoEntityTagRepository : MongoDbRepository, IEntityTagRepository { - public MongoEntityTagRepository(IMongoDbContextProvider dbContextProvider) : base(dbContextProvider) + public MongoEntityTagRepository(IMongoDbContextProvider dbContextProvider) : base( + dbContextProvider) { } public async Task DeleteManyAsync(Guid[] tagIds, CancellationToken cancellationToken = default) { - var collection = await GetCollectionAsync(); - - await collection.DeleteManyAsync(Builders.Filter.In(x => x.TagId, tagIds)); + var token = GetCancellationToken(cancellationToken); + + var collection = await GetCollectionAsync(token); + await collection.DeleteManyAsync(Builders.Filter.In(x => x.TagId, tagIds), token); } public Task FindAsync( @@ -29,11 +32,12 @@ namespace Volo.CmsKit.MongoDB.Tags [CanBeNull] Guid? tenantId, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityId, nameof(entityId)); return base.FindAsync(x => - x.TagId == tagId && - x.EntityId == entityId && - x.TenantId == tenantId, - cancellationToken: cancellationToken); + x.TagId == tagId && + x.EntityId == entityId && + x.TenantId == tenantId, + cancellationToken: GetCancellationToken(cancellationToken)); } } } \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoTagRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoTagRepository.cs index 02c42c22fb..5e8fdf94a7 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoTagRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoTagRepository.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using Volo.Abp; using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.MongoDB; using Volo.CmsKit.Tags; @@ -24,6 +25,9 @@ namespace Volo.CmsKit.MongoDB.Tags Guid? tenantId = null, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityType, nameof(entityType)); + Check.NotNullOrEmpty(name, nameof(name)); + return await (await GetMongoQueryableAsync(cancellationToken)) .AnyAsync(x => x.EntityType == entityType && @@ -51,6 +55,9 @@ namespace Volo.CmsKit.MongoDB.Tags Guid? tenantId = null, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityType, nameof(entityType)); + Check.NotNullOrEmpty(name, nameof(name)); + return FindAsync(x => x.EntityType == entityType && x.Name == name && @@ -64,6 +71,9 @@ namespace Volo.CmsKit.MongoDB.Tags Guid? tenantId = null, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityType, nameof(entityType)); + Check.NotNullOrEmpty(entityId, nameof(entityId)); + var entityTagIds = await (await GetDbContextAsync(cancellationToken)).EntityTags.AsQueryable() .Where(q => q.EntityId == entityId && q.TenantId == tenantId) .Select(q => q.TagId) diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Contents/ContentController.cs b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Contents/ContentController.cs index ab8270a2a1..9ba368f03d 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Contents/ContentController.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Contents/ContentController.cs @@ -1,27 +1,29 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Volo.Abp; +using Volo.Abp.GlobalFeatures; using Volo.CmsKit.Contents; +using Volo.CmsKit.GlobalFeatures; namespace Volo.CmsKit.Public.Contents { - + [RequiresGlobalFeature(typeof(ContentsFeature))] [RemoteService(Name = CmsKitCommonRemoteServiceConsts.RemoteServiceName)] [Area("cms-kit")] [Route("api/cms-kit-public/contents")] public class ContentController : CmsKitControllerBase, IContentPublicAppService { - protected readonly IContentPublicAppService _contentAppService; + protected IContentPublicAppService ContentAppService { get; } public ContentController(IContentPublicAppService contentAppService) { - _contentAppService = contentAppService; + ContentAppService = contentAppService; } [HttpGet] public virtual Task GetAsync(GetContentInput input) { - return _contentAppService.GetAsync(input); + return ContentAppService.GetAsync(input); } } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Tags/TagPublicController.cs b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Tags/TagPublicController.cs index 55041e5c6e..b1f18e2511 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Tags/TagPublicController.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Tags/TagPublicController.cs @@ -14,7 +14,7 @@ namespace Volo.CmsKit.Public.Tags [Route("api/cms-kit-public/tags")] public class TagPublicController : CmsKitPublicControllerBase, ITagAppService { - protected readonly ITagAppService TagAppService; + protected ITagAppService TagAppService { get; } public TagPublicController(ITagAppService tagAppService) {