IVSession.cs 812 B

123456789101112131415161718192021222324252627
  1. using System;
  2. namespace VCommon.VApplication
  3. {
  4. public interface IVSession
  5. {
  6. Guid? UserId { get; }
  7. Guid? TenantId { get; }
  8. string Token { get; }
  9. void DemandAuth();
  10. public Guid GetUserId()
  11. {
  12. if (!UserId.HasValue) throw new VApplicationAuthException("Session.UserId is null! Probably, user is not logged in.", AuthReason.AuthRequired);
  13. return UserId.Value;
  14. }
  15. public Guid GetTenantId()
  16. {
  17. if (!TenantId.HasValue)
  18. throw new VApplicationAuthException("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).", AuthReason.AuthRequired);
  19. return TenantId.Value;
  20. }
  21. }
  22. }