@using Microsoft.AspNetCore.Components.Routing
@using Oqtane.Modules
@using Oqtane.Modules.Controls
@using Oqtane.Modules.HtmlText.Services
@using Oqtane.Modules.HtmlText.Models
@using System.Net.Http;
@using Oqtane.Shared;
@namespace Oqtane.Modules.HtmlText
@inherits ModuleBase
@inject NavigationManager NavigationManager
@inject HttpClient http
@inject SiteState sitestate
Cancel
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Edit; } }
public override string Title { get { return "Edit Html/Text"; } }
string message = "";
string content;
string createdby;
DateTime createdon;
string modifiedby;
DateTime modifiedon;
protected override async Task OnInitializedAsync()
{
try
{
HtmlTextService htmltextservice = new HtmlTextService(http, sitestate, NavigationManager);
HtmlTextInfo htmltext = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId);
if (htmltext != null)
{
content = htmltext.Content;
createdby = htmltext.CreatedBy;
createdon = htmltext.CreatedOn;
modifiedby = htmltext.ModifiedBy;
modifiedon = htmltext.ModifiedOn;
}
}
catch (Exception ex)
{
message = ex.Message;
}
}
private async Task SaveContent()
{
try
{
HtmlTextService htmltextservice = new HtmlTextService(http, sitestate, NavigationManager);
HtmlTextInfo htmltext = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId);
if (htmltext != null)
{
htmltext.Content = content;
await htmltextservice.UpdateHtmlTextAsync(htmltext);
}
else
{
htmltext = new HtmlTextInfo();
htmltext.ModuleId = ModuleState.ModuleId;
htmltext.Content = content;
await htmltextservice.AddHtmlTextAsync(htmltext);
}
PageState.Reload = Constants.ReloadPage;
NavigationManager.NavigateTo(NavigateUrl());
}
catch (Exception ex)
{
message = ex.Message;
}
}
}