Ejemplo n.º 1
0
        public async Task <IActionResult> RolesManagementPermissionsAction(RolesManagementModel model)
        {
            IEnumerable <string> newPerms   = (model.NewPermissions == null) ? new List <string>() : model.NewPermissions.Split(',').ToList();
            IEnumerable <string> permsToAdd = await _permissionManager.GetPermissionsToAddAsync(model.SelectedRole, newPerms);

            IEnumerable <string> permsToRemove = await _permissionManager.GetPermissionsToRemoveAsync(model.SelectedRole, newPerms);

            foreach (string perm in permsToAdd)
            {
                await _permissionManager.AddPermissionToRoleAsync(model.SelectedRole, perm);
            }

            foreach (string perm in permsToRemove)
            {
                await _permissionManager.RemovePermissionFromRoleAsync(model.SelectedRole, perm);
            }

            await _logManager.WriteRoleChangingAsync(User.Identity.Name, model.SelectedRole, newPerms.ToList(), permsToRemove.ToList(), permsToAdd.ToList());

            model.Roles = await _moneyRoleManager.GetRolesAsync();

            model.Permissions = await _permissionManager.GetPermissionsAsStringsAsync();

            model.NewRole = "";

            return(View(nameof(MainController.RolesManagement), model));
        }