Пример #1
0
        public async Task RemoveRole(UserRolePairModel pairing)
        {
            //string loggedInUserId = User.FindFirstValue(ClaimTypes.NameIdentifier);

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

            await userManager.RemoveFromRoleAsync(user, pairing.RoleName);
        }
Пример #2
0
        public async Task RemoveRole(UserRolePairModel pairModel)
        {
            string loggedInUserID = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var    user           = await _userManager.FindByIdAsync(pairModel.UserId);

            _logger.LogInformation("Admin {Admin} removed user {User} from role {Role}", loggedInUserID, pairModel.UserId, pairModel.Role);

            await _userManager.RemoveFromRoleAsync(user, pairModel.Role);
        }
Пример #3
0
 public void RemoveARole(UserRolePairModel pairing)
 {
     using (var context = new ApplicationDbContext())
     {
         var userStore   = new UserStore <ApplicationUser>(context);
         var userManager = new UserManager <ApplicationUser>(userStore);
         userManager.RemoveFromRole(pairing.UserId, pairing.RoleName);
     }
 }
Пример #4
0
        public async Task AddARole(UserRolePairModel pair)
        {
            string loggeInUserId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var    user          = await _userManager.FindByIdAsync(pair.UserId);

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

            await _userManager.AddToRoleAsync(user, pair.RoleName);
        }
Пример #5
0
        public async Task AddRole(UserRolePairModel pairing)
        {
            //string loggedInUserId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            //var loggedInUser = userData.GetUserById(loggedInUserId).First();

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

            await userManager.AddToRoleAsync(user, pairing.RoleName);
        }
Пример #6
0
        public async Task RemoveToRole(UserRolePairModel pair)
        {
            string loggedInUserId = User.FindFirstValue(ClaimTypes.NameIdentifier);

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

            _logger.LogInformation("Admin {} quitó al usuario {User} del rol {Role}", loggedInUserId, user.Id, pair.RoleName);

            await _userManager.RemoveFromRoleAsync(user, pair.RoleName);
        }
Пример #7
0
        public void AddRole(UserRolePairModel pair)
        {
            using (var context = new ApplicationDbContext())
            {
                var userStore   = new UserStore <ApplicationUser>(context);
                var userManager = new UserManager <ApplicationUser>(userStore);

                userManager.AddToRole(pair.UserId, pair.RoleName);
            }
        }
        public void DeleteRole(UserRolePairModel userRole)
        {
            using (var context = new ApplicationDbContext())
            {
                var userStore   = new UserStore <ApplicationUser>(context);
                var userManager = new UserManager <ApplicationUser>(userStore);

                userManager.RemoveFromRole(userRole.UserId, userRole.RoleName);
            }
        }
Пример #9
0
        public async Task AddToRole(UserRolePairModel pair)
        {
            string loggedInUserId = User.FindFirstValue(ClaimTypes.NameIdentifier);

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

            // Do not use string interpolation in loggers. This way is correct
            _logger.LogInformation("Admin {} agregó al usuario {User} al rol {Role}", loggedInUserId, user.Id, pair.RoleName);

            await _userManager.AddToRoleAsync(user, pair.RoleName);
        }
Пример #10
0
        public async Task RemoveRole(UserRolePairModel pairing)
        {
            var loggedInUserId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var user           = await userManager.FindByIdAsync(pairing.UserId);

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

            await userManager.RemoveFromRoleAsync(user, pairing.RoleName);
        }
        public async Task AddRole(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} added user {User} to role {Role}",
                                   loggedInUser.FirstName + " " + loggedInUser.LastName, user.Id, pairing.RoleName);

            await _usermanager.AddToRoleAsync(user, pairing.RoleName);
        }
Пример #12
0
 public async Task RemoveUserFromRole(UserRolePairModel pairing)
 {
     using (HttpResponseMessage response = await _apiClientInitializer.ApiClient.PostAsJsonAsync("/api/User/Admin/RemoveRole", pairing))
     {
         if (response.IsSuccessStatusCode)
         {
             //Send feedback about successful operation
         }
         else
         {
             throw new Exception(response.ReasonPhrase);
         }
     }
 }
Пример #13
0
        public async Task RemoveARole(UserRolePairModel pairing)
        {
            // Log the information about who give who a role
            string loggedInUserId = User.FindFirstValue(ClaimTypes.NameIdentifier);

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

            // Log it before even if its crashed before
            // its done, to know that someone try to do it
            // Do not use string interpolation with logging
            _logger.LogInformation("Admin {Admin} removed user {User} from role {Role}",
                                   loggedInUserId, user.Id, pairing.RoleName);

            await _userManager.RemoveFromRoleAsync(user, pairing.RoleName);
        }
Пример #14
0
        public async Task AddRole(UserRolePairModel pair)
        {
            string loggedUserId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var    loggedUser   = _userData.GetUserById(loggedUserId);

            var userIdentity = await _userManager.FindByIdAsync(pair.UserId);

            if (userIdentity is null)
            {
                // TODO log?
            }
            else
            {
                _logger.LogInformation("Admin {Admin} added user {User} to role {Role}",
                                       loggedUser.EmailAddress, userIdentity.Email, pair.RoleName);
                await _userManager.AddToRoleAsync(userIdentity, pair.RoleName);
            }
        }
        private async Task UpdateUserRoles(UserRole userAddRole, UserRole userRemoveRole)
        {
            Console.WriteLine(">--------<");
            Console.WriteLine("Attempting to update roles.");
            infoMessage += Environment.NewLine + "Attempting to create new userroles..." + Environment.NewLine;
            await Task.Delay(3000);

            if (userAddRole.Roles is not null)
            {
                foreach (var role in userAddRole.Roles)
                {
                    Console.WriteLine($"Creating rolepair with User {userAddRole.Id} and role {role.Value} to be added.");

                    UserRolePairModel rolePair = new UserRolePairModel
                    {
                        UserId   = userAddRole.Id,
                        RoleName = role.Value
                    };

                    using (HttpResponseMessage response = await Http.PostAsJsonAsync("https://localhost:44372/Api/_Admin/Users/AddRole", rolePair))
                    {
                        Console.WriteLine("Accessing databse to update role.");

                        if (response.IsSuccessStatusCode)
                        {
                            infoMessage += Environment.NewLine + "Succesfully added new role: " + role.Value.ToString() + Environment.NewLine;
                            Console.WriteLine("Successfully added role.");
                        }
                        else
                        {
                            infoMessage += Environment.NewLine + "something went wrong updating the userRoles. Error:" + response.ReasonPhrase;
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("No roles to add to the user");
            }

            if (userRemoveRole.Roles is not null)
            {
                foreach (var role in userRemoveRole.Roles)
                {
                    Console.WriteLine($"Creating rolepair with User {userRemoveRole.Id} and role {role.Value} to be removed.");
                    UserRolePairModel rolePair = new UserRolePairModel
                    {
                        UserId   = userRemoveRole.Id,
                        RoleName = role.Value
                    };

                    using (HttpResponseMessage response = await Http.PostAsJsonAsync("https://localhost:44372/Api/_Admin/Users/RemoveRole", rolePair))
                    {
                        Console.WriteLine("Accessing databse to remove role.");

                        if (response.IsSuccessStatusCode)
                        {
                            infoMessage += Environment.NewLine + "Succesfully removed role. ";
                            Console.WriteLine("Successfully removed role.");
                        }
                        else
                        {
                            infoMessage += Environment.NewLine + "something went wrong updating the userRoles. Error:" + response.ReasonPhrase;
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("No roles to reomve from the user");
            }
        }
        public async Task RemoveRole(UserRolePairModel pairing)
        {
            var user = await _userManager.FindByIdAsync(pairing.UserId);

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

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