Esempio n. 1
0
        public override async Task <IDisplayResult> UpdateAsync(ContentTypePartDefinition contentTypePartDefinition, UpdateTypePartEditorContext context)
        {
            if (!String.Equals(nameof(FacebookPluginPart), contentTypePartDefinition.PartDefinition.Name))
            {
                return(null);
            }

            var model = new FacebookPluginPartSettingsViewModel();

            await context.Updater.TryUpdateModelAsync(model, Prefix,
                                                      m => m.Liquid);

            if (!string.IsNullOrEmpty(model.Liquid) && !_templateManager.Validate(model.Liquid, out var errors))
            {
                context.Updater.ModelState.AddModelError(nameof(model.Liquid), S["The Body doesn't contain a valid Liquid expression. Details: {0}", string.Join(" ", errors)]);
            }
            else
            {
                context.Builder.WithSettings(new FacebookPluginPartSettings {
                    Liquid = model.Liquid
                });
            }

            return(Edit(contentTypePartDefinition, context.Updater));
        }
        public override async Task <IDisplayResult> UpdateAsync(ContentTypePartDefinition contentTypePartDefinition, UpdateTypePartEditorContext context)
        {
            if (!String.Equals(nameof(FacebookPluginPart), contentTypePartDefinition.PartDefinition.Name, StringComparison.Ordinal))
            {
                return(null);
            }

            var model = new FacebookPluginPartSettingsViewModel();

            await context.Updater.TryUpdateModelAsync(model, Prefix,
                                                      m => m.Liquid);

            if (context.Updater.ModelState.ValidationState == ModelValidationState.Valid)
            {
                model.FacebookPluginPartSettings = new FacebookPluginPartSettings()
                {
                    Liquid = model.Liquid
                };
                context.Builder.WithSettings(model.FacebookPluginPartSettings);
            }
            return(Edit(contentTypePartDefinition, context.Updater));
        }