41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
using OrdersManagementDataModel.Dtos;
|
|
|
|
namespace OrdersManagement.Services;
|
|
|
|
public class RoleService(HttpClient httpClient)
|
|
{
|
|
public async Task<IEnumerable<RoleDto>?> GetRolesAsync()
|
|
{
|
|
return await httpClient.GetFromJsonAsync<IEnumerable<RoleDto>>("api/Roles");
|
|
}
|
|
|
|
public async Task<RoleDto?> GetRoleAsync(Guid roleId)
|
|
{
|
|
return await httpClient.GetFromJsonAsync<RoleDto>($"api/Roles/by-id/?id={roleId}");
|
|
}
|
|
|
|
public async Task<RoleDto?> GetRoleByNameAsync(string roleName)
|
|
{
|
|
return await httpClient.GetFromJsonAsync<RoleDto>($"api/Roles/by-name/?name={roleName}");
|
|
}
|
|
|
|
public async Task AddRoleAsync(RoleDto role)
|
|
{
|
|
await httpClient.PostAsJsonAsync("api/Roles", role);
|
|
}
|
|
|
|
public async Task UpdateRoleAsync(RoleDto role)
|
|
{
|
|
await httpClient.PutAsJsonAsync("api/Roles", role);
|
|
}
|
|
|
|
public async Task DeleteRoleAsync(Guid roleId)
|
|
{
|
|
await httpClient.DeleteAsync($"api/Roles/?id={roleId}");
|
|
}
|
|
|
|
// public async Task<IEnumerable<UserDto>?> GetUsersInRoleAsync(Guid roleId)
|
|
// {
|
|
// return await httpClient.GetFromJsonAsync<IEnumerable<UserDto>>($"api/Roles/{roleId}/Users");
|
|
// }
|
|
} |