EnVisageOnline/Beta/Source/EnVisage/App_Start/SecurityProvider.cs

62 lines
2.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using EnVisage.Code;
using EnVisage.Code.Cache;
namespace EnVisage.App_Start
{
public static class SecurityProvider
{
public static Dictionary<Guid, Areas> GeneralAccess
{
get
{
object d = System.Web.HttpContext.Current.Application["SecurityItems"];
return (d == null ? null : (Dictionary<Guid, Areas>)d);
}
set
{
System.Web.HttpContext.Current.Application["SecurityItems"] = value;
}
}
public static Dictionary<Guid, Guid> ProjectAccess
{
get
{
object d = System.Web.HttpContext.Current.Application["SecurityItems"];
return (d == null ? null : (Dictionary<Guid, Guid>)d);
}
set
{
System.Web.HttpContext.Current.Application["SecurityItems"] = value;
}
}
static SecurityProvider()
{
EnVisageEntities context = new EnVisageEntities();
ProjectAccessCache projAccessCache = new ProjectAccessCache();
SecurityAreasCache securityAreasCache = new SecurityAreasCache();
var projects = (from pr in projAccessCache.Value
select pr).ToList();
var _ProjectAccess = new Dictionary<Guid, Guid>();
foreach (var access in projects)
{
_ProjectAccess.Add(access.ProjectId, access.PrincipalId);
}
ProjectAccess = _ProjectAccess;
var securityItems = (from pr in securityAreasCache.Value
select pr).ToList();
var _GeneralAccess = new Dictionary<Guid, Areas>();
foreach (var access in securityItems)
{
_GeneralAccess.Add(access.PrincipalId, (Areas)Enum.Parse(typeof(Areas), access.SecurityObject));
}
GeneralAccess = _GeneralAccess;
}
}
}