2021-10-12 11:03:05 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
2021-05-12 16:03:14 +05:00
|
|
|
|
using System.Security.Claims;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi
|
|
|
|
|
{
|
|
|
|
|
public static class Extensions
|
|
|
|
|
{
|
2021-07-21 15:22:58 +05:00
|
|
|
|
public static int? GetCompanyId(this ClaimsPrincipal user)
|
2021-05-12 16:03:14 +05:00
|
|
|
|
{
|
2021-10-12 11:03:05 +05:00
|
|
|
|
var claimIdCompany = user.FindFirst(nameof(UserDto.IdCompany));
|
2021-07-21 15:22:58 +05:00
|
|
|
|
if (claimIdCompany is null)
|
2021-05-12 16:03:14 +05:00
|
|
|
|
return null;
|
|
|
|
|
|
2021-07-21 15:22:58 +05:00
|
|
|
|
return int.TryParse(claimIdCompany.Value, out int uid)
|
2021-05-12 16:03:14 +05:00
|
|
|
|
? uid
|
|
|
|
|
: null;
|
|
|
|
|
}
|
2021-08-17 13:03:17 +05:00
|
|
|
|
|
|
|
|
|
public static int? GetUserId(this ClaimsPrincipal user)
|
|
|
|
|
{
|
2021-10-12 11:03:05 +05:00
|
|
|
|
var userId = user.FindFirst(nameof(UserDto.Id));
|
2021-08-17 13:03:17 +05:00
|
|
|
|
if (userId is null)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
return int.TryParse(userId.Value, out int uid)
|
|
|
|
|
? uid
|
|
|
|
|
: null;
|
|
|
|
|
}
|
2021-05-12 16:03:14 +05:00
|
|
|
|
}
|
|
|
|
|
}
|