public override async Task <IDisplayResult> UpdateAsync(ContentPartFieldDefinition partFieldDefinition, UpdatePartFieldEditorContext context)
        {
            var model = new UserPickerFieldSettingsViewModel();

            if (await context.Updater.TryUpdateModelAsync(model, Prefix))
            {
                var settings = new UserPickerFieldSettings
                {
                    Hint     = model.Hint,
                    Required = model.Required,
                    Multiple = model.Multiple
                };

                var selectedRoles = model.Roles.Where(x => x.IsSelected).Select(x => x.Role).ToArray();

                if (model.DisplayAllUsers || selectedRoles.Length == 0)
                {
                    // No selected role should have the same effect as display all users
                    settings.DisplayedRoles  = Array.Empty <string>();
                    settings.DisplayAllUsers = true;
                }
                else
                {
                    settings.DisplayedRoles  = selectedRoles;
                    settings.DisplayAllUsers = false;
                }

                context.Builder.WithSettings(settings);
            }

            return(Edit(partFieldDefinition, context.Updater));
        }
예제 #2
0
        public override async Task <IDisplayResult> UpdateAsync(ContentPartFieldDefinition partFieldDefinition, UpdatePartFieldEditorContext context)
        {
            var model    = new UserPickerFieldSettingsViewModel();
            var settings = new UserPickerFieldSettings();

            if (await context.Updater.TryUpdateModelAsync(model, Prefix))
            {
                settings.Hint            = model.Hint;
                settings.Required        = model.Required;
                settings.Multiple        = model.Multiple;
                settings.DisplayAllUsers = model.DisplayAllUsers;
                if (settings.DisplayAllUsers)
                {
                    settings.DisplayedRoles = Array.Empty <String>();
                }
                else
                {
                    settings.DisplayedRoles = model.Roles.Where(x => x.IsSelected).Select(x => x.Role).ToArray();
                }

                context.Builder.WithSettings(settings);
            }

            return(Edit(partFieldDefinition));
        }