public void AddRange(MenuPermissionCollection menuPermissions)
 {
     foreach (MenuPermissionInfo permission in menuPermissions)
     {
         this.Add(permission);
     }
 }
 public bool CompareTo(MenuPermissionCollection menuPermissionCollection)
 {
     if (menuPermissionCollection.Count != Count)
     {
         return(false);
     }
     InnerList.Sort(new CompareMenuPermissions());
     menuPermissionCollection.InnerList.Sort(new CompareMenuPermissions());
     for (int i = 0; i <= Count - 1; i++)
     {
         if (menuPermissionCollection[i].MenuPermissionId != this[i].MenuPermissionId ||
             menuPermissionCollection[i].AllowAccess != this[i].AllowAccess)
         {
             return(false);
         }
     }
     return(true);
 }
        public static bool HasMenuPermission(MenuPermissionCollection menuPermissions, string permissionKey)
        {
            bool hasPermission = Null.NullBoolean;

            if (permissionKey.Contains(","))
            {
                foreach (string permission in permissionKey.Split(','))
                {
                    if (PortalSecurity.IsInRoles(menuPermissions.ToString(permission)))
                    {
                        hasPermission = true;
                        break;
                    }
                }
            }
            else
            {
                hasPermission = PortalSecurity.IsInRoles(menuPermissions.ToString(permissionKey));
            }
            return(hasPermission);
        }
        public static MenuPermissionCollection GetMenuPermissions(int portalId)
        {
            var cacheKey    = GetCacheKey(portalId);
            var permissions = DataCache.GetCache <MenuPermissionCollection>(cacheKey);

            if (permissions == null)
            {
                lock (ThreadLocker)
                {
                    permissions = DataCache.GetCache <MenuPermissionCollection>(cacheKey);
                    if (permissions == null)
                    {
                        permissions = new MenuPermissionCollection();
                        EnsureMenuDefaultPermissions(portalId);
                        var reader = DataService.GetPersonbaBarMenuPermissionsByPortal(portalId);
                        try
                        {
                            while (reader.Read())
                            {
                                var permissionInfo = CBO.FillObject <MenuPermissionInfo>(reader, false);
                                permissions.Add(permissionInfo, true);
                            }

                            DataCache.SetCache(cacheKey, permissions);
                        }
                        catch (Exception ex)
                        {
                            Logger.Error(ex);
                        }
                        finally
                        {
                            CBO.CloseDataReader(reader, true);
                        }
                    }
                }
            }

            return(permissions);
        }
 public MenuPermissionCollection(MenuPermissionCollection permissions)
 {
     this.AddRange(permissions);
 }