SetCurrentGroups() public static method

Sets the current groups of a session.
public static SetCurrentGroups ( string sessionId, UserGroup groups ) : void
sessionId string The session ID.
groups UserGroup The groups.
return void
示例#1
0
        /// <summary>
        /// Gets the current user groups.
        /// </summary>
        public static IEnumerable <UserGroup> GetCurrentGroups()
        {
            if (Session == null)
            {
                return(Array.Empty <UserGroup>());
            }

            var sessionId = Session.SessionID;

            var groups = SessionCache.GetCurrentGroups(sessionId);

            if (groups != null && groups.Length != 0)
            {
                return(groups);
            }

            var current = GetCurrentUser();

            if (current == null)
            {
                return(anonymousGroups ?? (anonymousGroups = new UserGroup[] { Users.FindUserGroup(Settings.AnonymousGroup) }));
            }

            // This check is necessary because after group deletion the session might contain outdated data
            groups = current.Groups.Select(g => Users.FindUserGroup(g)).Where(u => u != null).ToArray();
            SessionCache.SetCurrentGroups(sessionId, groups);
            return(groups);
        }
示例#2
0
        /// <summary>
        /// Gets the current user groups.
        /// </summary>
        public static UserGroup[] GetCurrentGroups()
        {
            if (Session != null)
            {
                string      sessionId = Session.SessionID;
                UserGroup[] groups    = SessionCache.GetCurrentGroups(sessionId);

                if (groups == null || groups.Length == 0)
                {
                    UserInfo current = GetCurrentUser();
                    if (current != null)
                    {
                        // This check is necessary because after group deletion the session might contain outdated data
                        List <UserGroup> temp = new List <UserGroup>(current.Groups.Length);
                        for (int i = 0; i < current.Groups.Length; i++)
                        {
                            UserGroup tempGroup = Users.FindUserGroup(current.Groups[i]);
                            if (tempGroup != null)
                            {
                                temp.Add(tempGroup);
                            }
                        }
                        groups = temp.ToArray();
                    }
                    else
                    {
                        groups = new UserGroup[] { Users.FindUserGroup(Settings.AnonymousGroup) };
                    }

                    SessionCache.SetCurrentGroups(sessionId, groups);
                }

                return(groups);
            }
            else
            {
                return(new UserGroup[0]);
            }
        }