faizinfy

HttpUserSession.vb

Dec 13th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 4.93 KB | None | 0 0
  1. Imports EmployeePerformanceCore
  2. Imports Microsoft.AspNet.Identity
  3. Imports System.Threading
  4. Imports System.Security.Claims
  5. Public Class HttpUserSession
  6.     Implements IUserSession
  7.  
  8.     Private idb As IDataContext
  9.  
  10.     Public Sub New(idb As IDataContext)
  11.         idb = idb
  12.     End Sub
  13.  
  14.     Public ReadOnly Property currentcompanyid As Integer Implements IUserSession.currentcompanyid
  15.         Get
  16.             Dim principal = DirectCast(Thread.CurrentPrincipal, ClaimsPrincipal)
  17.             Dim companyclaims = principal.Claims.Where(Function(a) a.Type = "companyid").FirstOrDefault
  18.             If Not companyclaims Is Nothing Then
  19.                 Return companyclaims.Value
  20.             Else
  21.                 Return 0
  22.             End If
  23.         End Get
  24.     End Property
  25.  
  26.     Public ReadOnly Property currentcompanylogourl As String Implements IUserSession.currentcompanylogourl
  27.         Get
  28.             Dim principal = DirectCast(Thread.CurrentPrincipal, ClaimsPrincipal)
  29.             Dim companyclaims = principal.Claims.Where(Function(a) a.Type = "companylogo").FirstOrDefault
  30.             If Not companyclaims Is Nothing Then
  31.                 Return companyclaims.Value
  32.             Else
  33.                 Return ""
  34.             End If
  35.         End Get
  36.     End Property
  37.  
  38.     Public ReadOnly Property currentcompanyname As String Implements IUserSession.currentcompanyname
  39.         Get
  40.             Dim principal = DirectCast(Thread.CurrentPrincipal, ClaimsPrincipal)
  41.             Dim companyclaim = principal.Claims.Where(Function(a) a.Type = "companyname").FirstOrDefault
  42.             If Not companyclaim Is Nothing Then
  43.                 Return companyclaim.Value
  44.             Else
  45.                 Return ""
  46.             End If
  47.         End Get
  48.     End Property
  49.  
  50.     Public ReadOnly Property currentpermission As IEnumerable(Of String) Implements IUserSession.currentpermission
  51.         Get
  52.             Dim principal = DirectCast(Thread.CurrentPrincipal, ClaimsPrincipal)
  53.             Dim companyclaim = principal.Claims.Where(Function(a) a.Type = "permissions").ToList
  54.  
  55.             Return companyclaim.Select(Function(a) a.Value)
  56.         End Get
  57.     End Property
  58.  
  59.     Public ReadOnly Property currentuserid As Integer Implements IUserSession.currentuserid
  60.         Get
  61.             Return HttpContext.Current.User.Identity.GetUserId
  62.         End Get
  63.     End Property
  64.  
  65.     Public ReadOnly Property currentusername As String Implements IUserSession.currentusername
  66.         Get
  67.             Return HttpContext.Current.User.Identity.GetUserName
  68.         End Get
  69.     End Property
  70.  
  71.     Public ReadOnly Property currentstaffid As Integer Implements IUserSession.currentstaffid
  72.         Get
  73.             Dim principal = DirectCast(Thread.CurrentPrincipal, ClaimsPrincipal)
  74.             Dim companyclaims = principal.Claims.Where(Function(a) a.Type = "staffid").FirstOrDefault
  75.             If Not companyclaims Is Nothing Then
  76.                 Return companyclaims.Value
  77.             Else
  78.                 Return 0
  79.             End If
  80.         End Get
  81.     End Property
  82.  
  83.     Public ReadOnly Property isloggedin As Boolean Implements IUserSession.isloggedin
  84.         Get
  85.             Return HttpContext.Current.User.Identity.IsAuthenticated
  86.         End Get
  87.     End Property
  88.  
  89.     Public ReadOnly Property currentpermissions As IEnumerable(Of String) Implements IUserSession.currentpermissions
  90.         Get
  91.             Dim principal = DirectCast(Thread.CurrentPrincipal, ClaimsPrincipal)
  92.             Dim companyclaim = principal.Claims.Where(Function(a) a.Type = "permissions").ToList
  93.  
  94.             Return companyclaim.Select(Function(a) a.Value)
  95.         End Get
  96.     End Property
  97.  
  98.     Public ReadOnly Property isSupervisor As Boolean Implements IUserSession.isSupervisor
  99.         Get
  100.             Dim principal = DirectCast(Thread.CurrentPrincipal, ClaimsPrincipal)
  101.             Dim supervisorclaim = principal.Claims.Where(Function(a) a.Type = "isSupervisor").FirstOrDefault
  102.             If Not supervisorclaim Is Nothing Then
  103.                 Return supervisorclaim.Value
  104.             Else
  105.                 Return False
  106.             End If
  107.         End Get
  108.     End Property
  109.  
  110.     'Public ReadOnly Property notifications As NotificationViewModel Implements IUserSession.notifications
  111.     '    Get
  112.     '        Return HttpContext.Current.Session("notifications")
  113.     '    End Get
  114.     'End Property
  115.  
  116.     'Public Function SetSession(currentstaffid As Integer, currentcompanyid As Integer) As Result Implements IUserSession.SetSession
  117.     '    Dim r As New Result
  118.  
  119.     '    Dim notifications As New NotificationViewModel
  120.     '    notifications.notifications = idb.AppraisalReviews.Where(Function(a) a.appraisedbystaffid = currentstaffid And a.isactivenotification = True).ToList
  121.     '    If Not notifications.notifications Is Nothing Then
  122.     '        HttpContext.Current.Session.Add("notifications", notifications)
  123.     '    End If
  124.  
  125.     '    Return r
  126.     'End Function
  127.  
  128. End Class
Advertisement
Add Comment
Please, Sign In to add comment