public async Task <IActionResult> Edit(int id, [Bind("Id,Name,NormalizedName,ConcurrencyStamp")] ResumeRole organiRole) { if (id != organiRole.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(organiRole); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OrganiRoleExists(organiRole.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(organiRole)); }
public async Task <IActionResult> Create([Bind("Name")] ResumeRole organiRole) { if (ModelState.IsValid) { await roleManager.CreateAsync(organiRole); return(RedirectToAction(nameof(Index))); } return(View(organiRole)); }
static internal IApplicationBuilder SeedIdentity(this IApplicationBuilder builder) { using (var scope = builder.ApplicationServices.CreateScope()) { var userManager = scope.ServiceProvider.GetRequiredService <UserManager <ResumeUser> >(); var roleManager = scope.ServiceProvider.GetRequiredService <RoleManager <ResumeRole> >(); ResumeRole superAdminRole = roleManager.FindByNameAsync("Admin").Result; if (superAdminRole == null) { superAdminRole = new ResumeRole { Name = "Admin" }; roleManager.CreateAsync(superAdminRole).Wait(); } ResumeUser superAdminUser = userManager.FindByEmailAsync("*****@*****.**").Result; if (superAdminUser == null) { superAdminUser = new ResumeUser { Email = "*****@*****.**", UserName = "******", EmailConfirmed = true }; var resultUser = userManager.CreateAsync(superAdminUser, "123").Result; if (resultUser.Succeeded) { var roleResult = userManager.AddToRoleAsync(superAdminUser, "Admin").Result; } } else if (!userManager.IsInRoleAsync(superAdminUser, "Admin").Result) { userManager.AddToRoleAsync(superAdminUser, "Admin").Wait(); } } return(builder); }