Ejemplo n.º 1
0
        public static void EnsureTag(Tag[] allTags, ITaggable taggable, Tag tag)
        {
            // we change taggable (e.g. Link) but do not call dbContext.Update as this is done
              // by caller. this way we can prevent Modified-property on taggable being updated,
              // just because TagString changed (e.g. when tag hierarchy has changed). if we add
              // a tag to a taggable, dbContext.Update should be called by caller, as he is actually
              // changing the taggable.

              string currentTagString = taggable.TagString ?? string.Empty;
              bool hasTags = !string.IsNullOrEmpty(currentTagString);

              string tagPath = GetTagPath(allTags, tag);

              if (hasTags && currentTagString.Contains(tagPath))
              {
            return;
              }

              taggable.TagString = hasTags
                             ? string.Concat(currentTagString, Separator, tagPath)
                             : tagPath;
        }
Ejemplo n.º 2
0
        private static string GetTagPath(Tag[] allTags, Tag tag)
        {
            Tag current = tag;

              var tagIds = new List<int>();
              while (current != null)
              {
            tagIds.Add(current.Id);
            current = allTags.SingleOrDefault(t => t.Id == current.ParentId);
              }

              tagIds.Reverse();

              return string.Concat(PathStarter, JoinTagPathElements(tagIds.ToArray()), PathEnder);
        }
Ejemplo n.º 3
0
 public static void EnsureTag(IDbContext dbContext, ITaggable taggable, Tag tag)
 {
     EnsureTag(dbContext.Tags.ToArray(), taggable, tag);
 }
Ejemplo n.º 4
0
        public static void SyncTagStringWithTagIds(IDbContext dbContext, Tag[] allTags, Link link)
        {
            link.ClearTagString();

              foreach (Tag tag in link.TagIds
                              .Select(tagId => allTags.FirstOrDefault(t => t.Id == tagId))
                              .Where(t => t != null))
              {
            EnsureTag(allTags, link, tag);
              }
        }