narsil/Tanshu.Accounts.Repository/Session.cs

38 lines
931 B
C#
Raw Normal View History

2018-08-24 10:41:33 +00:00
using System.Linq;
using Tanshu.Accounts.Entities;
2011-01-06 07:17:00 +00:00
namespace Tanshu.Accounts.Contracts
2011-01-06 07:17:00 +00:00
{
public static class Session
2011-01-06 07:17:00 +00:00
{
private static User _currentUser;
2011-01-06 07:17:00 +00:00
public static bool IsAuthenticated { get; private set; }
public static User User
2011-01-06 07:17:00 +00:00
{
get
{
return _currentUser;
2011-01-06 07:17:00 +00:00
}
set
{
if (value != null)
{
_currentUser = value;
2011-01-06 07:17:00 +00:00
IsAuthenticated = true;
}
else
{
_currentUser = null;
2011-01-06 07:17:00 +00:00
IsAuthenticated = false;
}
}
}
public static bool IsAllowed(string role)
{
if (_currentUser == null)
return false;
2018-08-24 10:41:33 +00:00
return _currentUser.Permissions.Any(x => x.Name == role);
}
2011-01-06 07:17:00 +00:00
}
}