Exemple #1
0
        private void LoadAuthorisationPermissions(UserGroupModel groupModel)
        {
            groupModel.PermissionGroups = new ObservableCollection<PermissionGroupModel>();

            var groupPermissions = groupModel.UserGroup.UserGroupPermissions.Select(x => x.Permission);

            foreach (var permissionGroup in PermissionGroups)
            {
                var premissionGroupModel = new PermissionGroupModel(permissionGroup);
                premissionGroupModel.Permissions = new ObservableCollection<PermissionModel>();

                foreach (Permission permission in permissionGroup.Permissions)
                {
                    var permissionModel = new PermissionModel(permission)
                        {
                            IsChecked = groupPermissions.Contains(permission)
                        };

                    permissionModel.PropertyChanged += PermissionModelOnPropertyChanged;
                    permissionModel.Permission.PropertyChanged += OnPropertyChanged;

                    premissionGroupModel.Permissions.Add(permissionModel);
                }

                premissionGroupModel.IsChecked = premissionGroupModel.Permissions.Any() && premissionGroupModel.Permissions.All((x) => x.IsChecked);
                premissionGroupModel.PropertyChanged += PremissionGroupModelOnPropertyChanged;
                premissionGroupModel.PermissionGroup.PropertyChanged += PremissionGroupOnPropertyChanged;

                groupModel.PermissionGroups.Add(premissionGroupModel);
                groupModel.PropertyChanged += OnPropertyChanged;
                groupModel.UserGroup.PropertyChanged += OnPropertyChanged;
            }
        }
Exemple #2
0
        private void LoadAuthorisationPermissions(SafeUserModel userModel)
        {
            userModel.PermissionGroups = new ObservableCollection<PermissionGroupModel>();

            var userPermissions = userModel.User.UserPermissions.Select(x => x.Permission);

            foreach (var permissionGroup in PermissionGroups)
            {
                var premissionGroupModel = new PermissionGroupModel(permissionGroup);
                premissionGroupModel.Permissions = new ObservableCollection<PermissionModel>();

                foreach (Permission permission in permissionGroup.Permissions.OrderBy(x => x.Name))
                {
                    var permissionModel = new PermissionModel(permission)
                    {
                        IsChecked = userPermissions.Contains(permission)
                    };

                    permissionModel.PropertyChanged += PermissionModelOnPropertyChanged;
                    permissionModel.Permission.PropertyChanged += OnPropertyChanged;
                    premissionGroupModel.Permissions.Add(permissionModel);
                }

                premissionGroupModel.IsChecked = premissionGroupModel.Permissions.Any() &&
                                                 premissionGroupModel.Permissions.All((x) => x.IsChecked);

                premissionGroupModel.PropertyChanged += PremissionGroupModelOnPropertyChanged;

                premissionGroupModel.PermissionGroup.PropertyChanged += OnPropertyChanged;

                userModel.PermissionGroups.Add(premissionGroupModel);
            }
        }