implement client and server service implementations in Html/Text module

This commit is contained in:
sbwalker
2024-03-05 08:44:09 -05:00
parent 7d7ea4c34b
commit 74952cf62d
11 changed files with 214 additions and 30 deletions

View File

@ -4,6 +4,8 @@ using System.Collections.Generic;
using Microsoft.Extensions.Caching.Memory;
using Oqtane.Infrastructure;
using System;
using Microsoft.EntityFrameworkCore;
using System.Threading.Tasks;
namespace Oqtane.Modules.HtmlText.Repository
{
@ -51,6 +53,36 @@ namespace Oqtane.Modules.HtmlText.Repository
_db.SaveChanges();
}
public async Task<IEnumerable<Models.HtmlText>> GetHtmlTextsAsync(int moduleId)
{
return await _cache.GetOrCreateAsync($"HtmlText:{_siteState.Alias.SiteKey}:{moduleId}", async entry =>
{
entry.SlidingExpiration = TimeSpan.FromMinutes(30);
return await _db.HtmlText.Where(item => item.ModuleId == moduleId).ToListAsync();
});
}
public async Task<Models.HtmlText> GetHtmlTextAsync(int htmlTextId)
{
return await _db.HtmlText.FindAsync(htmlTextId);
}
public async Task<Models.HtmlText> AddHtmlTextAsync(Models.HtmlText htmlText)
{
_db.HtmlText.Add(htmlText);
await _db.SaveChangesAsync();
ClearCache(htmlText.ModuleId);
return htmlText;
}
public async Task DeleteHtmlTextAsync(int htmlTextId)
{
Models.HtmlText htmlText = _db.HtmlText.FirstOrDefault(item => item.HtmlTextId == htmlTextId);
_db.HtmlText.Remove(htmlText);
ClearCache(htmlText.ModuleId);
await _db.SaveChangesAsync();
}
private void ClearCache(int moduleId)
{
_cache.Remove($"HtmlText:{_siteState.Alias.SiteKey}:{moduleId}");

View File

@ -1,6 +1,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Oqtane.Documentation;
using Oqtane.Modules.HtmlText.Models;
namespace Oqtane.Modules.HtmlText.Repository
{
@ -11,5 +11,10 @@ namespace Oqtane.Modules.HtmlText.Repository
Models.HtmlText GetHtmlText(int htmlTextId);
Models.HtmlText AddHtmlText(Models.HtmlText htmlText);
void DeleteHtmlText(int htmlTextId);
Task<IEnumerable<Models.HtmlText>> GetHtmlTextsAsync(int moduleId);
Task<Models.HtmlText> GetHtmlTextAsync(int htmlTextId);
Task<Models.HtmlText> AddHtmlTextAsync(Models.HtmlText htmlText);
Task DeleteHtmlTextAsync(int htmlTextId);
}
}