using Oqtane.Models;
using System.Threading.Tasks;
using System.Net.Http;
using System.Linq;
using System.Collections.Generic;
using Oqtane.Documentation;
using Oqtane.Shared;
namespace Oqtane.Services
{
///
/// Service to store and retrieve entries
///
public interface IProfileService
{
///
/// Returns a list of profile entries
///
///
///
Task> GetProfilesAsync(int siteId);
///
/// Returns a specific profile entry
///
///
///
Task GetProfileAsync(int profileId);
///
/// Creates a new profile entry
///
///
///
Task AddProfileAsync(Profile profile);
///
/// Updates an existing profile entry
///
///
///
Task UpdateProfileAsync(Profile profile);
///
/// Deletes a profile entry
///
///
///
Task DeleteProfileAsync(int profileId);
}
[PrivateApi("Don't show in the documentation, as everything should use the Interface")]
public class ProfileService : ServiceBase, IProfileService
{
public ProfileService(HttpClient http, SiteState siteState) : base(http, siteState) { }
private string Apiurl => CreateApiUrl("Profile");
public async Task> GetProfilesAsync(int siteId)
{
List profiles = await GetJsonAsync>($"{Apiurl}?siteid={siteId}");
return profiles.OrderBy(item => item.ViewOrder).ToList();
}
public async Task GetProfileAsync(int profileId)
{
return await GetJsonAsync($"{Apiurl}/{profileId}");
}
public async Task AddProfileAsync(Profile profile)
{
return await PostJsonAsync(Apiurl, profile);
}
public async Task UpdateProfileAsync(Profile profile)
{
return await PutJsonAsync($"{Apiurl}/{profile.ProfileId}", profile);
}
public async Task DeleteProfileAsync(int profileId)
{
await DeleteAsync($"{Apiurl}/{profileId}");
}
}
}