@using Oqtane.Modules.HtmlText.Services @using Oqtane.Modules.HtmlText.Models @using Oqtane.Modules.Controls @namespace Oqtane.Modules.HtmlText @inherits ModuleBase @inject IHtmlTextService HtmlTextService @inject ISettingService SettingService @inject NavigationManager NavigationManager @inject IStringLocalizer Localizer @inject IStringLocalizer SharedLocalizer @if (_content != null) {
@SharedLocalizer["Cancel"] @if (!string.IsNullOrEmpty(_content)) {

} }
      @SharedLocalizer["CreatedOn"] @SharedLocalizer["CreatedBy"]
@context.CreatedOn @context.CreatedBy
@((MarkupString)_view)
@code { public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Edit; public override string Title => "Edit Html/Text"; private RichTextEditor RichTextEditorHtml; private string _content = null; private string _createdby; private DateTime _createdon; private string _modifiedby; private DateTime _modifiedon; private List _htmltexts; private string _view = ""; protected override async Task OnInitializedAsync() { try { await LoadContent(); } catch (Exception ex) { await logger.LogError(ex, "Error Loading Content {Error}", ex.Message); AddModuleMessage(Localizer["Error.Content.Load"], MessageType.Error); } } private async Task LoadContent() { var htmltext = await HtmlTextService.GetHtmlTextAsync(ModuleState.ModuleId); if (htmltext != null) { _content = htmltext.Content; _content = Utilities.FormatContent(_content, PageState.Alias, "render"); _createdby = htmltext.CreatedBy; _createdon = htmltext.CreatedOn; _modifiedby = htmltext.ModifiedBy; _modifiedon = htmltext.ModifiedOn; } else { _content = string.Empty; } _htmltexts = await HtmlTextService.GetHtmlTextsAsync(ModuleState.ModuleId); _htmltexts = _htmltexts.OrderByDescending(item => item.CreatedOn).ToList(); _view = ""; } private async Task SaveContent() { string content = await RichTextEditorHtml.GetHtml(); content = Utilities.FormatContent(content, PageState.Alias, "save"); try { var htmltext = new HtmlText(); htmltext.ModuleId = ModuleState.ModuleId; htmltext.Content = content; await HtmlTextService.AddHtmlTextAsync(htmltext); await logger.LogInformation("Content Saved {HtmlText}", htmltext); NavigationManager.NavigateTo(NavigateUrl()); } catch (Exception ex) { await logger.LogError(ex, "Error Saving Content {Error}", ex.Message); AddModuleMessage(Localizer["Error.Content.Save"], MessageType.Error); } } private async Task View(Models.HtmlText htmltext) { try { htmltext = await HtmlTextService.GetHtmlTextAsync(htmltext.HtmlTextId, htmltext.ModuleId); if (htmltext != null) { _view = htmltext.Content; _view = Utilities.FormatContent(_view, PageState.Alias, "render"); StateHasChanged(); } } catch (Exception ex) { await logger.LogError(ex, "Error Viewing Content {Error}", ex.Message); AddModuleMessage(Localizer["Error.Content.View"], MessageType.Error); } } private async Task Restore(Models.HtmlText htmltext) { try { htmltext = await HtmlTextService.GetHtmlTextAsync(htmltext.HtmlTextId, ModuleState.ModuleId); if (htmltext != null) { var content = htmltext.Content; htmltext = new HtmlText(); htmltext.ModuleId = ModuleState.ModuleId; htmltext.Content = content; await HtmlTextService.AddHtmlTextAsync(htmltext); await logger.LogInformation("Content Restored {HtmlText}", htmltext); AddModuleMessage(Localizer["Message.Content.Restored"], MessageType.Success); await LoadContent(); StateHasChanged(); } } catch (Exception ex) { await logger.LogError(ex, "Error Restoring Content {Error}", ex.Message); AddModuleMessage(Localizer["Error.Content.Restore"], MessageType.Error); } } private async Task Delete(Models.HtmlText htmltext) { try { htmltext = await HtmlTextService.GetHtmlTextAsync(htmltext.HtmlTextId, ModuleState.ModuleId); if (htmltext != null) { await HtmlTextService.DeleteHtmlTextAsync(htmltext.HtmlTextId, htmltext.ModuleId); await logger.LogInformation("Content Deleted {HtmlText}", htmltext); AddModuleMessage(Localizer["Message.Content.Deleted"], MessageType.Success); await LoadContent(); StateHasChanged(); } } catch (Exception ex) { await logger.LogError(ex, "Error Deleting Content {Error}", ex.Message); AddModuleMessage(Localizer["Error.Content.Delete"], MessageType.Error); } } }