forked from liaozb/APIJSON.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDbInit.cs
More file actions
38 lines (33 loc) · 1.12 KB
/
DbInit.cs
File metadata and controls
38 lines (33 loc) · 1.12 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
using APIJSON.NET.Models;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
namespace APIJSON.NET
{
public static class DbInit
{
public static void Initialize(IApplicationBuilder app)
{
var db = app.ApplicationServices.GetRequiredService<DbContext>();
db.Db.CodeFirst.InitTables(typeof(Login));
if (!db.LoginDb.IsAny(it=>it.userId>0))
{
var ds = new List<Login>();
for (int i = 1; i < 10; i++)
{
var d = new Login();
d.userId = i;
d.userName = "admin"+i.ToString();
d.passWordSalt = Guid.NewGuid().ToString();
d.passWord = SimpleStringCipher.Instance.Encrypt("123456", null, Encoding.ASCII.GetBytes(d.passWordSalt));
d.roleCode = "role1";
ds.Add(d);
}
db.LoginDb.InsertRange(ds.ToArray());
}
}
}
}