Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
        private void LoadUserPermissions(SafeUserModel userModel)
        {
            userModel.Permissions = new ObservableCollection<PermissionModel>();

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

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

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