public async Task <IActionResult> CreateAllActionAsync() { AspNetRoleManager rolemger = GetService <AspNetRoleManager>(); IdentityRole admin = await rolemger.FindAsync(s => new IdentityRole { Id = s.Id }, d => d.Name.Equals("管理员")); var id = User.GetUserId(); var p = PermissionManager.GetAllActionByAssembly(); _permissionManager.Store.AutoSaveChanges = false; rolemger.Store.AutoSaveChanges = false; var bb = p.Each(action => { if (id.IsNotNullOrEmpty()) { action.CretaedUser = id; } }); foreach (var item in bb) { await rolemger.AddClaimAsync(admin, new Claim(item.Id, item.Id)); await _permissionManager.Store.CreateAsync(item, default); } rolemger.Store.AutoSaveChanges = true; _permissionManager.Store.AutoSaveChanges = true; await rolemger.Store.SaveChangesAsync(); var b = await _permissionManager.Store.SaveChangesAsync(); return(Json(b)); }
public async Task <IActionResult> CreateRoleClaimAsync([FromRoute] string id, [Bind("Id,RoleId")] [FromBody] AddRoleClaimDto model) { if (!ModelState.IsValid) { return(Failed()); } if (id != model.RoleId) { return(BadRequest()); } var result = await roleManager.AddClaimAsync(new IdentityRole { Id = model.RoleId }, new Claim(model.Id, model.Id)); return(Json(result)); }