DD.WellWorkover.Cloud/AsbCloudWebApi/Extensions.cs

31 lines
793 B
C#
Raw Normal View History

using AsbCloudApp.Data;
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)
{
var claimIdCompany = user.FindFirst(nameof(UserDto.IdCompany));
2021-07-21 15:22:58 +05:00
if (claimIdCompany is null)
return null;
2021-07-21 15:22:58 +05:00
return int.TryParse(claimIdCompany.Value, out int uid)
? uid
: null;
}
public static int? GetUserId(this ClaimsPrincipal user)
{
var userId = user.FindFirst(nameof(UserDto.Id));
if (userId is null)
return null;
return int.TryParse(userId.Value, out int uid)
? uid
: null;
}
}
}