RoleDataSeed.cs
2.32 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
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Yi.Framework.Rbac.Domain.Entities;
using Yi.Framework.Rbac.Domain.Shared.Enums;
using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
{
public class RoleDataSeed : IDataSeedContributor, ITransientDependency
{
private ISqlSugarRepository<RoleAggregateRoot> _repository;
public RoleDataSeed(ISqlSugarRepository<RoleAggregateRoot> repository)
{
_repository = repository;
}
public List<RoleAggregateRoot> GetSeedData()
{
var entities = new List<RoleAggregateRoot>();
RoleAggregateRoot role1 = new RoleAggregateRoot()
{
RoleName = "管理员",
RoleCode = "admin",
DataScope = DataScopeEnum.ALL,
OrderNum = 999,
Remark = "管理员",
IsDeleted = false
};
entities.Add(role1);
RoleAggregateRoot role2 = new RoleAggregateRoot()
{
RoleName = "测试角色",
RoleCode = "test",
DataScope = DataScopeEnum.ALL,
OrderNum = 1,
Remark = "测试用的角色",
IsDeleted = false
};
entities.Add(role2);
RoleAggregateRoot role3 = new RoleAggregateRoot()
{
RoleName = "普通角色",
RoleCode = "common",
DataScope = DataScopeEnum.ALL,
OrderNum = 1,
Remark = "正常用户",
IsDeleted = false
};
entities.Add(role3);
RoleAggregateRoot role4 = new RoleAggregateRoot()
{
RoleName = "默认角色",
RoleCode = "default",
DataScope = DataScopeEnum.ALL,
OrderNum = 1,
Remark = "可简单浏览",
IsDeleted = false
};
entities.Add(role4);
return entities;
}
public async Task SeedAsync(DataSeedContext context)
{
if (!await _repository.IsAnyAsync(x => true))
{
await _repository.InsertManyAsync(GetSeedData());
}
}
}
}