using Oqtane.Models; using System.Threading.Tasks; using System.Net.Http; using System.Linq; using Microsoft.AspNetCore.Components; using System.Collections.Generic; using Oqtane.Shared; namespace Oqtane.Services { public class ProfileService : ServiceBase, IProfileService { private readonly HttpClient http; private readonly SiteState sitestate; private readonly IUriHelper urihelper; public ProfileService(HttpClient http, SiteState sitestate, IUriHelper urihelper) { this.http = http; this.sitestate = sitestate; this.urihelper = urihelper; } private string apiurl { get { return CreateApiUrl(sitestate.Alias, urihelper.GetAbsoluteUri(), "Profile"); } } public async Task> GetProfilesAsync() { return await http.GetJsonAsync>(apiurl); } public async Task> GetProfilesAsync(int SiteId) { List Profiles = await http.GetJsonAsync>(apiurl + "?siteid=" + SiteId.ToString()); return Profiles.OrderBy(item => item.ViewOrder).ToList(); } public async Task GetProfileAsync(int ProfileId) { return await http.GetJsonAsync(apiurl + "/" + ProfileId.ToString()); } public async Task AddProfileAsync(Profile Profile) { return await http.PostJsonAsync(apiurl, Profile); } public async Task UpdateProfileAsync(Profile Profile) { return await http.PutJsonAsync(apiurl + "/" + Profile.SiteId.ToString(), Profile); } public async Task DeleteProfileAsync(int ProfileId) { await http.DeleteAsync(apiurl + "/" + ProfileId.ToString()); } } }