/// <summary> /// Gets a permission /// </summary> /// <param name="systemName">Permission system name</param> /// <returns>Permission</returns> public virtual SystemPermission GetSystemPermissionBySystemName(string systemName, bool userCache = false) { if (String.IsNullOrWhiteSpace(systemName)) return null; using (var context = new SsepsIIEntities()) { if (userCache) { return CacheService.Get(m_PermissionCacheKeyPattern.F(systemName), CacheTimeSpan.Infinite, () => (from perm in context.SystemPermissions orderby perm.SystemPermissionId where perm.SystemName == systemName select perm).FirstOrDefault()); } var query = from perm in context.SystemPermissions orderby perm.SystemPermissionId where perm.SystemName == systemName select perm; var permission = query.FirstOrDefault(); return permission; } }
/// <summary> /// Gets a permission /// </summary> /// <param name="permissionId">Permission identifier</param> /// <returns>Permission</returns> public virtual SystemPermission GetSystemPermissionById(int permissionId) { if (permissionId == 0) return null; using (var context = new SsepsIIEntities()) { return context .SystemPermissions .Where(pr => pr.SystemPermissionId == permissionId) .FirstOrDefault(); } }
/// <summary> /// Delete a permission /// </summary> /// <param name="permission">Permission</param> public virtual void DeleteSystemPermission(SystemPermission permission) { if (permission == null) throw new ArgumentNullException("permission"); using (var context = new SsepsIIEntities()) { context.SystemPermissions.Attach(permission); ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.ChangeObjectState(permission, System.Data.EntityState.Modified); context.SystemPermissions.Remove(permission); context.SaveChanges(); } ClearCache(); }
public List<SystemPermission> GetSystemRolePermissionsForAssignment(int systemRoleId) { using (var context = new SsepsIIEntities()) { var assignedList = context.SystemRolePermissions.Where(r => r.SystemRoleId == systemRoleId).Select(r => r.SystemPermissionId).ToList<int>(); var permissions = context.SystemPermissions.OrderBy(p => p.SystemName).ToList(); foreach (var permission in permissions) permission.IsAssignedToRole = assignedList.Contains(permission.SystemPermissionId); return permissions; } }
public void AssignUnassignPermission(int systemRoleId, int permissionId, bool assign, string whoCreated) { using (var context = new SsepsIIEntities()) context.AssignUnassignPermissionToRole(systemRoleId, permissionId, assign, whoCreated); }
public void DeleteSystemRolePermission(SystemRolePermission rolePermission) { using (var context = new SsepsIIEntities()) { context.SystemRolePermissions.Attach(rolePermission); ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.ChangeObjectState(rolePermission, System.Data.EntityState.Modified); context.SystemRolePermissions.Remove(rolePermission); context.SaveChanges(); } ClearCache(); }
private IEnumerable<SystemPermission> GetSystemRolePermissions(int systemRoleId) { using (var context = new SsepsIIEntities()) { return CacheService.Get(m_RolePermissionsCacheKey.F(systemRoleId), CacheTimeSpan.Infinite, () => context. SystemRolePermissions.Where( p => p.SystemRoleId == systemRoleId). Select(p => p.SystemPermission).ToArray()); } }
/// <summary> /// Inserts a permission /// </summary> /// <param name="permission">Permission</param> public virtual void InsertSystemPermission(SystemPermission permission) { if (permission == null) throw new ArgumentNullException("permission"); using (var context = new SsepsIIEntities()) { context.SystemPermissions.Add(permission); context.SaveChanges(); } ClearCache(); }
public void InsertSystemRolePermission(SystemRolePermission rolePermissionRecord) { using (var context = new SsepsIIEntities()) { context.SystemRolePermissions.Add(rolePermissionRecord); context.SaveChanges(); } ClearCache(); }
/// <summary> /// Gets all permissions /// </summary> /// <returns>Permissions</returns> public virtual IList<SystemPermission> GetAllSystemPermissions() { using (var context = new SsepsIIEntities()) { return (from cr in context.SystemPermissions.Include("SystemRolePermissions") orderby cr.Name select cr).ToArray().ToList(); } }