From 0ae018311acdbddd1dacc25ea5dff09886a1c7c8 Mon Sep 17 00:00:00 2001 From: enisn Date: Wed, 24 Feb 2021 16:39:05 +0300 Subject: [PATCH] CmsKit - Refactor CancellationToken usage --- .../Admin/Tags/EntityTagAdminAppService.cs | 4 +-- .../CmsKit/Admin/Tags/TagAdminAppService.cs | 3 +- .../Volo/CmsKit/Tags/TagManager.cs | 34 ++++++++++--------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Tags/EntityTagAdminAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Tags/EntityTagAdminAppService.cs index 6d51964487..4439cf2470 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Tags/EntityTagAdminAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Tags/EntityTagAdminAppService.cs @@ -33,7 +33,7 @@ namespace Volo.CmsKit.Admin.Tags await CheckPolicyAsync(definition.CreatePolicy); - var tag = await TagManager.GetOrAddAsync(input.EntityType, input.TagName, CurrentTenant?.Id); + var tag = await TagManager.GetOrAddAsync(input.EntityType, input.TagName); await EntityTagManager.AddTagToEntityAsync( tag.Id, @@ -71,7 +71,7 @@ namespace Volo.CmsKit.Admin.Tags foreach (var addedTag in addedTags) { - var tag = await TagManager.GetOrAddAsync(input.EntityType, addedTag, CurrentTenant?.Id); + var tag = await TagManager.GetOrAddAsync(input.EntityType, addedTag); await EntityTagManager.AddTagToEntityAsync(tag.Id, input.EntityType, input.EntityId, CurrentTenant?.Id); } diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Tags/TagAdminAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Tags/TagAdminAppService.cs index ed6d416cfa..b128ab182c 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Tags/TagAdminAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Tags/TagAdminAppService.cs @@ -47,8 +47,7 @@ namespace Volo.CmsKit.Admin.Tags var tag = await TagManager.InsertAsync( GuidGenerator.Create(), input.EntityType, - input.Name, - CurrentTenant?.Id); + input.Name); return await MapToGetOutputDtoAsync(tag); } diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/TagManager.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/TagManager.cs index a06d6d561f..0aabd2fba1 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/TagManager.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/TagManager.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using Volo.Abp; using Volo.Abp.Domain.Services; namespace Volo.CmsKit.Tags @@ -18,54 +19,55 @@ namespace Volo.CmsKit.Tags TagDefinitionStore = tagDefinitionStore; } - public virtual async Task GetOrAddAsync([NotNull] string entityType, [NotNull] string name, - Guid? tenantId = null, CancellationToken cancellationToken = default) + public virtual async Task GetOrAddAsync([NotNull] string entityType, [NotNull] string name) { - var entity = await TagRepository.FindAsync(entityType, name, tenantId, cancellationToken); + var entity = await TagRepository.FindAsync(entityType, name, CurrentTenant.Id); if (entity == null) { - entity = await InsertAsync(GuidGenerator.Create(), entityType, name, tenantId, cancellationToken); + entity = await InsertAsync(GuidGenerator.Create(), entityType, name); } return entity; } - public virtual async Task InsertAsync(Guid id, [NotNull] string entityType, [NotNull] string name, - Guid? tenantId = null, CancellationToken cancellationToken = default) + public virtual async Task InsertAsync(Guid id, + [NotNull] string entityType, + [NotNull] string name) { if (!await TagDefinitionStore.IsDefinedAsync(entityType)) { throw new EntityNotTaggableException(entityType); } - if (await TagRepository.AnyAsync(entityType, name, tenantId, cancellationToken)) + if (await TagRepository.AnyAsync(entityType, name, CurrentTenant.Id)) { throw new TagAlreadyExistException(entityType, name); } - return await TagRepository.InsertAsync(new Tag(id, entityType, name, tenantId), - cancellationToken: cancellationToken); + return await TagRepository.InsertAsync( + new Tag(id, entityType, name, CurrentTenant.Id)); } - public virtual async Task UpdateAsync(Guid id, [NotNull] string name, - CancellationToken cancellationToken = default) + public virtual async Task UpdateAsync(Guid id, + [NotNull] string name) { - var entity = await TagRepository.GetAsync(id, cancellationToken: cancellationToken); + Check.NotNullOrEmpty(name, nameof(name)); + + var entity = await TagRepository.GetAsync(id); if (name != entity.Name && - await TagRepository.AnyAsync(entity.EntityType, name, entity.TenantId, cancellationToken)) + await TagRepository.AnyAsync(entity.EntityType, name, entity.TenantId)) { throw new TagAlreadyExistException(entity.EntityType, name); } entity.SetName(name); - return await TagRepository.UpdateAsync(entity, cancellationToken: cancellationToken); + return await TagRepository.UpdateAsync(entity); } - public virtual Task> GetTagDefinitionsAsync( - CancellationToken cancellationToken = default) + public virtual Task> GetTagDefinitionsAsync() { return TagDefinitionStore.GetTagEntityTypeDefinitionListAsync(); }