本文整理汇总了C#中ApplicationRoleManager.Create方法的典型用法代码示例。如果您正苦于以下问题:C# ApplicationRoleManager.Create方法的具体用法?C# ApplicationRoleManager.Create怎么用?C# ApplicationRoleManager.Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApplicationRoleManager
的用法示例。
在下文中一共展示了ApplicationRoleManager.Create方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateRole
public bool CreateRole(string name)
{
var rm = new ApplicationRoleManager(
new RoleStore<IdentityRole>(context));
var idResult = rm.Create(new IdentityRole(name));
return idResult.Succeeded;
}
示例2: CreateNewRole
public void CreateNewRole(Role model)
{
ApplicationRoleManager rm = new ApplicationRoleManager(new ApplicationRoleStore(new ApplicationDbContext()));
rm.Create(new ApplicationRole(model.Name)
{
Id = Guid.NewGuid().ToString()
});
}
示例3: SeedIdentityForEF
public static void SeedIdentityForEF(ApplicationDbContext context)
{
if ((!context.Roles.Any()) && (!context.Users.Any()))
{
var roleStore = new ApplicationRoleStore(context);
//var roleManager = new RoleManager<ApplicationRole, int>(roleStore);
var roleManager = new ApplicationRoleManager(roleStore);
var role = new ApplicationRole
{
Name = "Admin",
Description = "Super Admin User group"
};
roleManager.Create(role);
var userStore = new UserStore<ApplicationUser,
ApplicationRole,
int,
ApplicationUserLogin,
ApplicationUserRole,
ApplicationUserClaim>(context);
var userManager = new ApplicationUserManager(userStore);
var user = new ApplicationUser
{
Email = "[email protected]",
UserName = "SuperUser",
EmailConfirmed = true
};
user.FirstName = "Jack";
user.LastName = "Smith";
userManager.Create(user, "[email protected]");
var result = userManager.SetLockoutEnabled(user.Id, false);
userManager.AddToRole(user.Id, "Admin");
//added group manager
var groupManager = new ApplicationGroupManager(roleManager,userManager);
var newGroup = new ApplicationGroup("SuperAdmins", "Full Access to All");
groupManager.CreateGroup(newGroup);
groupManager.SetUserGroups(user.Id, new int[] { newGroup.Id });
groupManager.SetGroupRoles(newGroup.Id, new string[] { role.Name });
}
}