AspNetIdentity
AspNetIdentity copied to clipboard
UserManager.AddToRolesAsync() and RemoveFromRolesAsync() fail on any conflict
When adding multiple roles or generally updating a user's roles, I'd like to be able to just give UserManager.AddToRolesAsync()
the full list of roles that the user should have and have it add any new roles. As it currently is, if the user already has even 1 of the roles being assigned, the operation reports as a failure, at best having added any new roles in the list prior to the role that the user already has.
Similarly, when removing roles, UserManager.RemoveFromRolesAsync()
will fail if the user does not have any of the given roles when, in my opinion, it should ignore those and continue with removing any that the user does have.
Looking at the code, it appears that it could be as simple as changing return new IdentityResult(Resources.UserAlreadyInRole);
to continue;
in UserManager.AddToRolesAsync()
and changing return new IdentityResult(Resources.UserNotInRole);
to continue;
in UserManager.RemoveFromRolesAsync()
.