Example #1
0
        protected override DriverResult Editor(AdminSearchSettingsPart part, IUpdateModel updater, dynamic shapeHelper)
        {
            return(ContentShape("Parts_AdminSearch_SiteSettings", () => {
                var model = new AdminSearchSettingsViewModel {
                    AvailableIndexes = _indexManager.GetSearchIndexProvider().List().ToList(),
                    SelectedIndex = part.SearchIndex
                };

                if (updater != null)
                {
                    if (updater.TryUpdateModel(model, Prefix, null, new[] { "AvailableIndexes" }))
                    {
                        part.SearchIndex = model.SelectedIndex;
                    }
                }

                return shapeHelper.EditorTemplate(TemplateName: "Parts/AdminSearch.SiteSettings", Model: model, Prefix: Prefix);
            }).OnGroup("search"));
        }
        public override async Task <IDisplayResult> UpdateAsync(AdminSearchSettings section, BuildEditorContext context)
        {
            var user = _httpContextAccessor.HttpContext?.User;

            if (!await _authorizationService.AuthorizeAsync(user, Permissions.ManageAdminSearchSettings))
            {
                return(null);
            }

            if (context.GroupId == GroupId)
            {
                var model = new AdminSearchSettingsViewModel();

                await context.Updater.TryUpdateModelAsync(model, Prefix);

                section.AdminSearchIndex  = model.AdminSearchIndex;
                section.AdminSearchFields = model.AdminSearchFields?.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
            }

            return(await EditAsync(section, context));
        }