-
Notifications
You must be signed in to change notification settings - Fork 1
/
Startup.cs
43 lines (39 loc) · 1.14 KB
/
Startup.cs
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
using CSE_DEPARTMENT.Models;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Owin;
using Owin;
[assembly: OwinStartupAttribute(typeof(CSE_DEPARTMENT.Startup))]
namespace CSE_DEPARTMENT
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
CreateUserAndRoles();
}
public void CreateUserAndRoles()
{
ApplicationDbContext context = new ApplicationDbContext();
var rolemanager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>());
var usermanager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
if (!rolemanager.RoleExists("SuperAdmin"))
{
//Create Default Role
var role = new IdentityRole("SuperAdmin");
rolemanager.Create(role);
//Create Default Users
var user = new ApplicationUser();
user.UserName = "[email protected]";
user.Email = "[email protected]";
string pwd = "@Anik123";
var newuser = usermanager.Create(user, pwd);
if (newuser.Succeeded)
{
usermanager.AddToRole(user.Id, "SuperAdmin");
}
}
}
}
}