Merge pull request #57 from sbwalker/master
Improve HtmlText module performance
This commit is contained in:
		@ -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<HtmlTextInfo> 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;
 | 
			
		||||
 | 
			
		||||
@ -19,10 +19,10 @@
 | 
			
		||||
    protected override async Task OnParametersSetAsync()
 | 
			
		||||
    {
 | 
			
		||||
        HtmlTextService htmltextservice = new HtmlTextService(http, sitestate, UriHelper);
 | 
			
		||||
        List<HtmlTextInfo> htmltext = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId);
 | 
			
		||||
        HtmlTextInfo htmltext = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId);
 | 
			
		||||
        if (htmltext != null)
 | 
			
		||||
        {
 | 
			
		||||
            content = htmltext.FirstOrDefault().Content;
 | 
			
		||||
            content = htmltext.Content;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -27,13 +27,9 @@ namespace Oqtane.Client.Modules.HtmlText.Services
 | 
			
		||||
            get { return CreateApiUrl(sitestate.Alias, urihelper.GetAbsoluteUri(), "HtmlText"); }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public async Task<List<HtmlTextInfo>> GetHtmlTextAsync(int ModuleId)
 | 
			
		||||
        public async Task<HtmlTextInfo> GetHtmlTextAsync(int ModuleId)
 | 
			
		||||
        {
 | 
			
		||||
            List<HtmlTextInfo> htmltext = await http.GetJsonAsync<List<HtmlTextInfo>>(apiurl);
 | 
			
		||||
            htmltext = htmltext
 | 
			
		||||
                .Where(item => item.ModuleId == ModuleId)
 | 
			
		||||
                .ToList();
 | 
			
		||||
            return htmltext;
 | 
			
		||||
            return await http.GetJsonAsync<HtmlTextInfo>(apiurl + "/" + ModuleId.ToString());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public async Task AddHtmlTextAsync(HtmlTextInfo htmltext)
 | 
			
		||||
 | 
			
		||||
@ -6,7 +6,7 @@ namespace Oqtane.Client.Modules.HtmlText.Services
 | 
			
		||||
{
 | 
			
		||||
    public interface IHtmlTextService 
 | 
			
		||||
    {
 | 
			
		||||
        Task<List<HtmlTextInfo>> GetHtmlTextAsync(int ModuleId);
 | 
			
		||||
        Task<HtmlTextInfo> GetHtmlTextAsync(int ModuleId);
 | 
			
		||||
 | 
			
		||||
        Task AddHtmlTextAsync(HtmlTextInfo htmltext);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -6,6 +6,22 @@ namespace Oqtane.Services
 | 
			
		||||
{
 | 
			
		||||
    public interface ISettingService
 | 
			
		||||
    {
 | 
			
		||||
        Task<List<Setting>> GetHostSettingsAsync();
 | 
			
		||||
 | 
			
		||||
        Task<Setting> UpdateHostSettingsAsync(List<Setting> HostSettings, string SettingName, string SettingValue);
 | 
			
		||||
 | 
			
		||||
        Task<List<Setting>> GetSiteSettingsAsync(int SiteId);
 | 
			
		||||
 | 
			
		||||
        Task<Setting> UpdateSiteSettingsAsync(List<Setting> SiteSettings, int SiteId, string SettingName, string SettingValue);
 | 
			
		||||
 | 
			
		||||
        Task<List<Setting>> GetPageSettingsAsync(int PageId);
 | 
			
		||||
 | 
			
		||||
        Task<Setting> UpdatePageSettingsAsync(List<Setting> PageSettings, int PageId, string SettingName, string SettingValue);
 | 
			
		||||
 | 
			
		||||
        Task<List<Setting>> GetPageModuleSettingsAsync(int PageModuleId);
 | 
			
		||||
 | 
			
		||||
        Task<Setting> UpdatePageModuleSettingsAsync(List<Setting> PageModuleSettings, int PageModuleId, string SettingName, string SettingValue);
 | 
			
		||||
 | 
			
		||||
        Task<List<Setting>> GetModuleSettingsAsync(int ModuleId);
 | 
			
		||||
 | 
			
		||||
        Task<Setting> UpdateModuleSettingsAsync(List<Setting> ModuleSettings, int ModuleId, string SettingName, string SettingValue);
 | 
			
		||||
 | 
			
		||||
@ -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<List<Setting>> GetHostSettingsAsync()
 | 
			
		||||
        {
 | 
			
		||||
            return await GetSettingsAsync("Host", -1);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public async Task<Setting> UpdateHostSettingsAsync(List<Setting> 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<List<Setting>> GetSiteSettingsAsync(int SiteId)
 | 
			
		||||
        {
 | 
			
		||||
            return await GetSettingsAsync("Site", SiteId);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public async Task<Setting> UpdateSiteSettingsAsync(List<Setting> 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<List<Setting>> GetPageSettingsAsync(int PageId)
 | 
			
		||||
        {
 | 
			
		||||
            return await GetSettingsAsync("Page", PageId);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public async Task<Setting> UpdatePageSettingsAsync(List<Setting> 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<List<Setting>> GetPageModuleSettingsAsync(int PageModuleId)
 | 
			
		||||
        {
 | 
			
		||||
            return await GetSettingsAsync("PageModule", PageModuleId);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public async Task<Setting> UpdatePageModuleSettingsAsync(List<Setting> 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<List<Setting>> GetModuleSettingsAsync(int ModuleId)
 | 
			
		||||
        {
 | 
			
		||||
            return await GetSettingsAsync("Module", ModuleId);
 | 
			
		||||
 | 
			
		||||
@ -15,13 +15,6 @@ namespace Oqtane.Server.Modules.HtmlText.Controllers
 | 
			
		||||
            htmltext = HtmlText;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // GET: api/<controller>
 | 
			
		||||
        [HttpGet]
 | 
			
		||||
        public IEnumerable<HtmlTextInfo> Get()
 | 
			
		||||
        {
 | 
			
		||||
            return htmltext.GetHtmlText();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // GET api/<controller>/5
 | 
			
		||||
        [HttpGet("{id}")]
 | 
			
		||||
        public HtmlTextInfo Get(int id)
 | 
			
		||||
 | 
			
		||||
@ -15,11 +15,11 @@ namespace Oqtane.Server.Modules.HtmlText.Repository
 | 
			
		||||
            db = context;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public IEnumerable<HtmlTextInfo> 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
 | 
			
		||||
 | 
			
		||||
@ -5,10 +5,9 @@ namespace Oqtane.Server.Modules.HtmlText.Repository
 | 
			
		||||
{
 | 
			
		||||
    public interface IHtmlTextRepository
 | 
			
		||||
    {
 | 
			
		||||
        IEnumerable<HtmlTextInfo> GetHtmlText();
 | 
			
		||||
        HtmlTextInfo GetHtmlText(int ModuleId);
 | 
			
		||||
        HtmlTextInfo AddHtmlText(HtmlTextInfo HtmlText);
 | 
			
		||||
        HtmlTextInfo UpdateHtmlText(HtmlTextInfo HtmlText);
 | 
			
		||||
        HtmlTextInfo GetHtmlText(int HtmlTextIdId);
 | 
			
		||||
        void DeleteHtmlText(int HtmlTextId);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user