コード例 #1
0
        public async Task <RuleBO> CopyToAsync(Guid ruleId, Guid containerId)
        {
            RuleBO result     = new RuleBO();
            RuleBO ruleToCopy = MapEntityToModel(await _ruleQueries.GetAsync(ruleId));

            string ruleName = ruleToCopy.Name;

            ruleToCopy.ContainerId = containerId;

            var rulesFromContainer = await _ruleQueries.GetByContainerIdAsync(containerId);

            if (rulesFromContainer != null && rulesFromContainer.Count > 0)
            {
                while (true)
                {
                    var existRuleWithName = rulesFromContainer.FirstOrDefault(rec => rec.Name == ruleName);
                    if (existRuleWithName == null)
                    {
                        break;
                    }
                    ruleName += " - Copy";
                }
            }

            ruleToCopy.Id   = Guid.Empty;
            ruleToCopy.Name = ruleName;
            result          = MapEntityToModel(await _ruleCommands.AddAsync(MapModelToEntity(ruleToCopy)));

            var listTags = await _tagQueries.GetByRuleIdAsync(ruleId);

            if (listTags != null && listTags.Count > 0)
            {
                foreach (var tag in listTags)
                {
                    await _tagCommands.AddTagToEntityAsync(new TagEntity
                    {
                        RuleId = result.Id,
                        TagId  = tag.Id
                    });
                }
            }

            result.Tags = _tagQueries.GetByRuleIdAsync(result.Id).Result.Select(rec => new TagBO(rec)).ToList();
            return(result);
        }
コード例 #2
0
        public async Task <List <TagBO> > GetByRuleIdAsync(Guid ruleId)
        {
            var result = await _TagQueries.GetByRuleIdAsync(ruleId);

            if (result != null)
            {
                var listTags = result
                               .Select(rec => MapEntityToModel(rec))
                               .ToList();

                await DetermineIfTagIsUsed(listTags);

                listTags = listTags.OrderBy(rec => rec.Name).ToList();
                return(listTags);
            }
            return(null);
        }