Example #1
0
        public List <TagBE> InsertTags(ulong pageId, IList <TagBE> tags)
        {
            var result = new List <TagBE>();

            foreach (TagBE tag in tags)
            {
                uint tagId = _session.Tags_Insert(tag);

                // If the tag already exists, retrieve it
                if (tagId == 0)
                {
                    var matchingTag = _session.Tags_GetByNameAndType(tag.Name, tag.Type);

                    // Rename if name only differs by capitalization and/or accent marks (MySql collation ignores both)
                    if (!StringUtil.EqualsInvariant(matchingTag.Name, tag.Name))
                    {
                        matchingTag.Name = tag.Name;
                        UpdateTag(matchingTag);
                    }

                    // if the tag is a define tag, check that it's still a valid one
                    if (tag.Type == TagType.DEFINE && _session.Tags_ValidateDefineTagMapping(matchingTag))
                    {
                        // if the define tag is valid, insert this tag as text
                        tag.Type = TagType.TEXT;
                        result.AddRange(InsertTags(pageId, new[] { tag }));
                        continue;
                    }
                    tagId = matchingTag.Id;
                }
                _session.TagMapping_Insert(pageId, tagId);
                result.Add(tag);
            }
            return(result);
        }