public void AssignTag(AssignTagDto input) { IDictionary <string, object> paramDict = GenerateParamDict(input); IList <MetaEntity> metaEntities = metaEntityManager.ExtractEntity(input.Type, input.Sql, paramDict); MetaEntitySyncResult targetResult = metaEntityManager.SyncEntityToTarget(metaEntities); Tag tagResult = tagRepository.FirstOrDefault(t => t.Id == input.TagId); tagTargetManager.AssignTag(targetResult.Targets, tagResult); }
private static IDictionary <string, object> GenerateParamDict(AssignTagDto input) { IDictionary <string, object> paramDict = new Dictionary <string, object>(); if (input.Param != null) { var jsonParams = JsonConvert.DeserializeObject(input.Param.ToString()) as JObject; foreach (var jsonParam in jsonParams) { paramDict[jsonParam.Key] = jsonParam.Value.ToString(); } } return(paramDict); }
public async Task AssignTag_Tests() { string Sql1 = @"SELECT Id, Name FROM Product"; IList <MetaEntity> metaEntities1 = metaEntityManager.ExtractEntity(MetaEntityType.Product, Sql1); MetaEntitySyncResult result1 = metaEntityManager.SyncEntityToTarget(metaEntities1); string Sql2 = @"SELECT Id, Name FROM Product WHERE VisibleIndividually = @param"; IList <MetaEntity> metaEntities2 = metaEntityManager.ExtractEntity(MetaEntityType.Product, Sql2, new { param = 0 }); MetaEntitySyncResult result2 = metaEntityManager.SyncEntityToTarget(metaEntities2); // Root 1 CreateTagDto createRoot1TagDto = new CreateTagDto { Name = "Root1" }; var root1TagDto = await tagAppService.Create(createRoot1TagDto); // Sub 11 CreateTagDto createSub11TagDto = new CreateTagDto { Name = "Sub11", ParentId = root1TagDto.Id }; var sub11TagDto = await tagAppService.Create(createSub11TagDto); // Leaf 111 CreateTagDto createLeaf111TagDto = new CreateTagDto { Name = "Leaf111", ParentId = sub11TagDto.Id }; var leaf111TagDto = await tagAppService.Create(createLeaf111TagDto); AssignTagDto assignTagDto = new AssignTagDto() { Type = MetaEntityType.Product, Sql = @"SELECT Id, Name FROM Product WHERE VisibleIndividually = @param", Param = "{ \"param\": 0 }", TagId = leaf111TagDto.Id }; tagTargetAppService.AssignTag(assignTagDto); IList <TagTarget> tagTargets = tagTargetRepository.GetAllList(); tagTargets.Count.ShouldBe(2); tagTargets[0].TagId.ShouldBe(3); tagTargets[0].TargetId.ShouldBe(14); tagTargets[1].TagId.ShouldBe(3); tagTargets[1].TargetId.ShouldBe(15); }