public async Task RemoveRole(UserRolePairModel pairing)
        {
            string adminUserId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var    user        = await _userManager.FindByIdAsync(pairing.UserId);

            _logger.LogInformation("Admin {Admin} removed user {User} from role {Role}.", adminUserId, user.Id, pairing.RoleName);
            await _userManager.RemoveFromRoleAsync(user, pairing.RoleName);
        }
        public async Task  AddRole(UserRolePairModel pairing)
        {
            string adminUserId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            //var adminUser = _userData.GetUserById(adminUserId).First();
            var user = await _userManager.FindByIdAsync(pairing.UserId);

            _logger.LogInformation("Admin {Admin} added user {User} to role {Role}.", adminUserId, user.Id, pairing.RoleName);
            await _userManager.AddToRoleAsync(user, pairing.RoleName);
        }
        public async Task AddRole(UserRolePairModel pairing)
        {
            var user = await _userManager.FindByIdAsync(pairing.UserId);

            string loggedInUserId = User.FindFirstValue(ClaimTypes.NameIdentifier);

            _logger.LogInformation("Admin {Admin} added user {User} to role {Role}", loggedInUserId, user.Id, pairing.RoleName);

            await _userManager.AddToRoleAsync(user, pairing.RoleName);
        }
Esempio n. 4
0
        public async Task RemoveARole(UserRolePairModel pairing)
        {
            string loggedInUserId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var    loggedInUser   = _userData.GetUserById(loggedInUserId).First();

            var user = await _userManager.FindByIdAsync(pairing.UserId);

            _logger.LogInformation("Admin {Admin} removed user {User} from role {Role}",
                                   loggedInUser.EmailAddress, user.Email, pairing.RoleName);

            await _userManager.RemoveFromRoleAsync(user, pairing.RoleName);
        }
Esempio n. 5
0
        public async Task AddRole(UserRolePairModel pairing)
        {
            // with Logging who made the role change
            string loggedInUserId = User.FindFirstValue(ClaimTypes.NameIdentifier);

            var user = await _userManager.FindByIdAsync(pairing.UserId);

            // don't use string interpolations because it will break querries you can run later on the structured loggers
            _logger.LogInformation("Admin {Admin} add user {User} to role {Role}", loggedInUserId, user.Id, pairing.RoleName);

            await _userManager.AddToRoleAsync(user, pairing.RoleName);
        }
Esempio n. 6
0
        public async Task AddARole(UserRolePairModel pairing)
        {
            string loggedInUserId = User.FindFirstValue(ClaimTypes.NameIdentifier); //in framework: RequestContext.Principal.Identity.GetUserId();

            var user = await _userManager.FindByIdAsync(pairing.UserId);

            // Note, there is no $ before ". This is not string interpolation, but struxtured logging.
            _logger.LogInformation("Admin {Admin} added user {User} to role {Role}",
                                   loggedInUserId, user.Id, pairing.RoleName);

            await _userManager.AddToRoleAsync(user, pairing.RoleName);
        }
Esempio n. 7
0
        public async Task AddARole(UserRolePairModel pairing)
        {
            var user = await _userManager.FindByIdAsync(pairing.UserId);

            await _userManager.AddToRoleAsync(user, pairing.RoleName);
        }
Esempio n. 8
0
        public async Task RemoveARole(UserRolePairModel pairing)
        {
            var user = await _userManager.FindByIdAsync(pairing.UserId);

            await _userManager.RemoveFromRoleAsync(user, pairing.RoleName);
        }
        public async Task RemoveRole(UserRolePairModel data)
        {
            var user = await _userManager.FindByIdAsync(data.UserId);

            await _userManager.RemoveFromRoleAsync(user, data.RoleName);
        }
        public async Task AddRole(UserRolePairModel data)
        {
            var user = await _userManager.FindByIdAsync(data.UserId);

            await _userManager.AddToRoleAsync(user, data.RoleName);
        }