mirror of https://github.com/abpframework/abp.git
6 changed files with 123 additions and 6 deletions
@ -0,0 +1,52 @@ |
|||||
|
using JetBrains.Annotations; |
||||
|
using System; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Domain.Services; |
||||
|
using Volo.CmsKit.Tags; |
||||
|
|
||||
|
namespace Volo.CmsKit.Tags |
||||
|
{ |
||||
|
public class EntityTagManager : DomainService, IEntityTagManager |
||||
|
{ |
||||
|
protected readonly IEntityTagRepository _entityTagRepository; |
||||
|
protected readonly ITagDefinitionStore _tagDefinitionStore; |
||||
|
|
||||
|
public EntityTagManager( |
||||
|
IEntityTagRepository entityTagRepository, |
||||
|
ITagDefinitionStore tagDefinitionStore) |
||||
|
{ |
||||
|
_entityTagRepository = entityTagRepository; |
||||
|
_tagDefinitionStore = tagDefinitionStore; |
||||
|
} |
||||
|
|
||||
|
public async Task<EntityTag> AddTagToEntityAsync( |
||||
|
[NotNull] Guid tagId, |
||||
|
[NotNull] string entityType, |
||||
|
[NotNull] string entityId, |
||||
|
[CanBeNull] Guid? tenantId = null, |
||||
|
CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
if (!await _tagDefinitionStore.IsDefinedAsync(entityType)) |
||||
|
{ |
||||
|
throw new EntityNotTaggableException(entityType); |
||||
|
} |
||||
|
|
||||
|
var entityTag = new EntityTag(tagId, entityId, tenantId); |
||||
|
|
||||
|
return await _entityTagRepository.InsertAsync(entityTag, cancellationToken: cancellationToken); |
||||
|
} |
||||
|
|
||||
|
public async Task RemoveTagFromEntityAsync( |
||||
|
[NotNull] Guid tagId, |
||||
|
[NotNull] string entityType, |
||||
|
[NotNull] string entityId, |
||||
|
[CanBeNull] Guid? tenantId = null, |
||||
|
CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
var entityTag = await _entityTagRepository.FindAsync(tagId, entityId, tenantId, cancellationToken); |
||||
|
|
||||
|
await _entityTagRepository.DeleteAsync(entityTag); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,24 @@ |
|||||
|
using JetBrains.Annotations; |
||||
|
using System; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Volo.CmsKit.Tags |
||||
|
{ |
||||
|
public interface IEntityTagManager |
||||
|
{ |
||||
|
Task<EntityTag> AddTagToEntityAsync( |
||||
|
[NotNull] Guid tagId, |
||||
|
[NotNull] string entityType, |
||||
|
[NotNull] string entityId, |
||||
|
[CanBeNull] Guid? tenantId = null, |
||||
|
CancellationToken cancellationToken = default); |
||||
|
|
||||
|
Task RemoveTagFromEntityAsync( |
||||
|
[NotNull] Guid tagId, |
||||
|
[NotNull] string entityType, |
||||
|
[NotNull] string entityId, |
||||
|
[CanBeNull] Guid? tenantId = null, |
||||
|
CancellationToken cancellationToken = default); |
||||
|
} |
||||
|
} |
||||
@ -1,9 +1,17 @@ |
|||||
using Volo.Abp.Domain.Repositories; |
using JetBrains.Annotations; |
||||
|
using System; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Domain.Repositories; |
||||
|
|
||||
namespace Volo.CmsKit.Tags |
namespace Volo.CmsKit.Tags |
||||
{ |
{ |
||||
public interface IEntityTagRepository : IBasicRepository<EntityTag> |
public interface IEntityTagRepository : IBasicRepository<EntityTag> |
||||
{ |
{ |
||||
|
Task<EntityTag> FindAsync( |
||||
|
[NotNull] Guid tagId, |
||||
|
[NotNull] string entityId, |
||||
|
[CanBeNull] Guid? tenantId, |
||||
|
CancellationToken cancellationToken = default); |
||||
} |
} |
||||
} |
} |
||||
Loading…
Reference in new issue