59 lines
1.6 KiB
C#
59 lines
1.6 KiB
C#
using System;
|
|
using xIdentityHelper;
|
|
using System.Threading;
|
|
using xCommons.Extensions;
|
|
using xIdentityModels.Dtos;
|
|
using xExceptions.Constants;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
namespace xIds.Controllers
|
|
{
|
|
public partial class AuthorizationController
|
|
{
|
|
/// <summary>
|
|
/// Retrieve Specified Role By Id ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("Roles/{id}")]
|
|
[Authorize(Policy = XPolicies.EnabledAdmin)]
|
|
public virtual async Task<ActionResult<XRoleDefinitionDto>> Get(
|
|
[FromRoute] int id,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
try
|
|
{
|
|
//
|
|
// Validate ...
|
|
if (!id.IsValidIntId())
|
|
{
|
|
XException.InvalidArgs.Throw();
|
|
}
|
|
|
|
//
|
|
var userInfo = await GetUserInfo();
|
|
|
|
//
|
|
var result = await roleProvider.GetAsync(
|
|
id: id,
|
|
ignoreSoftDeleteds: true,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return Ok(result.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var result = GetExceptionActionResult(ex);
|
|
return result;
|
|
}
|
|
}
|
|
}
|
|
} |