public async Task AddTagToEntityAsync_ShouldAdd_WhenEverythingCorrect() { var tag = await _tagRepository.InsertAsync(new Tag(_guidGenerator.Create(), _cmsKitTestData.EntityType1, "My Test Tag #1")); var entityTag = await _entityTagManager.AddTagToEntityAsync(tag.Id, _cmsKitTestData.EntityType1, _cmsKitTestData.EntityId1); entityTag.ShouldNotBeNull(); }
private async Task SeedTagsAsync() { var created1 = await _tagRepository.InsertAsync( await _tagManager.CreateAsync( _cmsKitTestData.TagId_1, _cmsKitTestData.EntityType1, _cmsKitTestData.TagName_1)); await _entityTagManager.AddTagToEntityAsync(created1.Id, created1.EntityType, _cmsKitTestData.EntityId1); var created2 = await _tagRepository.InsertAsync( await _tagManager.CreateAsync( _cmsKitTestData.TagId_2, _cmsKitTestData.EntityType2, _cmsKitTestData.TagName_2)); await _entityTagManager.AddTagToEntityAsync(created2.Id, created2.EntityType, _cmsKitTestData.EntityId2); foreach (var tag in _cmsKitTestData.Content_1_Tags) { var tagEntity = await _tagRepository.InsertAsync( await _tagManager.CreateAsync( _guidGenerator.Create(), _cmsKitTestData.Content_1_EntityType, tag)); await _entityTagManager.AddTagToEntityAsync(tagEntity.Id, _cmsKitTestData.Content_1_EntityType, _cmsKitTestData.Content_1_EntityId); } foreach (var tag in _cmsKitTestData.Content_2_Tags) { var tagEntity = await _tagRepository.InsertAsync( await _tagManager.CreateAsync( _guidGenerator.Create(), _cmsKitTestData.Content_2_EntityType, tag)); await _entityTagManager.AddTagToEntityAsync(tagEntity.Id, _cmsKitTestData.Content_2_EntityType, _cmsKitTestData.Content_2_EntityId); } }
public virtual async Task AddTagToEntityAsync(EntityTagCreateDto input) { var definition = await TagDefinitionStore.GetTagEntityTypeDefinitionAsync(input.EntityType); await CheckPolicyAsync(definition.CreatePolicy); var tag = await TagManager.GetOrAddAsync(input.EntityType, input.TagName); await EntityTagManager.AddTagToEntityAsync( tag.Id, input.EntityType, input.EntityId, CurrentTenant?.Id); }
public virtual async Task SetEntityTagsAsync(EntityTagSetDto input) { var definition = await TagDefinitionStore.GetTagEntityTypeDefinitionsAsync(input.EntityType); await CheckPolicyAsync(definition.UpdatePolicy); var existingTags = await TagRepository.GetAllRelatedTagsAsync(input.EntityType, input.EntityId, CurrentTenant?.Id); var deletedTags = existingTags.Where(x => !input.Tags.Contains(x.Name)).ToList(); var addedTags = input.Tags.Where(x => !existingTags.Any(a => a.Name == x)); await EntityTagRepository.DeleteManyAsync(deletedTags.Select(s => s.Id).ToArray()); foreach (var addedTag in addedTags) { var tag = await TagManager.GetOrAddAsync(input.EntityType, addedTag, CurrentTenant?.Id); await EntityTagManager.AddTagToEntityAsync(tag.Id, input.EntityType, input.EntityId, CurrentTenant?.Id); } }