using Oqtane.Models; using System.Threading.Tasks; using System.Net.Http; using System.Collections.Generic; using Oqtane.Documentation; using Oqtane.Shared; using System.Linq; namespace Oqtane.Services { /// /// Service to manage s on a /// public interface ISiteGroupService { /// /// Get all s /// /// Task> GetSiteGroupsAsync(int siteId, int siteGroupDefinitionId); /// /// Get one specific /// /// ID-reference of a /// Task GetSiteGroupAsync(int siteSiteGroupDefinitionId); /// /// Get one specific /// /// ID-reference of a /// ID-reference of a /// Task GetSiteGroupAsync(int siteId, int siteGroupDefinitionId); /// /// Add / save a new to the database. /// /// /// Task AddSiteGroupAsync(SiteGroup siteGroup); /// /// Update a in the database. /// /// /// Task UpdateSiteGroupAsync(SiteGroup siteGroup); /// /// Delete a in the database. /// /// ID-reference of a /// Task DeleteSiteGroupAsync(int siteSiteGroupDefinitionId); } [PrivateApi("Don't show in the documentation, as everything should use the Interface")] public class SiteGroupService : ServiceBase, ISiteGroupService { public SiteGroupService(HttpClient http, SiteState siteState) : base(http, siteState) { } private string Apiurl => CreateApiUrl("SiteGroup"); public async Task> GetSiteGroupsAsync(int siteId, int siteGroupDefinitionId) { return await GetJsonAsync>($"{Apiurl}?siteid={siteId}&groupid={siteGroupDefinitionId}", Enumerable.Empty().ToList()); } public async Task GetSiteGroupAsync(int siteSiteGroupDefinitionId) { return await GetJsonAsync($"{Apiurl}/{siteSiteGroupDefinitionId}"); } public async Task GetSiteGroupAsync(int siteId, int siteGroupDefinitionId) { var siteGroups = await GetSiteGroupsAsync(siteId, siteGroupDefinitionId); if (siteGroups != null && siteGroups.Count > 0) { return siteGroups[0]; } else { return null; } } public async Task AddSiteGroupAsync(SiteGroup siteGroup) { return await PostJsonAsync(Apiurl, siteGroup); } public async Task UpdateSiteGroupAsync(SiteGroup siteGroup) { return await PutJsonAsync($"{Apiurl}/{siteGroup.SiteGroupDefinitionId}", siteGroup); } public async Task DeleteSiteGroupAsync(int siteSiteGroupDefinitionId) { await DeleteAsync($"{Apiurl}/{siteSiteGroupDefinitionId}"); } } }