using Oqtane.Models; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNetCore.Components; using Oqtane.Shared; using System.Collections.Generic; using System.Linq; using Oqtane.Services.Interfaces; namespace Oqtane.Services { public class TenantService : ServiceBase, ITenantService { private readonly HttpClient _http; private readonly SiteState _siteState; private readonly NavigationManager _navigationManager; public TenantService(HttpClient http, SiteState siteState, NavigationManager navigationManager) { _http = http; _siteState = siteState; _navigationManager = navigationManager; } private string Apiurl { get { return CreateApiUrl(_siteState.Alias, _navigationManager.Uri, "Tenant"); } } public async Task> GetTenantsAsync() { List tenants = await _http.GetJsonAsync>(Apiurl); return tenants.OrderBy(item => item.Name).ToList(); } public async Task GetTenantAsync(int tenantId) { return await _http.GetJsonAsync($"{Apiurl}/{tenantId.ToString()}"); } public async Task AddTenantAsync(Tenant tenant) { return await _http.PostJsonAsync(Apiurl, tenant); } public async Task UpdateTenantAsync(Tenant tenant) { return await _http.PutJsonAsync($"{Apiurl}/{tenant.TenantId.ToString()}", tenant); } public async Task DeleteTenantAsync(int tenantId) { await _http.DeleteAsync($"{Apiurl}/{tenantId.ToString()}"); } } }