commit 6807d7512944aab32691ad66c4c24b51d7143ed9
Author: Vojtěch Bartička <aitakaitov@gmail.com>
Date:   Sun May 15 17:55:49 2022 +0200

    More fixes

diff --git a/Backend/Core/MapperProfiles/TagProfileEF.cs b/Backend/Core/MapperProfiles/TagProfileEF.cs
index fe651e2..fe0976e 100644
--- a/Backend/Core/MapperProfiles/TagProfileEF.cs
+++ b/Backend/Core/MapperProfiles/TagProfileEF.cs
@@ -24,7 +24,8 @@ namespace Core.MapperProfiles
                 .ForMember(fat => fat.Id, opt => opt.Ignore())
                 .ForMember(fat => fat.Annotation, opt => opt.Ignore());
 
-            CreateMap<FinalAnnotationTag, TagInstanceInfo>();
+            CreateMap<FinalAnnotationTag, TagInstanceInfo>()
+                .ForMember(ti => ti.OccurenceId, opt => opt.MapFrom(at => at.Id));
         }
     }
 }
diff --git a/Backend/Core/Services/AnnotationService/AnnotationServiceEF.cs b/Backend/Core/Services/AnnotationService/AnnotationServiceEF.cs
index 59531ca..1c0fcf7 100644
--- a/Backend/Core/Services/AnnotationService/AnnotationServiceEF.cs
+++ b/Backend/Core/Services/AnnotationService/AnnotationServiceEF.cs
@@ -165,29 +165,46 @@ namespace Core.Services.AnnotationService
 
             var documentContent = context.Documents.Where(d => d.Id == annotation.Document.Id).Select(d => d.Content).First();
 
-            IQueryable<AnnotationTagGeneric> tagsQuery;
             List<AnnotationTagGeneric> tags;
             if (!isFinal)
             {
-                tagsQuery = context.AnnotationTags.Where(at => at.Annotation.Id == annotationId);
+                tags = context.AnnotationTags
+                    .Where(at => at.Annotation.Id == annotationId)
+                    .Include(at => at.Tag)
+                    .ThenInclude(t => t.Category)
+                    .Include(at => at.SubTag)
+                    .OrderBy(at => at.Position)
+                    .Select(at => at as AnnotationTagGeneric)
+                    .ToList();
             }
             else
             {
-                tagsQuery = context.FinalAnnotationTags.Where(at => at.Annotation.Id == annotationId);
+                tags = context.FinalAnnotationTags
+                    .Where(at => at.Annotation.Id == annotationId)
+                    .Include(at => at.Users)
+                    .Include(at => at.Tag)
+                    .ThenInclude(t => t.Category)
+                    .Include(at => at.SubTag)
+                    .OrderBy(at => at.Position)
+                    .Select(at => at as AnnotationTagGeneric)
+                    .ToList();
             }
 
-            tags = tagsQuery.Include(at => at.Tag)
-                .ThenInclude(t => t.Category)
-                .Include(at => at.SubTag)
-                .OrderBy(at => at.Position)
-                .Select(at => at)
-                .ToList();
 
             List<TagInstanceInfo> tagInstanceInfos = new();
             foreach (var tag in tags)
             {
-                var tagInstance = mapper.Map<TagInstanceInfo>(tag);
-                tagInstanceInfos.Add(tagInstance);
+                if (!isFinal)
+                {
+                    var tagInstance = mapper.Map<TagInstanceInfo>(tag);
+                    tagInstanceInfos.Add(tagInstance);
+                }
+                else
+                {
+                    var tagInstance = mapper.Map<TagInstanceInfo>(tag as FinalAnnotationTag);
+                    tagInstanceInfos.Add(tagInstance);
+                }
+
             }
 
             var docToRender = "";
@@ -225,7 +242,7 @@ namespace Core.Services.AnnotationService
                     if (annotation.ModifiedType == EModified.ADDED)
                     {
 
-                        AnnotationTagGeneric lastModifiedTag = isFinal ? context.FinalAnnotationTags.Where(at => at.Id == annotation.LastModifiedTagId).First() : 
+                        AnnotationTagGeneric lastModifiedTag = isFinal ? context.FinalAnnotationTags.Where(at => at.Id == annotation.LastModifiedTagId).First() :
                             context.AnnotationTags.Where(at => at.Id == annotation.LastModifiedTagId).First();
 
                         var result = htmlService.PartialPreprocessHTMLAddTag(docToRender, documentContent.Content, lastModifiedTag, tags, cachedInfoToReturn);
