Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 204bd181

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

Cleanup in seeding

Zobrazit rozdíly:

Backend/Core/Seeding/Seeder.cs
16 16
        {
17 17
            if (!context.Users.Any(u => u.Role == ERole.ADMINISTRATOR))
18 18
            {
19
                DocumentContent content = new DocumentContent()
20
                {
21
                    Content = "Dummy content"
22
                };
23
                context.DocumentContents.Add(content);
24

  
25
                User user = new User()
26
                {
27
                    Username = "testuser",
28
                    Name = "Test",
29
                    Surname = "User",
30
                    Password = BCrypt.Net.BCrypt.HashPassword("password"),
31
                    Role = ERole.ANNOTATOR
32
                };
33
                context.Users.Add(user);
34

  
35
                User admin = new User()
36
                {
37
                    Username = "admin",
38
                    Name = "Admin",
39
                    Surname = "User",
40
                    Password = BCrypt.Net.BCrypt.HashPassword("admin"),
41
                    Role = ERole.ADMINISTRATOR
42
                };
43
                context.Users.Add(admin);
44

  
45
                Document document = new Document()
46
                {
47
                    Content = content,
48
                    Name = "Test document",
49
                    DateAdded = DateTime.Now,
50
                    Length = 10,
51
                    RequiredAnnotations = 3,
52
                    UserAdded = user
53
                };
54
                context.Documents.Add(document);
55
                context.SaveChanges();
56

  
57
                Annotation annotation = new Annotation()
58
                {
59
                    DateAssigned = DateTime.Now,
60
                    DateLastChanged = DateTime.Now,
61
                    Document = document,
62
                    Note = "",
63
                    State = EState.NEW,
64
                    User = user,
65
                    UserAssigned = user
66
                };
67
                context.Annotations.Add(annotation);
68

  
69
                Class clss = new Class()
70
                {
71
                    Color = "rgb(...)",
72
                    Description = "Dummy description",
73
                    Name = "Dummy class name"
74
                };
75
                context.Classes.Add(clss);
76

  
77
                annotation.Classes.Add(clss);
78

  
79
                TagCategory category = new TagCategory()
80
                {
81
                    Name = "Dummy category",
82
                    Color = "rgb(...)",
83
                    Description = "Dummy category description"
84
                };
85
                context.TagCategories.Add(category);
86

  
87
                Tag tag = new Tag()
88
                {
89
                    Name = "Dummy tag",
90
                    Category = category,
91
                    Description = "Dummy tag",
92
                    Color = "rgb(...)"
93
                };
94
                context.Tags.Add(tag);
95
                SubTag subTag = new SubTag()
96
                {
97
                    Description = "Dummy subtag",
98
                    Name = "Dummy subtag",
99
                    Tag = tag
100
                };
101
                context.SubTags.Add(subTag);
102

  
103
                AnnotationTag annotationTag = new AnnotationTag()
104
                {
105
                    Annotation = annotation,
106
                    Instance = 0,
107
                    Length = 1,
108
                    Position = 0,
109
                    Tag = tag,
110
                    Note = "Dummy note"
111
                };
112
                context.AnnotationTags.Add(annotationTag);
113

  
19
                var users = AddUsers(context);
20
                var classes = AddClasses(context);
21
                DummyTags.AddDummyTags(context);
114 22
                context.SaveChanges();
115 23
            }
116 24
        }
......
131 39
                context.SaveChanges();
132 40
            }
133 41
        }
42

  
43
        private static List<Class> AddClasses(DatabaseContext context)
44
        {
45
            List<Class> classes = new List<Class>();
46
            Class class1 = new Class()
47
            {
48
                Name = "Class1",
49
                Description = "Class1 description",
50
                Color = "Class 1 color"
51
            };
52
            context.Classes.Add(class1);
53
            classes.Add(class1);
54
            return classes;
55
        }
56

  
57
        private static List<User> AddUsers(DatabaseContext context)
58
        {
59
            List<User> users = new List<User>();
60
            User annotator1 = new User()
61
            {
62
                Username = "annotator1",
63
                Name = "Anno",
64
                Surname = "Tator1",
65
                Password = BCrypt.Net.BCrypt.HashPassword("password"),
66
                Role = ERole.ANNOTATOR
67
            };
68
            context.Users.Add(annotator1);
69
            users.Add(annotator1);
70

  
71
            User annotator2 = new User()
72
            {
73
                Username = "annotator2",
74
                Name = "Anno",
75
                Surname = "Tator2",
76
                Password = BCrypt.Net.BCrypt.HashPassword("password"),
77
                Role = ERole.ANNOTATOR
78
            };
79
            context.Users.Add(annotator2);
80
            users.Add(annotator2);
81

  
82
            User annotator3 = new User()
83
            {
84
                Username = "annotator3",
85
                Name = "Anno",
86
                Surname = "Tator3",
87
                Password = BCrypt.Net.BCrypt.HashPassword("password"),
88
                Role = ERole.ANNOTATOR
89
            };
90
            context.Users.Add(annotator3);
91
            users.Add(annotator3);
92

  
93
            User annotator4 = new User()
94
            {
95
                Username = "annotator4",
96
                Name = "Anno",
97
                Surname = "Tator4",
98
                Password = BCrypt.Net.BCrypt.HashPassword("password"),
99
                Role = ERole.ANNOTATOR
100
            };
101
            context.Users.Add(annotator4);
102
            users.Add(annotator4);
103

  
104
            User annotator5 = new User()
105
            {
106
                Username = "annotator5",
107
                Name = "Anno",
108
                Surname = "Tator5",
109
                Password = BCrypt.Net.BCrypt.HashPassword("password"),
110
                Role = ERole.ANNOTATOR
111
            };
112
            context.Users.Add(annotator5);
113
            users.Add(annotator5);
114

  
115
            User admin = new User()
116
            {
117
                Username = "admin",
118
                Name = "Admin",
119
                Surname = "User",
120
                Password = BCrypt.Net.BCrypt.HashPassword("admin"),
121
                Role = ERole.ADMINISTRATOR
122
            };
123
            context.Users.Add(admin);
124
            users.Add(admin);
125

  
126
            return users;
127
        }
134 128
    }
135 129
}

Také k dispozici: Unified diff