Projekt

Obecné

Profil

Stáhnout (3.8 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.Documents.Any())
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 = "password",
31
                    Role = ERole.ANNOTATOR
32
                };
33
                context.Users.Add(user);
34

    
35
                Document document = new Document()
36
                {
37
                    Content = content,
38
                    Name = "Test document",
39
                    DateAdded = DateTime.Now,
40
                    Length = 10,
41
                    RequiredAnnotations = 3,
42
                    UserAdded = user
43
                };
44
                context.Documents.Add(document);
45
                context.SaveChanges();
46

    
47
                Annotation annotation = new Annotation()
48
                {
49
                    DateAssigned = DateTime.Now,
50
                    DateLastChanged = DateTime.Now,
51
                    Document = document,
52
                    Note = "",
53
                    State = EState.NEW,
54
                    User = user,
55
                    UserAssigned = user
56
                };
57
                context.Annotations.Add(annotation);
58

    
59
                Class clss = new Class()
60
                {
61
                    Color = "rgb(...)",
62
                    Description = "Dummy description",
63
                    Name = "Dummy class name"
64
                };
65
                context.Classes.Add(clss);
66

    
67
                annotation.Classes.Add(clss);
68

    
69
                TagCategory category = new TagCategory()
70
                {
71
                    Name = "Dummy category",
72
                    Color = "rgb(...)",
73
                    Description = "Dummy category description"
74
                };
75
                context.TagCategories.Add(category);
76

    
77
                Tag tag = new Tag()
78
                {
79
                    Name = "Dummy tag",
80
                    Category = category,
81
                    Description = "Dummy tag",
82
                    Color = "rgb(...)"
83
                };
84
                context.Tags.Add(tag);
85
                SubTag subTag = new SubTag()
86
                {
87
                    Description = "Dummy subtag",
88
                    Name = "Dummy subtag",
89
                    Tag = tag
90
                };
91
                context.SubTags.Add(subTag);
92

    
93
                AnnotationTag annotationTag = new AnnotationTag()
94
                {
95
                    Annotation = annotation,
96
                    Instance = 0,
97
                    Length = 1,
98
                    Position = 0,
99
                    Tag = tag,
100
                    Note = "Dummy note"
101
                };
102
                context.AnnotationTags.Add(annotationTag);
103

    
104
                context.SaveChanges();
105
            }
106
        }
107

    
108
        public static void SeedProduction(DatabaseContext context)
109
        {
110
            if (!context.Documents.Any())
111
            {
112
                User admin = new User()
113
                {
114
                    Name = "Admin",
115
                    Surname = "Admin",
116
                    Role = ERole.ADMINISTRATOR,
117
                    Username = "admin",
118
                    Password = "123a456b789c"
119
                };
120
                context.Users.Add(admin);
121
                context.SaveChanges();
122
            }
123
        }
124
    }
125
}
    (1-1/1)