public async Task <IActionResult> CreatePost(ShortcodeTemplateViewModel model, string submit) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageShortcodeTemplates)) { return(Forbid()); } if (ModelState.IsValid) { if (String.IsNullOrWhiteSpace(model.Name)) { ModelState.AddModelError(nameof(ShortcodeTemplateViewModel.Name), S["The name is mandatory."]); } else if (String.IsNullOrEmpty(model.Content)) { ModelState.AddModelError(nameof(ShortcodeTemplateViewModel.Content), S["The template content is mandatory."]); } else if (!_liquidTemplateManager.Validate(model.Content, out var errors)) { ModelState.AddModelError(nameof(ShortcodeTemplateViewModel.Content), S["The template doesn't contain a valid Liquid expression. Details: {0}", string.Join(" ", errors)]); } else { var shortcodeTemplatesDocument = await _shortcodeTemplatesManager.GetShortcodeTemplatesDocumentAsync(); if (shortcodeTemplatesDocument.ShortcodeTemplates.ContainsKey(model.Name)) { ModelState.AddModelError(nameof(ShortcodeTemplateViewModel.Name), S["A template with the same name already exists."]); } } } if (ModelState.IsValid) { var template = new ShortcodeTemplate { Content = model.Content, Hint = model.Hint, Usage = model.Usage, DefaultValue = model.DefaultValue, Categories = JsonConvert.DeserializeObject <string[]>(model.SelectedCategories) }; await _shortcodeTemplatesManager.UpdateShortcodeTemplateAsync(model.Name, template); if (submit == "SaveAndContinue") { return(RedirectToAction(nameof(Edit), new { name = model.Name })); } else { return(RedirectToAction(nameof(Index))); } } // If we got this far, something failed, redisplay form return(View(model)); }
public override async Task <IDisplayResult> UpdateAsync(ContentTypePartDefinition contentTypePartDefinition, UpdateTypePartEditorContext context) { if (!String.Equals(nameof(TitlePart), contentTypePartDefinition.PartDefinition.Name)) { return(null); } var model = new TitlePartSettingsViewModel(); await context.Updater.TryUpdateModelAsync(model, Prefix, m => m.Pattern, m => m.Options, m => m.RenderTitle); if (!string.IsNullOrEmpty(model.Pattern) && !_templateManager.Validate(model.Pattern, out var errors)) { context.Updater.ModelState.AddModelError(nameof(model.Pattern), S["Pattern doesn't contain a valid Liquid expression. Details: {0}", string.Join(" ", errors)]); } else { context.Builder.WithSettings(new TitlePartSettings { Pattern = model.Pattern, Options = model.Options, RenderTitle = model.RenderTitle }); } return(Edit(contentTypePartDefinition, context.Updater)); }
public override async Task <IDisplayResult> UpdateAsync(ContentTypeDefinition contentTypeDefinition, UpdateTypeEditorContext context) { var model = new FullTextAspectSettingsViewModel(); await context.Updater.TryUpdateModelAsync(model, Prefix, m => m.IncludeFullTextTemplate, m => m.FullTextTemplate, m => m.IncludeDisplayText, m => m.IncludeBodyAspect); if (!string.IsNullOrEmpty(model.FullTextTemplate) && !_templateManager.Validate(model.FullTextTemplate, out var errors)) { context.Updater.ModelState.AddModelError(nameof(model.FullTextTemplate), T["Full-text doesn't contain a valid Liquid expression. Details: {0}", string.Join(" ", errors)]); } else { context.Builder.WithSettings(new FullTextAspectSettings { IncludeFullTextTemplate = model.IncludeFullTextTemplate, FullTextTemplate = model.FullTextTemplate, IncludeDisplayText = model.IncludeDisplayText, IncludeBodyAspect = model.IncludeBodyAspect }); } return(Edit(contentTypeDefinition, context.Updater)); }
public override async Task <IDisplayResult> UpdateAsync(ContentTypePartDefinition contentTypePartDefinition, UpdateTypePartEditorContext context) { if (!String.Equals(nameof(AutoroutePart), contentTypePartDefinition.PartDefinition.Name, StringComparison.Ordinal)) { return(null); } var model = new AutoroutePartSettingsViewModel(); await context.Updater.TryUpdateModelAsync(model, Prefix, m => m.Pattern, m => m.AllowCustomPath, m => m.AllowUpdatePath, m => m.ShowHomepageOption); if (!string.IsNullOrEmpty(model.Pattern) && !_templateManager.Validate(model.Pattern, out var errors)) { context.Updater.ModelState.AddModelError(nameof(model.Pattern), T["Pattern doesn't contain a valid Liquid expression. Details: {0}", string.Join(" ", errors)]); } else { context.Builder.WithSetting(nameof(AutoroutePartSettings.Pattern), model.Pattern); context.Builder.WithSetting(nameof(AutoroutePartSettings.AllowCustomPath), model.AllowCustomPath.ToString()); context.Builder.WithSetting(nameof(AutoroutePartSettings.AllowUpdatePath), model.AllowUpdatePath.ToString()); context.Builder.WithSetting(nameof(AutoroutePartSettings.ShowHomepageOption), model.ShowHomepageOption.ToString()); } return(Edit(contentTypePartDefinition, context.Updater)); }
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) { var model = new AutoroutePartSettingsViewModel(); await context.Updater.TryUpdateModelAsync(model, Prefix, m => m.Pattern, m => m.AllowCustomPath, m => m.AllowUpdatePath, m => m.ShowHomepageOption, m => m.AllowDisabled, m => m.AllowRouteContainedItems, m => m.ManageContainedItemRoutes, m => m.AllowAbsolutePath); if (!string.IsNullOrEmpty(model.Pattern) && !_templateManager.Validate(model.Pattern, out var errors)) { context.Updater.ModelState.AddModelError(nameof(model.Pattern), S["Pattern doesn't contain a valid Liquid expression. Details: {0}", string.Join(" ", errors)]); } else { context.Builder.WithSettings(new AutoroutePartSettings { Pattern = model.Pattern, AllowCustomPath = model.AllowCustomPath, AllowUpdatePath = model.AllowUpdatePath, ShowHomepageOption = model.ShowHomepageOption, AllowDisabled = model.AllowDisabled, AllowRouteContainedItems = model.AllowRouteContainedItems, ManageContainedItemRoutes = model.ManageContainedItemRoutes, AllowAbsolutePath = model.AllowAbsolutePath }); } return(Edit(contentTypePartDefinition, context.Updater)); }
public override async Task <IDisplayResult> UpdateAsync(LiquidPart model, IUpdateModel updater) { var viewModel = new LiquidPartViewModel(); if (await updater.TryUpdateModelAsync(viewModel, Prefix, t => t.Liquid)) { if (!string.IsNullOrEmpty(viewModel.Liquid) && !_liquidTemplatemanager.Validate(viewModel.Liquid, out var errors)) { updater.ModelState.AddModelError(Prefix, nameof(viewModel.Liquid), S["The Liquid Body doesn't contain a valid Liquid expression. Details: {0}", string.Join(" ", errors)]); } else { model.Liquid = viewModel.Liquid; } } return(Edit(model)); }
public override async Task <IDisplayResult> UpdateAsync(MarkdownField field, IUpdateModel updater, UpdateFieldEditorContext context) { var viewModel = new EditMarkdownFieldViewModel(); if (await updater.TryUpdateModelAsync(viewModel, Prefix, f => f.Markdown)) { if (!string.IsNullOrEmpty(viewModel.Markdown) && !_liquidTemplateManager.Validate(viewModel.Markdown, out var errors)) { var fieldName = context.PartFieldDefinition.DisplayName(); context.Updater.ModelState.AddModelError(nameof(field.Markdown), S["{0} field doesn't contain a valid Liquid expression. Details: {1}", fieldName, string.Join(" ", errors)]); } else { field.Markdown = viewModel.Markdown; } } return(Edit(field, context)); }
public override async Task <IDisplayResult> UpdateAsync(MarkdownBodyPart model, IUpdateModel updater, UpdatePartEditorContext context) { var viewModel = new MarkdownBodyPartViewModel(); if (await context.Updater.TryUpdateModelAsync(viewModel, Prefix, vm => vm.Markdown)) { if (!string.IsNullOrEmpty(viewModel.Markdown) && !_liquidTemplateManager.Validate(viewModel.Markdown, out var errors)) { var partName = context.TypePartDefinition.DisplayName(); updater.ModelState.AddModelError(Prefix, nameof(viewModel.Markdown), S["{0} doesn't contain a valid Liquid expression. Details: {1}", partName, string.Join(" ", errors)]); } else { model.Markdown = viewModel.Markdown; } } return(Edit(model, context)); }
public override async Task <IDisplayResult> UpdateAsync(HtmlField field, IUpdateModel updater, UpdateFieldEditorContext context) { var viewModel = new EditHtmlFieldViewModel(); var settings = context.PartFieldDefinition.GetSettings <HtmlFieldSettings>(); if (await updater.TryUpdateModelAsync(viewModel, Prefix, f => f.Html)) { if (!string.IsNullOrEmpty(viewModel.Html) && !_liquidTemplateManager.Validate(viewModel.Html, out var errors)) { var fieldName = context.PartFieldDefinition.DisplayName(); context.Updater.ModelState.AddModelError(Prefix, nameof(viewModel.Html), S["{0} doesn't contain a valid Liquid expression. Details: {1}", fieldName, string.Join(" ", errors)]); } else { field.Html = settings.SanitizeHtml ? _htmlSanitizerService.Sanitize(viewModel.Html) : viewModel.Html; } } return(Edit(field, context)); }
public override async Task <IDisplayResult> UpdateAsync(HtmlBodyPart model, IUpdateModel updater, UpdatePartEditorContext context) { var viewModel = new HtmlBodyPartViewModel(); var settings = context.TypePartDefinition.GetSettings <HtmlBodyPartSettings>(); if (await updater.TryUpdateModelAsync(viewModel, Prefix, t => t.Html)) { if (!string.IsNullOrEmpty(viewModel.Html) && !_liquidTemplateManager.Validate(viewModel.Html, out var errors)) { var partName = context.TypePartDefinition.DisplayName(); updater.ModelState.AddModelError(Prefix, nameof(viewModel.Html), S["{0} doesn't contain a valid Liquid expression. Details: {1}", partName, string.Join(" ", errors)]); } else { model.Html = settings.SanitizeHtml ? _htmlSanitizerService.Sanitize(viewModel.Html) : viewModel.Html; } } return(Edit(model, context)); }