Projekt

Obecné

Profil

Stáhnout (2.82 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() { Content = "Dummy content" };
20
                context.DocumentContents.Add(content);
21

    
22
                User user = new User() { Username = "testuser", Name = "Test", Surname = "User", Password = "password", Role = ERole.ANNOTATOR };
23
                context.Users.Add(user);
24

    
25
                Document document = new Document() { Content = content, Name = "Test document", DateAdded = DateTime.Now, Length = 10, RequiredAnnotations = 3, UserAdded = user };
26
                context.Documents.Add(document);
27
                context.SaveChanges();
28

    
29
                Annotation annotation = new Annotation()
30
                {
31
                    DateAssigned = DateTime.Now,
32
                    DateLastChanged = DateTime.Now,
33
                    Document = document,
34
                    Note = "",
35
                    State = EState.NEW,
36
                    User = user,
37
                    UserAssigned = user
38
                };
39
                context.Annotations.Add(annotation);
40

    
41
                Class clss = new Class() { Color = "rgb(...)", Description = "Dummy description", Name = "Dummy class name" };
42
                context.Classes.Add(clss);
43

    
44
                annotation.Classes.Add(clss);
45

    
46
                TagCategory category = new TagCategory() { Name = "Dummy category", Color = "rgb(...)", Description = "Dummy category description" };
47
                context.TagCategories.Add(category);
48

    
49
                Tag tag = new Tag() { Name = "Dummy tag", Category = category, Description = "Dummy tag", Color = "rgb(...)" };
50
                context.Tags.Add(tag);
51
                SubTag subTag = new SubTag() { Description = "Dummy subtag", Name = "Dummy subtag", Tag = tag };
52
                context.SubTags.Add(subTag);
53

    
54
                AnnotationTag annotationTag = new AnnotationTag() { Annotation = annotation, Instance = 0, Length = 1, Position = 0, Tag = tag, Note = "Dummy note" };
55
                context.AnnotationTags.Add(annotationTag);
56

    
57
                context.SaveChanges();
58
            }
59
        }
60

    
61
        public static void SeedProduction(DatabaseContext context)
62
        {
63
            if (!context.Documents.Any())
64
            {
65
                User admin = new User() { Name = "Admin", Surname = "Admin", Role = ERole.ADMINISTRATOR, Username = "admin", Password = "123a456b789c" };
66
                context.Users.Add(admin);
67
                context.SaveChanges();
68
            }
69
        }
70
    }
71
}
    (1-1/1)