narsil/Tanshu.Accounts.Repository/Session.cs
tanshu 69617949bd Important! : Need to update to new schema using SQL Scripts
Important! : This version will not work.  It is pre-alpha and saved in case of catastrophic failure
Refactor: Remove dependency on Fluent Nhibernate.
Refactor: All Primary keys are now Guids.
Refactor: Class Mappings changed from AutoMap to Explicit Mappings.
Breakage: All Cascading is now disabled and entities must be explicitly saved/updated/deleted
Breakage: Auto Commiting is now off and "SaveChanges()" needs to be called on all BIs.
Refactor: Changed the pattern where all relevant db code for an operation is basically in the same function.
Chore: Removed Advance and Payments options.
2014-10-12 15:11:45 +05:30

47 lines
1.3 KiB
C#

using System.Collections.Generic;
using Tanshu.Accounts.Entities.Auth;
using Tanshu.Accounts.Repository;
namespace Tanshu.Accounts.Contracts
{
public static class Session
{
private static Dictionary<string, bool> _roles;
private static User _currentUser;
public static bool IsAuthenticated { get; private set; }
public static User User
{
get
{
return _currentUser;
}
set
{
if (value != null)
{
_currentUser = value;
IsAuthenticated = true;
}
else
{
_currentUser = null;
IsAuthenticated = false;
_roles = null;
}
}
}
public static bool IsAllowed(RoleConstants role)
{
if (_currentUser == null)
return false;
if (_roles == null)
_roles = new Dictionary<string, bool>();
if (!_roles.ContainsKey(role.Role))
_roles.Add(role.Role, MembershipBI.IsUserInRole(_currentUser.UserID, role.Role));
return _roles[role.Role];
}
}
}