diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/Blog.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/Blog.cs index 79c496970c..832ed4385e 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/Blog.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/Blog.cs @@ -20,18 +20,20 @@ namespace Volo.CmsKit.Blogs TenantId = tenantId; } - public string Name { get; protected set; } + [NotNull] + public virtual string Name { get; protected set; } - public string Slug { get; protected set; } + [NotNull] + public virtual string Slug { get; protected set; } - public Guid? TenantId { get; protected set; } + public virtual Guid? TenantId { get; protected set; } - public void SetName(string name) + public virtual void SetName(string name) { Name = Check.NotNullOrWhiteSpace(name, nameof(name), maxLength: BlogConsts.MaxNameLength); } - public void SetSlug(string slug) + public virtual void SetSlug(string slug) { Check.NotNullOrWhiteSpace(slug, nameof(slug), maxLength: BlogConsts.MaxNameLength); diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/BlogPost.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/BlogPost.cs index 7a52fe0d9f..bd7cf61516 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/BlogPost.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/BlogPost.cs @@ -12,15 +12,18 @@ namespace Volo.CmsKit.Blogs { public class BlogPost : FullAuditedAggregateRootWithUser, IMultiTenant { - public Guid BlogId { get; protected set; } + public virtual Guid BlogId { get; protected set; } - public string Title { get; protected set; } + [NotNull] + public virtual string Title { get; protected set; } - public string Slug { get; protected set; } + [NotNull] + public virtual string Slug { get; protected set; } - public string ShortDescription { get; protected set; } + [NotNull] + public virtual string ShortDescription { get; protected set; } - public Guid? TenantId { get; protected set; } + public virtual Guid? TenantId { get; protected set; } protected BlogPost() { @@ -39,7 +42,7 @@ namespace Volo.CmsKit.Blogs ShortDescription = shortDescription; } - public void SetTitle(string title) + public virtual void SetTitle(string title) { Title = Check.NotNullOrWhiteSpace(title, nameof(title), BlogPostConsts.MaxTitleLength); } @@ -51,7 +54,7 @@ namespace Volo.CmsKit.Blogs Slug = slug.NormalizeSlug(); } - public void SetShortDescription(string shortDescription) + public virtual void SetShortDescription(string shortDescription) { ShortDescription = Check.Length(shortDescription, nameof(shortDescription), BlogPostConsts.MaxShortDescriptionLength); } diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/BlogPostManager.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/BlogPostManager.cs index aed2b9fffd..2754794b26 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/BlogPostManager.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/BlogPostManager.cs @@ -1,44 +1,49 @@ -using System; +using JetBrains.Annotations; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Volo.Abp; using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Services; +using Volo.Abp.VirtualFileSystem; namespace Volo.CmsKit.Blogs { public class BlogPostManager : DomainService, IBlogPostManager { - protected readonly IBlogPostRepository blogPostRepository; - protected readonly IBlogRepository blogRepository; + protected IBlogPostRepository BlogPostRepository { get; } + protected IBlogRepository BlogRepository { get; } public BlogPostManager( IBlogPostRepository blogPostRepository, IBlogRepository blogRepository) { - this.blogPostRepository = blogPostRepository; - this.blogRepository = blogRepository; + this.BlogPostRepository = blogPostRepository; + this.BlogRepository = blogRepository; } - public async Task CreateAsync(BlogPost blogPost) + public virtual async Task CreateAsync(BlogPost blogPost) { await CheckBlogExistenceAsync(blogPost.BlogId); await CheckSlugExistenceAsync(blogPost.BlogId, blogPost.Slug); - return await blogPostRepository.InsertAsync(blogPost); + return await BlogPostRepository.InsertAsync(blogPost); } - public async Task UpdateAsync(BlogPost blogPost) + public virtual async Task UpdateAsync(BlogPost blogPost) { await CheckBlogExistenceAsync(blogPost.BlogId); - await blogPostRepository.UpdateAsync(blogPost); + await BlogPostRepository.UpdateAsync(blogPost); } - public async Task SetSlugUrlAsync(BlogPost blogPost, string newSlug) + public virtual async Task SetSlugUrlAsync(BlogPost blogPost, [NotNull] string newSlug) { + Check.NotNullOrWhiteSpace(newSlug, nameof(newSlug)); + await CheckSlugExistenceAsync(blogPost.BlogId, newSlug); blogPost.SetSlug(newSlug); @@ -46,7 +51,7 @@ namespace Volo.CmsKit.Blogs private async Task CheckSlugExistenceAsync(Guid blogId, string slug) { - if (await blogPostRepository.SlugExistsAsync(blogId, slug)) + if (await BlogPostRepository.SlugExistsAsync(blogId, slug)) { throw new BlogPostSlugAlreadyExistException(blogId, slug); } @@ -54,7 +59,7 @@ namespace Volo.CmsKit.Blogs private async Task CheckBlogExistenceAsync(Guid blogId) { - if (!await blogRepository.ExistsAsync(blogId)) + if (!await BlogRepository.ExistsAsync(blogId)) throw new EntityNotFoundException(typeof(Blog), blogId); } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/BlogPostSlugAlreadyExistException.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/BlogPostSlugAlreadyExistException.cs index 8e59249299..034cb8e60d 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/BlogPostSlugAlreadyExistException.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/BlogPostSlugAlreadyExistException.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.Serialization; using Volo.Abp; namespace Volo.CmsKit.Blogs @@ -9,7 +10,7 @@ namespace Volo.CmsKit.Blogs { } - internal BlogPostSlugAlreadyExistException(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext context) : base(serializationInfo, context) + internal BlogPostSlugAlreadyExistException(SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext context) : base(serializationInfo, context) { } @@ -24,8 +25,8 @@ namespace Volo.CmsKit.Blogs WithData(nameof(BlogId), BlogId); } - public string Slug { get; } + public virtual string Slug { get; } - public Guid BlogId { get; } + public virtual Guid BlogId { get; } } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/IBlogPostManager.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/IBlogPostManager.cs index 5027fa8e38..334b4912ef 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/IBlogPostManager.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/IBlogPostManager.cs @@ -1,4 +1,5 @@ -using System; +using JetBrains.Annotations; +using System; using System.Threading.Tasks; namespace Volo.CmsKit.Blogs @@ -9,6 +10,6 @@ namespace Volo.CmsKit.Blogs Task UpdateAsync(BlogPost blogPost); - Task SetSlugUrlAsync(BlogPost blogPost, string newSlug); + Task SetSlugUrlAsync(BlogPost blogPost, [NotNull] string newSlug); } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/IBlogRepository.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/IBlogRepository.cs index 4213884057..2feb057111 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/IBlogRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/IBlogRepository.cs @@ -1,4 +1,5 @@ using System; +using System.Threading; using System.Threading.Tasks; using Volo.Abp.Domain.Repositories; @@ -6,7 +7,7 @@ namespace Volo.CmsKit.Blogs { public interface IBlogRepository : IBasicRepository { - public Task GetBySlugAsync(string slug); - Task ExistsAsync(Guid blogId); + public Task GetBySlugAsync(string slug, CancellationToken cancellationToken = default); + Task ExistsAsync(Guid blogId, CancellationToken cancellationToken = default); } } 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 d2ddbf35aa..f04889299c 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 @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore; using System; using System.Security.Cryptography.X509Certificates; +using System.Threading; using System.Threading.Tasks; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; @@ -14,14 +15,14 @@ namespace Volo.CmsKit.Blogs { } - public async Task ExistsAsync(Guid blogId) + public virtual async Task ExistsAsync(Guid blogId, CancellationToken cancellationToken = default) { - return await (await GetQueryableAsync()).AnyAsync(x => x.Id == blogId); + return await (await GetQueryableAsync()).AnyAsync(x => x.Id == blogId, cancellationToken); } - public Task GetBySlugAsync(string slug) + public virtual Task GetBySlugAsync(string slug, CancellationToken cancellationToken = default) { - return GetAsync(x => x.Slug == slug); + return GetAsync(x => x.Slug == slug, cancellationToken: cancellationToken); } } } 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 d733f82bf6..d917842c59 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 @@ -1,5 +1,6 @@ using MongoDB.Driver.Core.Operations; using System; +using System.Threading; using System.Threading.Tasks; using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.MongoDB; @@ -13,14 +14,14 @@ namespace Volo.CmsKit.MongoDB.Blogs { } - public async Task ExistsAsync(Guid blogId) + public virtual async Task ExistsAsync(Guid blogId, CancellationToken cancellationToken = default) { return await AsyncExecuter.AnyAsync( await GetQueryableAsync(), x => x.Id == blogId); } - public Task GetBySlugAsync(string slug) + public virtual Task GetBySlugAsync(string slug, CancellationToken cancellationToken = default) { return GetAsync(x => x.Slug == slug); }