Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 09b22f6f

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

Added documents and annotations to seeding

Zobrazit rozdíly:

Backend/Core/Seeding/Seeder.cs
24 24
                AddTagInstance(context);
25 25
                context.SaveChanges();
26 26
            }
27
           
28 27
        }
29 28

  
30 29
        private static void AddTagInstance(DatabaseContext context)
31 30
        {
31
            AddDocumentAndAnnotation(context);
32

  
32 33
            var tag = context.Tags.Where(t => context.SubTags.Any(st => st.Tag == t)).First();
33 34
            var subtag = context.SubTags.Where(st => st.Tag == tag).First();
34 35
            var annotation = context.Annotations.First();
......
45 46
            context.AnnotationTags.Add(at);
46 47
        }
47 48

  
49
        private static void AddDocumentAndAnnotation(DatabaseContext context)
50
        {
51
            var adminUser = context.Users.Where(u => u.Role == ERole.ADMINISTRATOR).First();
52
            var normalUser = context.Users.Where(u => u.Role == ERole.ANNOTATOR).First();
53

  
54
            // Add documents
55
            DocumentContent dctext = new DocumentContent()
56
            {
57
                Content = "sample document content of TEXT file"
58
            };
59
            context.DocumentContents.Add(dctext);
60

  
61
            Document dtext = new()
62
            {
63
                Content = dctext,
64
                Name = "Sample TEXT document",
65
                DateAdded = DateTime.Now,
66
                UserAdded = adminUser,
67
                Length = dctext.Content.Length,
68
                RequiredAnnotations = 3
69
            };
70
            context.Documents.Add(dtext);
71

  
72
            DocumentContent dchtml = new DocumentContent()
73
            {
74
                Content = "<!DOCTYPE html><html>sample document content of HTML file</html>"
75
            };
76
            context.DocumentContents.Add(dchtml);
77

  
78
            Document dhtml = new()
79
            {
80
                Content = dchtml,
81
                Name = "Sample TEXT document",
82
                DateAdded = DateTime.Now,
83
                UserAdded = adminUser,
84
                Length = dchtml.Content.Length,
85
                RequiredAnnotations = 3
86
            };
87
            context.Documents.Add(dhtml);
88

  
89
            // Create user and admin annotation
90
            Annotation annotationAdmin = new Annotation()
91
            {
92
                State = EState.NEW,
93
                DateAssigned = DateTime.Now,
94
                DateLastChanged = DateTime.Now,
95
                Document = dtext,
96
                Note = "sample note",
97
                User = adminUser,
98
                UserAssigned = adminUser,
99
            };
100
            Annotation annotationUser = new Annotation()
101
            {
102
                State = EState.NEW,
103
                DateAssigned = DateTime.Now,
104
                DateLastChanged = DateTime.Now,
105
                Document = dhtml,
106
                Note = "sample note",
107
                User = normalUser,
108
                UserAssigned = adminUser,
109
            };
110
            context.Annotations.Add(annotationUser);
111
            context.Annotations.Add(annotationAdmin);
112

  
113
            context.SaveChanges();
114
        }
115

  
48 116
        public static void SeedProduction(DatabaseContext context)
49 117
        {
50 118
            if (!context.Users.Any(u => u.Role == ERole.ADMINISTRATOR))

Také k dispozici: Unified diff