using Oqtane.Models; using System.Threading.Tasks; using System.Net.Http; using System.Collections.Generic; using Oqtane.Shared; using System.Net; using Oqtane.Documentation; namespace Oqtane.Services { [PrivateApi("Don't show in the documentation, as everything should use the Interface")] public class PageService : ServiceBase, IPageService { public PageService(HttpClient http, SiteState siteState) : base(http, siteState) { } private string Apiurl => CreateApiUrl("Page"); public async Task> GetPagesAsync(int siteId) { return await GetJsonAsync>($"{Apiurl}?siteid={siteId}"); } public async Task GetPageAsync(int pageId) { return await GetJsonAsync($"{Apiurl}/{pageId}"); } public async Task GetPageAsync(string path, int siteId) { try { return await GetJsonAsync($"{Apiurl}/path/{siteId}?path={WebUtility.UrlEncode(path)}"); } catch { return null; } } public async Task AddPageAsync(Page page) { return await PostJsonAsync(Apiurl, page); } public async Task AddPageAsync(int pageId, int userId) { return await PostJsonAsync($"{Apiurl}/{pageId}?userid={userId}", null); } public async Task UpdatePageAsync(Page page) { return await PutJsonAsync($"{Apiurl}/{page.PageId}", page); } public async Task UpdatePageOrderAsync(int siteId, int pageId, int? parentId) { var parent = parentId == null ? string.Empty : parentId.ToString(); await PutAsync($"{Apiurl}/?siteid={siteId}&pageid={pageId}&parentid={parent}"); } public async Task DeletePageAsync(int pageId) { await DeleteAsync($"{Apiurl}/{pageId}"); } } }