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();
///
/// Get all s
///
///
Task> GetSiteGroupsAsync(int primarySiteId);
///
/// Get one specific
///
/// ID-reference of a
///
Task GetSiteGroupAsync(int siteGroupId);
///
/// 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 siteGroupId);
}
[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()
{
return await GetSiteGroupsAsync(-1);
}
public async Task> GetSiteGroupsAsync(int primarySiteId)
{
return await GetJsonAsync>($"{Apiurl}?siteid={primarySiteId}", Enumerable.Empty().ToList());
}
public async Task GetSiteGroupAsync(int siteGroupId)
{
return await GetJsonAsync($"{Apiurl}/{siteGroupId}");
}
public async Task AddSiteGroupAsync(SiteGroup siteGroup)
{
return await PostJsonAsync(Apiurl, siteGroup);
}
public async Task UpdateSiteGroupAsync(SiteGroup siteGroup)
{
return await PutJsonAsync($"{Apiurl}/{siteGroup.SiteGroupId}", siteGroup);
}
public async Task DeleteSiteGroupAsync(int siteGroupId)
{
await DeleteAsync($"{Apiurl}/{siteGroupId}");
}
}
}