commit 005202c61398d067956affeafcc8c44818501f9b
Author: Vojtěch Bartička <aitakaitov@gmail.com>
Date:   Wed Apr 20 13:53:06 2022 +0200

    Users assigned on document upload

diff --git a/Backend/Backend/Program.cs b/Backend/Backend/Program.cs
index b186906..7a12272 100644
--- a/Backend/Backend/Program.cs
+++ b/Backend/Backend/Program.cs
@@ -114,7 +114,7 @@ using (var scope = app.Services.CreateScope())
     {
         //context.Database.EnsureDeleted();
         //context.Database.EnsureCreated();
-        context.Database.Migrate();
+        //context.Database.Migrate();
         Seeder.SeedDevelopment(context);
     }
     else
diff --git a/Backend/Core/Contexts/DatabaseContext.cs b/Backend/Core/Contexts/DatabaseContext.cs
index 43a87c5..ff34af6 100644
--- a/Backend/Core/Contexts/DatabaseContext.cs
+++ b/Backend/Core/Contexts/DatabaseContext.cs
@@ -31,8 +31,8 @@ namespace Core.Contexts
 
         protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
         {
-            //optionsBuilder.UseNpgsql(_configuration["ConnectionString"], b => b.MigrationsAssembly("RestAPI"));
-            optionsBuilder.UseNpgsql("Host=localhost:5432;Database=dbo;Username=myuser;Password=password");
+            optionsBuilder.UseNpgsql(_configuration["ConnectionString"], b => b.MigrationsAssembly("RestAPI"));
+            //optionsBuilder.UseNpgsql("Host=localhost:5432;Database=dbo;Username=myuser;Password=password");
         }
     }
 }
diff --git a/Backend/Core/Services/DocumentService/DocumentServiceEF.cs b/Backend/Core/Services/DocumentService/DocumentServiceEF.cs
index b148923..af5862c 100644
--- a/Backend/Core/Services/DocumentService/DocumentServiceEF.cs
+++ b/Backend/Core/Services/DocumentService/DocumentServiceEF.cs
@@ -41,20 +41,22 @@ namespace Core.Services.DocumentService
         {
             User user = databaseContext.Users.Single(u => u.Id == userId);
 
+            var users = databaseContext.Users.Select(u => u).ToList();
+
             foreach (var documentInfo in request.Documents)
             {
                 if (documentInfo.Format == Models.Enums.EAddDocumentFormat.TEXTFILE)
                 {
                     // TODO hardcoded UTF-8 - maybe do something smarter
                     var documentContent = Encoding.UTF8.GetString(Convert.FromBase64String(documentInfo.Content));
-                    SaveDocument(documentContent, user, documentInfo.Name);
+                    SaveDocument(documentContent, user, documentInfo.Name, users);
                 }
                 else if (documentInfo.Format == Models.Enums.EAddDocumentFormat.ZIP)
                 {
                     var (names, contents) = UnzipDocuments(documentInfo.Content);
                     for (int i = 0; i < names.Count; i++)
                     {
-                        SaveDocument(contents[i], user, names[i]);
+                        SaveDocument(contents[i], user, names[i], users);
                     }
                 }
             }
@@ -89,7 +91,7 @@ namespace Core.Services.DocumentService
             return (names, contents);
         }
 
-        private void SaveDocument(string content, User userAdded, string documentName)
+        private void SaveDocument(string content, User userAdded, string documentName, List<User> users)
         {
             DocumentContent documentContent = new DocumentContent()
             {
@@ -103,9 +105,24 @@ namespace Core.Services.DocumentService
                 UserAdded = userAdded,
                 Name = documentName,
                 Length = documentContent.Content.Length,
-                RequiredAnnotations = 3                     // TODO this is only for beta testing purposes
+                RequiredAnnotations = 3                     // TODO this is only for testing purposes
             };
 
+            foreach (var user in users)
+            {
+                Annotation annotation = new Annotation()
+                {
+                    User = user,
+                    UserAssigned = userAdded,
+                    State = Models.Enums.EState.NEW,
+                    DateAssigned = DateTime.Now,
+                    DateLastChanged = DateTime.Now,
+                    Document = document,
+                    Note = ""
+                };
+                databaseContext.Annotations.Add(annotation);
+            }
+
             databaseContext.DocumentContents.Add(documentContent);
             databaseContext.Documents.Add(document);
             databaseContext.SaveChanges();                  // Maybe do this after all the documents are added
