using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Threading.Tasks; using Oqtane.Services; using Oqtane.Shared; namespace Oqtane.Modules.HtmlText.Services { public class HtmlTextService : ServiceBase, IHtmlTextService, IService { private readonly SiteState _siteState; public HtmlTextService(HttpClient http, SiteState siteState) : base(http) { _siteState = siteState; } private string ApiUrl => CreateApiUrl("HtmlText", _siteState.Alias); public async Task GetHtmlTextAsync(int moduleId) { var htmltext = await GetJsonAsync>(CreateAuthorizationPolicyUrl($"{ApiUrl}/{moduleId}", new Dictionary() { { EntityNames.Module, moduleId } })); return htmltext.FirstOrDefault(); } public async Task AddHtmlTextAsync(Models.HtmlText htmlText) { await PostJsonAsync(CreateAuthorizationPolicyUrl($"{ApiUrl}", new Dictionary() { { EntityNames.Module, htmlText.ModuleId } }), htmlText); } public async Task UpdateHtmlTextAsync(Models.HtmlText htmlText) { await PutJsonAsync(CreateAuthorizationPolicyUrl($"{ApiUrl}/{htmlText.HtmlTextId}", new Dictionary() { { EntityNames.Module, htmlText.ModuleId } }), htmlText); } public async Task DeleteHtmlTextAsync(int moduleId) { await DeleteAsync(CreateAuthorizationPolicyUrl($"{ApiUrl}/{moduleId}", new Dictionary() { { EntityNames.Module, moduleId } })); } } }