namespace Abp.Runtime.Session { /// /// Extension methods for . /// public static class AbpSessionExtensions { /// /// Gets current User's Id. /// Throws if is null. /// /// Session object. /// Current User's Id. public static long GetUserId(this IAbpSession session) { if (!session.UserId.HasValue) { throw new AbpException("Session.UserId is null! Probably, user is not logged in."); } return session.UserId.Value; } /// /// Gets current Tenant's Id. /// Throws if is null. /// /// Session object. /// Current Tenant's Id. /// public static int GetTenantId(this IAbpSession session) { if (!session.TenantId.HasValue) { throw new AbpException("Session.TenantId is null! Possible problems: No user logged in or current logged in user in a host user (TenantId is always null for host users)."); } return session.TenantId.Value; } /// /// Creates from given session. /// Returns null if is null. /// /// The session. public static UserIdentifier ToUserIdentifier(this IAbpSession session) { return session.UserId == null ? null : new UserIdentifier(session.TenantId, session.GetUserId()); } } }