Files
monorepo/LCU.WebApps.Indirect.ReserveManagementSystem/WebApp/ReserveManagementSystemUI/Helpers/ServiceHelpers.cs
T
2026-03-17 08:54:34 -05:00

47 lines
1.5 KiB
C#

using Microsoft.AspNetCore.Components.Authorization;
using System.Reflection;
using ReserveManagementSystemUI.Model.Configuration;
using Serilog;
namespace ReserveManagementSystemUI.Helpers
{
public class ServiceHelpers
{
private AuthenticationStateProvider _authenticationStateProvider;
private readonly RmsUIConfiguration _rmsUIConfig;
public ServiceHelpers(RmsUIConfiguration rmsUIConfig, AuthenticationStateProvider authenticationStateProvider)
{
_rmsUIConfig = rmsUIConfig;
_authenticationStateProvider = authenticationStateProvider;
}
public string GetControllerApiUrl(string apiUrl, string controller)
{
PropertyInfo propInfo = typeof(RmsUIConfiguration).GetProperty(controller);
var propValue = propInfo.GetValue(_rmsUIConfig, null);
return _rmsUIConfig.RmsApiUrl + propValue;
}
public string GetReportServerBaseUrl()
{
return _rmsUIConfig.ReportServerUrl;
}
public string GetUserName()
{
var authState = _authenticationStateProvider.GetAuthenticationStateAsync().Result;
if (authState?.User?.Identity?.Name == null)
{
Log.Error("Could not get user identity by AuthenticationState");
return "";
}
var userName = authState.User.Identity.Name;
return userName[4..];
}
}
}