Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 005202c6

Přidáno uživatelem Vojtěch Bartička před asi 2 roky(ů)

Users assigned on document upload

Zobrazit rozdíly:

Backend/Backend/Program.cs
114 114
    {
115 115
        //context.Database.EnsureDeleted();
116 116
        //context.Database.EnsureCreated();
117
        context.Database.Migrate();
117
        //context.Database.Migrate();
118 118
        Seeder.SeedDevelopment(context);
119 119
    }
120 120
    else
Backend/Core/Contexts/DatabaseContext.cs
31 31

  
32 32
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
33 33
        {
34
            //optionsBuilder.UseNpgsql(_configuration["ConnectionString"], b => b.MigrationsAssembly("RestAPI"));
35
            optionsBuilder.UseNpgsql("Host=localhost:5432;Database=dbo;Username=myuser;Password=password");
34
            optionsBuilder.UseNpgsql(_configuration["ConnectionString"], b => b.MigrationsAssembly("RestAPI"));
35
            //optionsBuilder.UseNpgsql("Host=localhost:5432;Database=dbo;Username=myuser;Password=password");
36 36
        }
37 37
    }
38 38
}
Backend/Core/Services/DocumentService/DocumentServiceEF.cs
41 41
        {
42 42
            User user = databaseContext.Users.Single(u => u.Id == userId);
43 43

  
44
            var users = databaseContext.Users.Select(u => u).ToList();
45

  
44 46
            foreach (var documentInfo in request.Documents)
45 47
            {
46 48
                if (documentInfo.Format == Models.Enums.EAddDocumentFormat.TEXTFILE)
47 49
                {
48 50
                    // TODO hardcoded UTF-8 - maybe do something smarter
49 51
                    var documentContent = Encoding.UTF8.GetString(Convert.FromBase64String(documentInfo.Content));
50
                    SaveDocument(documentContent, user, documentInfo.Name);
52
                    SaveDocument(documentContent, user, documentInfo.Name, users);
51 53
                }
52 54
                else if (documentInfo.Format == Models.Enums.EAddDocumentFormat.ZIP)
53 55
                {
54 56
                    var (names, contents) = UnzipDocuments(documentInfo.Content);
55 57
                    for (int i = 0; i < names.Count; i++)
56 58
                    {
57
                        SaveDocument(contents[i], user, names[i]);
59
                        SaveDocument(contents[i], user, names[i], users);
58 60
                    }
59 61
                }
60 62
            }
......
89 91
            return (names, contents);
90 92
        }
91 93

  
92
        private void SaveDocument(string content, User userAdded, string documentName)
94
        private void SaveDocument(string content, User userAdded, string documentName, List<User> users)
93 95
        {
94 96
            DocumentContent documentContent = new DocumentContent()
95 97
            {
......
103 105
                UserAdded = userAdded,
104 106
                Name = documentName,
105 107
                Length = documentContent.Content.Length,
106
                RequiredAnnotations = 3                     // TODO this is only for beta testing purposes
108
                RequiredAnnotations = 3                     // TODO this is only for testing purposes
107 109
            };
108 110

  
111
            foreach (var user in users)
112
            {
113
                Annotation annotation = new Annotation()
114
                {
115
                    User = user,
116
                    UserAssigned = userAdded,
117
                    State = Models.Enums.EState.NEW,
118
                    DateAssigned = DateTime.Now,
119
                    DateLastChanged = DateTime.Now,
120
                    Document = document,
121
                    Note = ""
122
                };
123
                databaseContext.Annotations.Add(annotation);
124
            }
125

  
109 126
            databaseContext.DocumentContents.Add(documentContent);
110 127
            databaseContext.Documents.Add(document);
111 128
            databaseContext.SaveChanges();                  // Maybe do this after all the documents are added

Také k dispozici: Unified diff