public async Task <IActionResult> RemoveUserFromClaim(AddOrRemoveClaimViewModel model) { if (model == null) { return(NotFound()); } var user = await _userManager.FindByIdAsync(model.UserId); if (user == null) { return(NotFound()); } var requestClaims = model.UserClaims.Where(r => r.IsSelected) .Select(u => new Claim(u.ClaimType, true.ToString())).ToList(); var result = await _userManager.RemoveClaimsAsync(user, requestClaims); if (result.Succeeded) { return(RedirectToAction("index")); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } return(View(model)); }
public async Task <IActionResult> AddUserToClaim(string id) { if (string.IsNullOrEmpty(id)) { return(NotFound()); } var user = await _userManager.FindByIdAsync(id); if (user == null) { return(NotFound()); } var allClaims = ClaimStore.AllClaims; var userClaims = await _userManager.GetClaimsAsync(user); var validClaims = allClaims .Where(c => userClaims.All(uc => uc.Type != c.Type)) .Select(c => new ClaimsViewModel(c.Type)).ToList(); var model = new AddOrRemoveClaimViewModel(id, validClaims); return(View(model)); }
public async Task <IActionResult> RemoveUserFromClaim(string id) { if (string.IsNullOrEmpty(id)) { return(NotFound()); } var user = await _userManager.FindByIdAsync(id); if (user == null) { return(NotFound()); } var userClaims = await _userManager.GetClaimsAsync(user); var validClaims = userClaims.Select(c => new ClaimsViewModel(c.Type)).ToList(); var model = new AddOrRemoveClaimViewModel(id, validClaims); return(View(model)); }