Revize ceb95b98
Přidáno uživatelem Vojtěch Bartička před asi 2 roky(ů)
Backend/Core/Services/DocumentService/DocumentServiceEF.cs | ||
---|---|---|
12 | 12 |
using AutoMapper; |
13 | 13 |
using Models.Users; |
14 | 14 |
using Ganss.XSS; |
15 |
using Core.StaticConfig; |
|
16 | 15 |
|
17 | 16 |
namespace Core.Services.DocumentService |
18 | 17 |
{ |
... | ... | |
41 | 40 |
public void AddDocuments(DocumentAddRequest request, Guid userId) |
42 | 41 |
{ |
43 | 42 |
User user = databaseContext.Users.Single(u => u.Id == userId); |
44 |
|
|
45 |
var users = databaseContext.Users.Select(u => u).ToList(); |
|
43 |
int requiredAnnotations = int.Parse(databaseContext.ConfigurationItems.Single(ci => ci.Key == Constants.Constants.RequiredAnnotationsKey).Value); |
|
46 | 44 |
|
47 | 45 |
foreach (var documentInfo in request.Documents) |
48 | 46 |
{ |
... | ... | |
50 | 48 |
{ |
51 | 49 |
// TODO hardcoded UTF-8 - maybe do something smarter |
52 | 50 |
var documentContent = Encoding.UTF8.GetString(Convert.FromBase64String(documentInfo.Content)); |
53 |
SaveDocument(documentContent, user, documentInfo.Name, users);
|
|
51 |
SaveDocument(documentContent, user, documentInfo.Name, requiredAnnotations);
|
|
54 | 52 |
} |
55 | 53 |
else if (documentInfo.Format == Models.Enums.EAddDocumentFormat.ZIP) |
56 | 54 |
{ |
57 | 55 |
var (names, contents) = UnzipDocuments(documentInfo.Content); |
58 | 56 |
for (int i = 0; i < names.Count; i++) |
59 | 57 |
{ |
60 |
SaveDocument(contents[i], user, names[i], users);
|
|
58 |
SaveDocument(contents[i], user, names[i], requiredAnnotations);
|
|
61 | 59 |
} |
62 | 60 |
} |
63 | 61 |
} |
... | ... | |
92 | 90 |
return (names, contents); |
93 | 91 |
} |
94 | 92 |
|
95 |
private void SaveDocument(string content, User userAdded, string documentName, List<User> users)
|
|
93 |
private void SaveDocument(string content, User userAdded, string documentName, int requiredAnnotations)
|
|
96 | 94 |
{ |
97 | 95 |
DocumentContent documentContent = new DocumentContent() |
98 | 96 |
{ |
... | ... | |
106 | 104 |
UserAdded = userAdded, |
107 | 105 |
Name = documentName, |
108 | 106 |
Length = documentContent.Content.Length, |
109 |
RequiredAnnotations = GlobalConfiguration.RequiredAnnotations
|
|
107 |
RequiredAnnotations = requiredAnnotations
|
|
110 | 108 |
}; |
111 | 109 |
|
112 | 110 |
databaseContext.DocumentContents.Add(documentContent); |
... | ... | |
167 | 165 |
|
168 | 166 |
public void SetRequiredAnnotationsGlobal(int requiredAnnotations) |
169 | 167 |
{ |
170 |
GlobalConfiguration.RequiredAnnotations = requiredAnnotations; |
|
168 |
var requiredAnnotationsItem = databaseContext.ConfigurationItems.Single(ci => ci.Key == Constants.Constants.RequiredAnnotationsKey); |
|
169 |
requiredAnnotationsItem.Value = requiredAnnotations.ToString(); |
|
170 |
databaseContext.SaveChanges(); |
|
171 | 171 |
} |
172 | 172 |
|
173 |
public int GetRequiredAnnotationsGlobal() |
|
174 |
{ |
|
175 |
var requiredAnnotationsItem = databaseContext.ConfigurationItems.Single(ci => ci.Key == Constants.Constants.RequiredAnnotationsKey); |
|
176 |
return int.Parse(requiredAnnotationsItem.Value); |
|
177 |
} |
|
173 | 178 |
} |
174 | 179 |
} |
Také k dispozici: Unified diff
Added endpoint to get global required annotations, moved configuration to database