Ejemplo n.º 1
0
 public async Task <IActionResult> ChangeRoles(AdminChangeRoleTransmitModel model)
 {
     if (await _dataAccess.ChangeRole(model))
     {
         return(StatusCode(200, "Role changed"));
     }
     return(StatusCode(418, "Something bad"));
 }
Ejemplo n.º 2
0
        public async Task <bool> ChangeRole(AdminChangeRoleTransmitModel model)
        {
            ApplicationUser user = await _userManager.FindByNameAsync(model.UserName);

            IList <string> roles = await _userManager.GetRolesAsync(user);

            IdentityResult deleteResult = await _userManager.RemoveFromRolesAsync(user, roles);

            IdentityResult addResult = new IdentityResult();

            if (deleteResult.Succeeded)
            {
                addResult = await _userManager.AddToRoleAsync(user, model.Role);
            }

            return(addResult.Succeeded);
        }