Projekt

Obecné

Profil

Stáhnout (4.27 KB) Statistiky
| Větev: | Tag: | Revize:
1
using Core.Contexts;
2
using Core.Entities;
3
using Core.Enums;
4
using Microsoft.EntityFrameworkCore;
5
using System;
6
using System.Collections.Generic;
7
using System.Linq;
8
using System.Text;
9
using System.Threading.Tasks;
10

    
11
namespace Core.Seeding
12
{
13
    public class Seeder
14
    {
15
        public static void SeedDevelopment(DatabaseContext context)
16
        {
17
            if (!context.Users.Any(u => u.Role == ERole.ADMINISTRATOR))
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

    
114
                context.SaveChanges();
115
            }
116
        }
117

    
118
        public static void SeedProduction(DatabaseContext context)
119
        {
120
            if (!context.Users.Any(u => u.Role == ERole.ADMINISTRATOR))
121
            {
122
                User admin = new User()
123
                {
124
                    Name = "Admin",
125
                    Surname = "Admin",
126
                    Role = ERole.ADMINISTRATOR,
127
                    Username = "admin",
128
                    Password = BCrypt.Net.BCrypt.HashPassword("123a456b789c")
129
                };
130
                context.Users.Add(admin);
131
                context.SaveChanges();
132
            }
133
        }
134
    }
135
}
    (1-1/1)