commit f260dac88132acadb16cac8f07a74751ed0e746f
Author: Vojtěch Bartička <aitakaitov@gmail.com>
Date:   Sun May 15 17:19:14 2022 +0200

    Fixed issues in AnnotationService and HTMLService

diff --git a/Backend/Core/Services/AnnotationService/AnnotationServiceEF.cs b/Backend/Core/Services/AnnotationService/AnnotationServiceEF.cs
index 64171d4..59531ca 100644
--- a/Backend/Core/Services/AnnotationService/AnnotationServiceEF.cs
+++ b/Backend/Core/Services/AnnotationService/AnnotationServiceEF.cs
@@ -224,7 +224,10 @@ namespace Core.Services.AnnotationService
                 {
                     if (annotation.ModifiedType == EModified.ADDED)
                     {
-                        var lastModifiedTag = context.AnnotationTags.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);
                         docToRender = result.Item1;
                         cachedInfoToReturn = result.Item2;
@@ -315,7 +318,8 @@ namespace Core.Services.AnnotationService
                     Length = request.Length,
                     Position = request.Position,
                     SelectedText = request.SelectedText,
-                    Note = ""
+                    Note = "",
+                    IsFinal = true
                 };
             }
             else
@@ -754,5 +758,32 @@ namespace Core.Services.AnnotationService
 
             return true;
         }
+
+        public void SetTagIsFinal(Guid annotationId, Guid occurenceId, bool isFinal)
+        {
+            Annotation annotation;
+            try
+            {
+                annotation = context.FinalAnnotations.Single(fa => fa.Id == annotationId);
+            }
+            catch (Exception)
+            {
+                throw new InvalidOperationException("Annotation not found");
+            }
+
+            FinalAnnotationTag finalTagInstance;
+            try
+            {
+                finalTagInstance = context.FinalAnnotationTags.Single(fat => fat.Id == occurenceId);
+            }
+            catch (Exception)
+            {
+                throw new InvalidOperationException("Tag instance not found");
+            }
+
+            finalTagInstance.IsFinal = isFinal;
+
+            context.SaveChanges();
+        }
     }
 }
diff --git a/Backend/Core/Services/HTMLService/HTMLService.cs b/Backend/Core/Services/HTMLService/HTMLService.cs
index 873bf77..178d2fa 100644
--- a/Backend/Core/Services/HTMLService/HTMLService.cs
+++ b/Backend/Core/Services/HTMLService/HTMLService.cs
@@ -452,7 +452,7 @@ namespace Core.Services
          *      Partial HTML Preprocessing ----------------------------------------------------------------------------
          */
 
-        public (string, CachedInfo) PartialPreprocessHTMLAddTag(string htmlToEdit, string htmlOriginal, AnnotationTag tagToAdd, List<AnnotationTagGeneric> tags, CachedInfo cachedInfo)
+        public (string, CachedInfo) PartialPreprocessHTMLAddTag(string htmlToEdit, string htmlOriginal, AnnotationTagGeneric tagToAdd, List<AnnotationTagGeneric> tags, CachedInfo cachedInfo)
         {
             UnpackCachedInfo(cachedInfo);
 
@@ -524,7 +524,7 @@ namespace Core.Services
         }
 
 
-        public (string, CachedInfo) PartialPreprocessHTMLRemoveTag(string htmlToEdit, string htmlOriginal, AnnotationTag tagToRemove, List<AnnotationTagGeneric> tags, CachedInfo cachedInfo)
+        public (string, CachedInfo) PartialPreprocessHTMLRemoveTag(string htmlToEdit, string htmlOriginal, AnnotationTagGeneric tagToRemove, List<AnnotationTagGeneric> tags, CachedInfo cachedInfo)
         {
             UnpackCachedInfo(cachedInfo);
 
diff --git a/Backend/Core/Services/HTMLService/IHTMLService.cs b/Backend/Core/Services/HTMLService/IHTMLService.cs
index 8cb7444..4c08c16 100644
--- a/Backend/Core/Services/HTMLService/IHTMLService.cs
+++ b/Backend/Core/Services/HTMLService/IHTMLService.cs
@@ -11,7 +11,7 @@ namespace Core.Services
     public interface IHTMLService
     {
         public (string, CachedInfo) FullPreprocessHTML(string htmlSource, List<AnnotationTagGeneric> tags);
-        public (string, CachedInfo) PartialPreprocessHTMLAddTag(string htmlToEdit, string htmlOriginal, AnnotationTag tagToAdd, List<AnnotationTagGeneric> tags, CachedInfo cachedInfo);
-        public (string, CachedInfo) PartialPreprocessHTMLRemoveTag(string htmlToEdit, string htmlOriginal, AnnotationTag tagToRemove, List<AnnotationTagGeneric> tags, CachedInfo cachedInfo);
+        public (string, CachedInfo) PartialPreprocessHTMLAddTag(string htmlToEdit, string htmlOriginal, AnnotationTagGeneric tagToAdd, List<AnnotationTagGeneric> tags, CachedInfo cachedInfo);
+        public (string, CachedInfo) PartialPreprocessHTMLRemoveTag(string htmlToEdit, string htmlOriginal, AnnotationTagGeneric tagToRemove, List<AnnotationTagGeneric> tags, CachedInfo cachedInfo);
     }
 }
