Browse Source

add check and fix cancellation token usages.

pull/7806/head
Ilkay Ilknur 6 years ago
parent
commit
b55d0865fe
  1. 45
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Blogs/EfCoreBlogPostRepository.cs
  2. 9
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Blogs/EfCoreBlogRepository.cs
  3. 13
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs
  4. 12
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Pages/EfCorePageRepository.cs
  5. 5
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreEntityTagRepository.cs
  6. 13
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreTagRepository.cs
  7. 51
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogPostRepository.cs
  8. 5
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogRepository.cs
  9. 26
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs
  10. 34
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Pages/MongoPageRepository.cs
  11. 22
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoEntityTagRepository.cs
  12. 10
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoTagRepository.cs
  13. 10
      modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Contents/ContentController.cs
  14. 2
      modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Tags/TagPublicController.cs

45
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<BlogPost> GetBySlugAsync(Guid blogId, string slug, CancellationToken cancellationToken = default)
public async Task<BlogPost> 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<int> 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<List<BlogPost>> GetPagedListAsync(Guid blogId, int skipCount, int maxResultCount, string sorting, bool includeDetails = false, CancellationToken cancellationToken = default)
public async Task<List<BlogPost>> 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<bool> SlugExistsAsync(Guid blogId, string slug, CancellationToken cancellationToken = default)
public async Task<bool> 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));
}
}
}
}

9
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<bool> 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<Blog> GetBySlugAsync(string slug, CancellationToken cancellationToken = default)
public virtual Task<Blog> 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));
}
}
}

13
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 &&

12
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<Page> GetBySlugAsync(string slug, CancellationToken cancellationToken = default)
public virtual Task<Page> GetBySlugAsync([NotNull] string slug, CancellationToken cancellationToken = default)
{
Check.NotNullOrEmpty(slug, nameof(slug));
return GetAsync(x => x.Slug == slug, cancellationToken: GetCancellationToken(cancellationToken));
}
public virtual Task<Page> FindBySlugAsync(string slug, CancellationToken cancellationToken = default)
public virtual Task<Page> 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<bool> ExistsAsync(string slug, CancellationToken cancellationToken = default)
public virtual async Task<bool> ExistsAsync([NotNull] string slug,
CancellationToken cancellationToken = default)
{
Check.NotNullOrEmpty(slug, nameof(slug));
return await (await GetDbSetAsync()).AnyAsync(x => x.Slug == slug, GetCancellationToken(cancellationToken));
}
}

5
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));
}
}
}

13
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<EntityTag>()
.Where(q => q.EntityId == entityId && q.TenantId == tenantId)
.Select(q => q.TagId)

51
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<CmsKitMongoDbContext, BlogPost, Guid>, IBlogPostRepository
{
public MongoBlogPostRepository(IMongoDbContextProvider<CmsKitMongoDbContext> dbContextProvider) : base(dbContextProvider)
public MongoBlogPostRepository(IMongoDbContextProvider<CmsKitMongoDbContext> dbContextProvider) : base(
dbContextProvider)
{
}
public Task<BlogPost> GetBySlugAsync(Guid blogId, string slug, CancellationToken cancellationToken = default)
public Task<BlogPost> 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<int> 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<List<BlogPost>> GetPagedListAsync(Guid blogId, int skipCount, int maxResultCount, string sorting, bool includeDetails = false, CancellationToken cancellationToken = default)
public async Task<List<BlogPost>> 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<bool> SlugExistsAsync(Guid blogId, string slug, CancellationToken cancellationToken = default)
public async Task<bool> 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);
}
}
}
}

5
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<Blog> GetBySlugAsync(string slug, CancellationToken cancellationToken = default)
public virtual Task<Blog> GetBySlugAsync([NotNull]string slug, CancellationToken cancellationToken = default)
{
Check.NotNullOrEmpty(slug, nameof(slug));
return GetAsync(x => x.Slug == slug, cancellationToken: cancellationToken);
}
}

26
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<ICmsKitMongoDbContext, Content, Guid>, IContentRepository
{
public MongoContentRepository(IMongoDbContextProvider<ICmsKitMongoDbContext> dbContextProvider) : base(dbContextProvider)
public MongoContentRepository(IMongoDbContextProvider<ICmsKitMongoDbContext> 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<Content> 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<bool> ExistsAsync([NotNull] string entityType, [NotNull] string entityId, Guid? tenantId = null, CancellationToken cancellationToken = default)
public virtual async Task<bool> 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 &&

34
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<ICmsKitMongoDbContext, Page, Guid>, IPageRepository
{
public MongoPageRepository(IMongoDbContextProvider<ICmsKitMongoDbContext> dbContextProvider) : base(dbContextProvider)
public MongoPageRepository(IMongoDbContextProvider<ICmsKitMongoDbContext> dbContextProvider) : base(
dbContextProvider)
{
}
public virtual async Task<int> GetCountAsync(string filter = null, CancellationToken cancellationToken = default)
public virtual async Task<int> GetCountAsync(string filter = null,
CancellationToken cancellationToken = default)
{
var cancellation = GetCancellationToken(cancellationToken);
return await (await GetMongoQueryableAsync(cancellation))
.WhereIf<Page, IMongoQueryable<Page>>(
!filter.IsNullOrWhiteSpace(),
@ -33,12 +37,12 @@ namespace Volo.CmsKit.MongoDB.Pages
public virtual async Task<List<Page>> 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<Page, IMongoQueryable<Page>>(
!filter.IsNullOrWhiteSpace(),
@ -51,19 +55,23 @@ namespace Volo.CmsKit.MongoDB.Pages
.ToListAsync(cancellation);
}
public virtual Task<Page> GetBySlugAsync(string slug, CancellationToken cancellationToken = default)
public virtual Task<Page> GetBySlugAsync([NotNull]string slug, CancellationToken cancellationToken = default)
{
Check.NotNullOrEmpty(slug, nameof(slug));
return GetAsync(x => x.Slug == slug, cancellationToken: GetCancellationToken(cancellationToken));
}
public virtual Task<Page> FindBySlugAsync(string slug, CancellationToken cancellationToken = default)
public virtual Task<Page> 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<bool> ExistsAsync(string slug, CancellationToken cancellationToken = default)
public virtual async Task<bool> 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));
}
}
}
}

22
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<ICmsKitMongoDbContext, EntityTag>, IEntityTagRepository
public class MongoEntityTagRepository : MongoDbRepository<ICmsKitMongoDbContext, EntityTag>, IEntityTagRepository
{
public MongoEntityTagRepository(IMongoDbContextProvider<ICmsKitMongoDbContext> dbContextProvider) : base(dbContextProvider)
public MongoEntityTagRepository(IMongoDbContextProvider<ICmsKitMongoDbContext> dbContextProvider) : base(
dbContextProvider)
{
}
public async Task DeleteManyAsync(Guid[] tagIds, CancellationToken cancellationToken = default)
{
var collection = await GetCollectionAsync();
await collection.DeleteManyAsync(Builders<EntityTag>.Filter.In(x => x.TagId, tagIds));
var token = GetCancellationToken(cancellationToken);
var collection = await GetCollectionAsync(token);
await collection.DeleteManyAsync(Builders<EntityTag>.Filter.In(x => x.TagId, tagIds), token);
}
public Task<EntityTag> 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));
}
}
}

10
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)

10
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<ContentDto> GetAsync(GetContentInput input)
{
return _contentAppService.GetAsync(input);
return ContentAppService.GetAsync(input);
}
}
}

2
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)
{

Loading…
Cancel
Save