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 NavigationManager _navigationManager; public ProfileService(HttpClient http, SiteState sitestate, NavigationManager NavigationManager) { this._http = http; this._siteState = sitestate; this._navigationManager = NavigationManager; } private string apiurl { get { return CreateApiUrl(_siteState.Alias, _navigationManager.Uri, "Profile"); } } 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()); } } }