UserDataSeed.cs
3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using Microsoft.Extensions.Options;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Yi.Framework.Rbac.Domain.Entities;
using Yi.Framework.Rbac.Domain.Entities.ValueObjects;
using Yi.Framework.Rbac.Domain.Shared.Enums;
using Yi.Framework.Rbac.Domain.Shared.Options;
using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
{
public class UserDataSeed : IDataSeedContributor, ITransientDependency
{
private ISqlSugarRepository<UserAggregateRoot> _repository;
private RbacOptions _options;
public UserDataSeed(ISqlSugarRepository<UserAggregateRoot> repository, IOptions<RbacOptions> options)
{
_repository = repository;
_options = options.Value;
}
public async Task SeedAsync(DataSeedContext context)
{
if (!await _repository.IsAnyAsync(x => true))
{
var entities = new List<UserAggregateRoot>();
UserAggregateRoot user1 = new UserAggregateRoot()
{
Name = "超级管理员",
UserName = "admin",
Nick = "超级管理员",
EncryPassword = new EncryPasswordValueObject(_options.AdminPassword),
Email = "admin@example.com",
Phone = 13800000000,
Sex = SexEnum.Male,
Address = "成都",
Age = 20,
Introduction = "超级管理员",
OrderNum = 999,
Remark = "超级管理员",
State = true
};
user1.BuildPassword();
entities.Add(user1);
UserAggregateRoot user2 = new UserAggregateRoot()
{
Name = "测试",
UserName = "test",
Nick = "测试",
EncryPassword=new EncryPasswordValueObject(_options.AdminPassword),
Email = "test@example.com",
Phone = 15900000000,
Sex = SexEnum.Woman,
Address = "成都",
Age = 18,
Introduction = "测试",
OrderNum = 1,
Remark = "测试",
State = true
};
user2.BuildPassword();
entities.Add(user2);
UserAggregateRoot user3 = new UserAggregateRoot()
{
Name = "游客",
UserName = "guest",
Nick = "测试",
EncryPassword = new EncryPasswordValueObject("123456"),
Email = "454313500@qq.com",
Phone = 15900000000,
Sex = SexEnum.Woman,
Address = "深圳",
Age = 18,
Introduction = "临时游客",
OrderNum = 1,
Remark = "懒得创账号",
State = true
};
user3.BuildPassword();
entities.Add(user3);
await _repository.InsertManyAsync(entities);
}
}
}
}