diff --git a/Oqtane.Client/Modules/HtmlText/Edit.razor b/Oqtane.Client/Modules/HtmlText/Edit.razor index 591c436d..3bc2812a 100644 --- a/Oqtane.Client/Modules/HtmlText/Edit.razor +++ b/Oqtane.Client/Modules/HtmlText/Edit.razor @@ -28,16 +28,14 @@ public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Edit; } } public override string Title { get { return "Edit Html/Text"; } } - HtmlTextInfo htmltext; string content; protected override async Task OnInitializedAsync() { HtmlTextService htmltextservice = new HtmlTextService(http, sitestate, UriHelper); - List htmltextlist = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId); - if (htmltextlist != null) + HtmlTextInfo htmltext = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId); + if (htmltext != null) { - htmltext = htmltextlist.FirstOrDefault(); content = htmltext.Content; } } @@ -45,6 +43,7 @@ private async Task SaveContent() { HtmlTextService htmltextservice = new HtmlTextService(http, sitestate, UriHelper); + HtmlTextInfo htmltext = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId); if (htmltext != null) { htmltext.Content = content; diff --git a/Oqtane.Client/Modules/HtmlText/Index.razor b/Oqtane.Client/Modules/HtmlText/Index.razor index e39d1148..d172eacd 100644 --- a/Oqtane.Client/Modules/HtmlText/Index.razor +++ b/Oqtane.Client/Modules/HtmlText/Index.razor @@ -19,10 +19,10 @@ protected override async Task OnParametersSetAsync() { HtmlTextService htmltextservice = new HtmlTextService(http, sitestate, UriHelper); - List htmltext = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId); + HtmlTextInfo htmltext = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId); if (htmltext != null) { - content = htmltext.FirstOrDefault().Content; + content = htmltext.Content; } } } \ No newline at end of file diff --git a/Oqtane.Client/Modules/HtmlText/Services/HtmlTextService.cs b/Oqtane.Client/Modules/HtmlText/Services/HtmlTextService.cs index e8257b00..aca530af 100644 --- a/Oqtane.Client/Modules/HtmlText/Services/HtmlTextService.cs +++ b/Oqtane.Client/Modules/HtmlText/Services/HtmlTextService.cs @@ -27,13 +27,9 @@ namespace Oqtane.Client.Modules.HtmlText.Services get { return CreateApiUrl(sitestate.Alias, urihelper.GetAbsoluteUri(), "HtmlText"); } } - public async Task> GetHtmlTextAsync(int ModuleId) + public async Task GetHtmlTextAsync(int ModuleId) { - List htmltext = await http.GetJsonAsync>(apiurl); - htmltext = htmltext - .Where(item => item.ModuleId == ModuleId) - .ToList(); - return htmltext; + return await http.GetJsonAsync(apiurl + "/" + ModuleId.ToString()); } public async Task AddHtmlTextAsync(HtmlTextInfo htmltext) diff --git a/Oqtane.Client/Modules/HtmlText/Services/IHtmlTextService.cs b/Oqtane.Client/Modules/HtmlText/Services/IHtmlTextService.cs index c0dcc46c..9d3bfa98 100644 --- a/Oqtane.Client/Modules/HtmlText/Services/IHtmlTextService.cs +++ b/Oqtane.Client/Modules/HtmlText/Services/IHtmlTextService.cs @@ -6,7 +6,7 @@ namespace Oqtane.Client.Modules.HtmlText.Services { public interface IHtmlTextService { - Task> GetHtmlTextAsync(int ModuleId); + Task GetHtmlTextAsync(int ModuleId); Task AddHtmlTextAsync(HtmlTextInfo htmltext); diff --git a/Oqtane.Client/Services/Interfaces/ISettingService.cs b/Oqtane.Client/Services/Interfaces/ISettingService.cs index aa9834fd..c6b617c5 100644 --- a/Oqtane.Client/Services/Interfaces/ISettingService.cs +++ b/Oqtane.Client/Services/Interfaces/ISettingService.cs @@ -6,6 +6,22 @@ namespace Oqtane.Services { public interface ISettingService { + Task> GetHostSettingsAsync(); + + Task UpdateHostSettingsAsync(List HostSettings, string SettingName, string SettingValue); + + Task> GetSiteSettingsAsync(int SiteId); + + Task UpdateSiteSettingsAsync(List SiteSettings, int SiteId, string SettingName, string SettingValue); + + Task> GetPageSettingsAsync(int PageId); + + Task UpdatePageSettingsAsync(List PageSettings, int PageId, string SettingName, string SettingValue); + + Task> GetPageModuleSettingsAsync(int PageModuleId); + + Task UpdatePageModuleSettingsAsync(List PageModuleSettings, int PageModuleId, string SettingName, string SettingValue); + Task> GetModuleSettingsAsync(int ModuleId); Task UpdateModuleSettingsAsync(List ModuleSettings, int ModuleId, string SettingName, string SettingValue); diff --git a/Oqtane.Client/Services/SettingService.cs b/Oqtane.Client/Services/SettingService.cs index cea5f994..f6bfaac2 100644 --- a/Oqtane.Client/Services/SettingService.cs +++ b/Oqtane.Client/Services/SettingService.cs @@ -5,7 +5,6 @@ using System.Linq; using Microsoft.AspNetCore.Components; using System.Collections.Generic; using Oqtane.Shared; -using System; namespace Oqtane.Services { @@ -27,6 +26,106 @@ namespace Oqtane.Services get { return CreateApiUrl(sitestate.Alias, urihelper.GetAbsoluteUri(), "Setting"); } } + public async Task> GetHostSettingsAsync() + { + return await GetSettingsAsync("Host", -1); + } + + public async Task UpdateHostSettingsAsync(List HostSettings, string SettingName, string SettingValue) + { + Setting setting = HostSettings.Where(item => item.SettingName == SettingName).FirstOrDefault(); + if (setting == null) + { + setting = new Setting(); + setting.EntityName = "Host"; + setting.EntityId = -1; + setting.SettingName = SettingName; + setting.SettingValue = SettingValue; + setting = await AddSettingAsync(setting); + } + else + { + setting.SettingValue = SettingValue; + setting = await UpdateSettingAsync(setting); + } + return setting; + } + + public async Task> GetSiteSettingsAsync(int SiteId) + { + return await GetSettingsAsync("Site", SiteId); + } + + public async Task UpdateSiteSettingsAsync(List SiteSettings, int SiteId, string SettingName, string SettingValue) + { + Setting setting = SiteSettings.Where(item => item.SettingName == SettingName).FirstOrDefault(); + if (setting == null) + { + setting = new Setting(); + setting.EntityName = "Site"; + setting.EntityId = SiteId; + setting.SettingName = SettingName; + setting.SettingValue = SettingValue; + setting = await AddSettingAsync(setting); + } + else + { + setting.SettingValue = SettingValue; + setting = await UpdateSettingAsync(setting); + } + return setting; + } + + public async Task> GetPageSettingsAsync(int PageId) + { + return await GetSettingsAsync("Page", PageId); + } + + public async Task UpdatePageSettingsAsync(List PageSettings, int PageId, string SettingName, string SettingValue) + { + Setting setting = PageSettings.Where(item => item.SettingName == SettingName).FirstOrDefault(); + if (setting == null) + { + setting = new Setting(); + setting.EntityName = "Page"; + setting.EntityId = PageId; + setting.SettingName = SettingName; + setting.SettingValue = SettingValue; + setting = await AddSettingAsync(setting); + } + else + { + setting.SettingValue = SettingValue; + setting = await UpdateSettingAsync(setting); + } + return setting; + } + + public async Task> GetPageModuleSettingsAsync(int PageModuleId) + { + return await GetSettingsAsync("PageModule", PageModuleId); + } + + public async Task UpdatePageModuleSettingsAsync(List PageModuleSettings, int PageModuleId, string SettingName, string SettingValue) + { + Setting setting = PageModuleSettings.Where(item => item.SettingName == SettingName).FirstOrDefault(); + if (setting == null) + { + setting = new Setting(); + setting.EntityName = "PageModule"; + setting.EntityId = PageModuleId; + setting.SettingName = SettingName; + setting.SettingValue = SettingValue; + setting = await AddSettingAsync(setting); + } + else + { + setting.SettingValue = SettingValue; + setting = await UpdateSettingAsync(setting); + } + return setting; + } + public async Task> GetModuleSettingsAsync(int ModuleId) { return await GetSettingsAsync("Module", ModuleId); diff --git a/Oqtane.Server/Modules/HtmlText/Controllers/HtmlTextController.cs b/Oqtane.Server/Modules/HtmlText/Controllers/HtmlTextController.cs index f3dc2d9b..695e460b 100644 --- a/Oqtane.Server/Modules/HtmlText/Controllers/HtmlTextController.cs +++ b/Oqtane.Server/Modules/HtmlText/Controllers/HtmlTextController.cs @@ -15,13 +15,6 @@ namespace Oqtane.Server.Modules.HtmlText.Controllers htmltext = HtmlText; } - // GET: api/ - [HttpGet] - public IEnumerable Get() - { - return htmltext.GetHtmlText(); - } - // GET api//5 [HttpGet("{id}")] public HtmlTextInfo Get(int id) diff --git a/Oqtane.Server/Modules/HtmlText/Repository/HtmlTextRepository.cs b/Oqtane.Server/Modules/HtmlText/Repository/HtmlTextRepository.cs index 2347e601..fc80ddfc 100644 --- a/Oqtane.Server/Modules/HtmlText/Repository/HtmlTextRepository.cs +++ b/Oqtane.Server/Modules/HtmlText/Repository/HtmlTextRepository.cs @@ -15,11 +15,11 @@ namespace Oqtane.Server.Modules.HtmlText.Repository db = context; } - public IEnumerable GetHtmlText() + public HtmlTextInfo GetHtmlText(int ModuleId) { try { - return db.HtmlText.ToList(); + return db.HtmlText.Where(item => item.ModuleId == ModuleId).FirstOrDefault(); } catch { @@ -27,6 +27,7 @@ namespace Oqtane.Server.Modules.HtmlText.Repository } } + public HtmlTextInfo AddHtmlText(HtmlTextInfo HtmlText) { try @@ -55,19 +56,6 @@ namespace Oqtane.Server.Modules.HtmlText.Repository } } - public HtmlTextInfo GetHtmlText(int HtmlTextId) - { - try - { - HtmlTextInfo HtmlText = db.HtmlText.Find(HtmlTextId); - return HtmlText; - } - catch - { - throw; - } - } - public void DeleteHtmlText(int HtmlTextId) { try diff --git a/Oqtane.Server/Modules/HtmlText/Repository/IHtmlTextRepository.cs b/Oqtane.Server/Modules/HtmlText/Repository/IHtmlTextRepository.cs index 463d5e50..cd7ea0e8 100644 --- a/Oqtane.Server/Modules/HtmlText/Repository/IHtmlTextRepository.cs +++ b/Oqtane.Server/Modules/HtmlText/Repository/IHtmlTextRepository.cs @@ -5,10 +5,9 @@ namespace Oqtane.Server.Modules.HtmlText.Repository { public interface IHtmlTextRepository { - IEnumerable GetHtmlText(); + HtmlTextInfo GetHtmlText(int ModuleId); HtmlTextInfo AddHtmlText(HtmlTextInfo HtmlText); HtmlTextInfo UpdateHtmlText(HtmlTextInfo HtmlText); - HtmlTextInfo GetHtmlText(int HtmlTextIdId); void DeleteHtmlText(int HtmlTextId); } }