public async Task <IActionResult> Edit(EditeRoles model) { var role = await roleManager.FindByIdAsync(model.Id); if (role == null) { ViewBag.ErrorMessage = $"Role with Id = {model.Id} cannot be found"; return(View("NotFound")); } else { role.Name = model.RoleName; // Update the Role using UpdateAsync var result = await roleManager.UpdateAsync(role); if (result.Succeeded) { return(RedirectToAction("ListRoles")); } foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } return(View(model)); } }
public async Task <IActionResult> Edit(String id) { var role = await roleManager.FindByIdAsync(id); if (role == null) { ViewBag.ErrorMessage = $"Role with Id = {id} cannot be found"; return(View("NotFound")); } var model = new EditeRoles { Id = role.Id, RoleName = role.Name, Users = new List <string> () }; foreach (var user in userManager.Users.ToList()) { // If the user is in this role, add the username to // Users property of EditRoleViewModel. This model // object is then passed to the view for display if (await userManager.IsInRoleAsync(user, role.Name)) { model.Users.Add(user.UserName); } } return(View(model)); }