Browse Source

CmsKit - Move EventBus & Set logic to Domain layer

pull/7745/head
enisn 6 years ago
parent
commit
180263adb4
  1. 21
      modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Blogs/BlogFeatureAdminAppService.cs
  2. 36
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/BlogFeatureManager.cs
  3. 2
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/IBlogFeatureManager.cs

21
modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Blogs/BlogFeatureAdminAppService.cs

@ -41,26 +41,9 @@ namespace Volo.CmsKit.Admin.Blogs
}
[Authorize(CmsKitAdminPermissions.Blogs.Features)]
public async Task SetAsync(Guid blogId, BlogFeatureInputDto dto)
public Task SetAsync(Guid blogId, BlogFeatureInputDto dto)
{
var blogFeature = await BlogFeatureRepository.FindAsync(blogId, dto.FeatureName);
if (blogFeature == null)
{
var newBlogFeature = new BlogFeature(blogId, dto.FeatureName, dto.IsEnabled);
await BlogFeatureRepository.InsertAsync(newBlogFeature);
}
else
{
blogFeature.IsEnabled = dto.IsEnabled;
await BlogFeatureRepository.UpdateAsync(blogFeature);
}
await EventBus.PublishAsync(new BlogFeatureChangedEto
{
BlogId = blogId,
FeatureName = dto.FeatureName,
IsEnabled = dto.IsEnabled
});
return BlogFeatureManager.SetAsync(blogId, dto.FeatureName, dto.IsEnabled);
}
}
}

36
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/BlogFeatureManager.cs

@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Domain.Services;
using Volo.Abp.EventBus.Distributed;
using Volo.Abp.Uow;
namespace Volo.CmsKit.Blogs
{
@ -11,12 +13,20 @@ namespace Volo.CmsKit.Blogs
protected IDefaultBlogFeatureProvider DefaultBlogFeatureProvider { get; }
protected IUnitOfWorkManager UnitOfWorkManager { get; }
protected IDistributedEventBus EventBus { get; }
public BlogFeatureManager(
IBlogFeatureRepository blogFeatureRepository,
IDefaultBlogFeatureProvider defaultBlogFeatureProvider)
IDefaultBlogFeatureProvider defaultBlogFeatureProvider,
IUnitOfWorkManager unitOfWorkManager,
IDistributedEventBus eventBus)
{
BlogFeatureRepository = blogFeatureRepository;
DefaultBlogFeatureProvider = defaultBlogFeatureProvider;
UnitOfWorkManager = unitOfWorkManager;
EventBus = eventBus;
}
public async Task<List<BlogFeature>> GetListAsync(Guid blogId)
@ -29,5 +39,29 @@ namespace Volo.CmsKit.Blogs
return blogFeatures;
}
public async Task SetAsync(Guid blogId, string featureName, bool isEnabled)
{
var blogFeature = await BlogFeatureRepository.FindAsync(blogId, featureName);
if (blogFeature == null)
{
var newBlogFeature = new BlogFeature(blogId, featureName, isEnabled);
await BlogFeatureRepository.InsertAsync(newBlogFeature);
}
else
{
blogFeature.IsEnabled = isEnabled;
await BlogFeatureRepository.UpdateAsync(blogFeature);
}
await UnitOfWorkManager.Current.SaveChangesAsync();
await EventBus.PublishAsync(new BlogFeatureChangedEto
{
BlogId = blogId,
FeatureName = featureName,
IsEnabled = isEnabled
});
}
}
}

2
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/IBlogFeatureManager.cs

@ -11,5 +11,7 @@ namespace Volo.CmsKit.Blogs
public interface IBlogFeatureManager : IDomainService
{
Task<List<BlogFeature>> GetListAsync(Guid blogId);
Task SetAsync(Guid blogId, string featureName, bool isEnabled);
}
}

Loading…
Cancel
Save