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 RoleService : ServiceBase, IRoleService { private readonly HttpClient http; private readonly SiteState sitestate; private readonly IUriHelper urihelper; public RoleService(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(), "Role"); } } public async Task> GetRolesAsync() { List Roles = await http.GetJsonAsync>(apiurl); return Roles.OrderBy(item => item.Name).ToList(); } public async Task> GetRolesAsync(int SiteId) { List Roles = await http.GetJsonAsync>(apiurl + "?siteid=" + SiteId.ToString()); return Roles.OrderBy(item => item.Name).ToList(); } public async Task GetRoleAsync(int RoleId) { return await http.GetJsonAsync(apiurl + "/" + RoleId.ToString()); } public async Task AddRoleAsync(Role Role) { return await http.PostJsonAsync(apiurl, Role); } public async Task UpdateRoleAsync(Role Role) { return await http.PutJsonAsync(apiurl + "/" + Role.SiteId.ToString(), Role); } public async Task DeleteRoleAsync(int RoleId) { await http.DeleteAsync(apiurl + "/" + RoleId.ToString()); } } }