Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports EmployeePerformanceCore
- Imports Microsoft.AspNet.Identity
- Imports System.Threading
- Imports System.Security.Claims
- Public Class HttpUserSession
- Implements IUserSession
- Private idb As IDataContext
- Public Sub New(idb As IDataContext)
- idb = idb
- End Sub
- Public ReadOnly Property currentcompanyid As Integer Implements IUserSession.currentcompanyid
- Get
- Dim principal = DirectCast(Thread.CurrentPrincipal, ClaimsPrincipal)
- Dim companyclaims = principal.Claims.Where(Function(a) a.Type = "companyid").FirstOrDefault
- If Not companyclaims Is Nothing Then
- Return companyclaims.Value
- Else
- Return 0
- End If
- End Get
- End Property
- Public ReadOnly Property currentcompanylogourl As String Implements IUserSession.currentcompanylogourl
- Get
- Dim principal = DirectCast(Thread.CurrentPrincipal, ClaimsPrincipal)
- Dim companyclaims = principal.Claims.Where(Function(a) a.Type = "companylogo").FirstOrDefault
- If Not companyclaims Is Nothing Then
- Return companyclaims.Value
- Else
- Return ""
- End If
- End Get
- End Property
- Public ReadOnly Property currentcompanyname As String Implements IUserSession.currentcompanyname
- Get
- Dim principal = DirectCast(Thread.CurrentPrincipal, ClaimsPrincipal)
- Dim companyclaim = principal.Claims.Where(Function(a) a.Type = "companyname").FirstOrDefault
- If Not companyclaim Is Nothing Then
- Return companyclaim.Value
- Else
- Return ""
- End If
- End Get
- End Property
- Public ReadOnly Property currentpermission As IEnumerable(Of String) Implements IUserSession.currentpermission
- Get
- Dim principal = DirectCast(Thread.CurrentPrincipal, ClaimsPrincipal)
- Dim companyclaim = principal.Claims.Where(Function(a) a.Type = "permissions").ToList
- Return companyclaim.Select(Function(a) a.Value)
- End Get
- End Property
- Public ReadOnly Property currentuserid As Integer Implements IUserSession.currentuserid
- Get
- Return HttpContext.Current.User.Identity.GetUserId
- End Get
- End Property
- Public ReadOnly Property currentusername As String Implements IUserSession.currentusername
- Get
- Return HttpContext.Current.User.Identity.GetUserName
- End Get
- End Property
- Public ReadOnly Property currentstaffid As Integer Implements IUserSession.currentstaffid
- Get
- Dim principal = DirectCast(Thread.CurrentPrincipal, ClaimsPrincipal)
- Dim companyclaims = principal.Claims.Where(Function(a) a.Type = "staffid").FirstOrDefault
- If Not companyclaims Is Nothing Then
- Return companyclaims.Value
- Else
- Return 0
- End If
- End Get
- End Property
- Public ReadOnly Property isloggedin As Boolean Implements IUserSession.isloggedin
- Get
- Return HttpContext.Current.User.Identity.IsAuthenticated
- End Get
- End Property
- Public ReadOnly Property currentpermissions As IEnumerable(Of String) Implements IUserSession.currentpermissions
- Get
- Dim principal = DirectCast(Thread.CurrentPrincipal, ClaimsPrincipal)
- Dim companyclaim = principal.Claims.Where(Function(a) a.Type = "permissions").ToList
- Return companyclaim.Select(Function(a) a.Value)
- End Get
- End Property
- Public ReadOnly Property isSupervisor As Boolean Implements IUserSession.isSupervisor
- Get
- Dim principal = DirectCast(Thread.CurrentPrincipal, ClaimsPrincipal)
- Dim supervisorclaim = principal.Claims.Where(Function(a) a.Type = "isSupervisor").FirstOrDefault
- If Not supervisorclaim Is Nothing Then
- Return supervisorclaim.Value
- Else
- Return False
- End If
- End Get
- End Property
- 'Public ReadOnly Property notifications As NotificationViewModel Implements IUserSession.notifications
- ' Get
- ' Return HttpContext.Current.Session("notifications")
- ' End Get
- 'End Property
- 'Public Function SetSession(currentstaffid As Integer, currentcompanyid As Integer) As Result Implements IUserSession.SetSession
- ' Dim r As New Result
- ' Dim notifications As New NotificationViewModel
- ' notifications.notifications = idb.AppraisalReviews.Where(Function(a) a.appraisedbystaffid = currentstaffid And a.isactivenotification = True).ToList
- ' If Not notifications.notifications Is Nothing Then
- ' HttpContext.Current.Session.Add("notifications", notifications)
- ' End If
- ' Return r
- 'End Function
- End Class
Advertisement
Add Comment
Please, Sign In to add comment