Projekt

Obecné

Profil

Stáhnout (4.27 KB) Statistiky
| Větev: | Tag: | Revize:
1 ebb51a7f Vojtěch Bartička
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 b8028d82 Vojtěch Bartička
            if (!context.Users.Any(u => u.Role == ERole.ADMINISTRATOR))
18 ebb51a7f Vojtěch Bartička
            {
19 fc0e5b36 Vojtěch Bartička
                DocumentContent content = new DocumentContent()
20
                {
21
                    Content = "Dummy content"
22
                };
23 ebb51a7f Vojtěch Bartička
                context.DocumentContents.Add(content);
24
25 fc0e5b36 Vojtěch Bartička
                User user = new User()
26
                {
27
                    Username = "testuser",
28
                    Name = "Test",
29
                    Surname = "User",
30 c99a6c25 Lukáš Vlček
                    Password = BCrypt.Net.BCrypt.HashPassword("password"),
31 fc0e5b36 Vojtěch Bartička
                    Role = ERole.ANNOTATOR
32
                };
33 ebb51a7f Vojtěch Bartička
                context.Users.Add(user);
34
35 c99a6c25 Lukáš Vlček
                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 fc0e5b36 Vojtěch Bartička
                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 ebb51a7f Vojtěch Bartička
                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 fc0e5b36 Vojtěch Bartička
                Class clss = new Class()
70
                {
71
                    Color = "rgb(...)",
72
                    Description = "Dummy description",
73
                    Name = "Dummy class name"
74
                };
75 ebb51a7f Vojtěch Bartička
                context.Classes.Add(clss);
76
77
                annotation.Classes.Add(clss);
78
79 fc0e5b36 Vojtěch Bartička
                TagCategory category = new TagCategory()
80
                {
81
                    Name = "Dummy category",
82
                    Color = "rgb(...)",
83
                    Description = "Dummy category description"
84
                };
85 ebb51a7f Vojtěch Bartička
                context.TagCategories.Add(category);
86
87 fc0e5b36 Vojtěch Bartička
                Tag tag = new Tag()
88
                {
89
                    Name = "Dummy tag",
90
                    Category = category,
91
                    Description = "Dummy tag",
92
                    Color = "rgb(...)"
93
                };
94 ebb51a7f Vojtěch Bartička
                context.Tags.Add(tag);
95 fc0e5b36 Vojtěch Bartička
                SubTag subTag = new SubTag()
96
                {
97
                    Description = "Dummy subtag",
98
                    Name = "Dummy subtag",
99
                    Tag = tag
100
                };
101 ebb51a7f Vojtěch Bartička
                context.SubTags.Add(subTag);
102
103 fc0e5b36 Vojtěch Bartička
                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 ebb51a7f Vojtěch Bartička
                context.AnnotationTags.Add(annotationTag);
113
114
                context.SaveChanges();
115
            }
116
        }
117
118
        public static void SeedProduction(DatabaseContext context)
119
        {
120 b8028d82 Vojtěch Bartička
            if (!context.Users.Any(u => u.Role == ERole.ADMINISTRATOR))
121 ebb51a7f Vojtěch Bartička
            {
122 fc0e5b36 Vojtěch Bartička
                User admin = new User()
123
                {
124
                    Name = "Admin",
125
                    Surname = "Admin",
126
                    Role = ERole.ADMINISTRATOR,
127
                    Username = "admin",
128 c99a6c25 Lukáš Vlček
                    Password = BCrypt.Net.BCrypt.HashPassword("123a456b789c")
129 fc0e5b36 Vojtěch Bartička
                };
130 ebb51a7f Vojtěch Bartička
                context.Users.Add(admin);
131
                context.SaveChanges();
132
            }
133
        }
134
    }
135 c99a6c25 Lukáš Vlček
}