/// <summary>
    /// Returns true if the contact is in any/all of the specified community groups (i.e. if any of the user assigned to the contact is in any/all specified community groups).
    /// </summary>
    /// <param name="contact">Contact which should be checked</param>
    /// <param name="groupNames">Name of the groups separated with semicolon</param>
    /// <param name="allGroups">If true, contact has to in all specified groups. If false, it is sufficient if the contact is at least in one of the groups.</param>
    public static bool IsInCommunityGroup(object contact, string groupNames, bool allGroups)
    {
        ContactInfo ci = contact as ContactInfo;

        if (ci == null)
        {
            return(false);
        }

        if (!string.IsNullOrEmpty(groupNames))
        {
            string[] groups = groupNames.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string groupName in groups)
            {
                bool isInGroup = false;
                foreach (UserInfo user in ci.Users)
                {
                    BaseInfo group = ModuleCommands.CommunityGetGroupInfoByName(groupName, CMSContext.CurrentSiteName);
                    if (group != null)
                    {
                        isInGroup = ModuleCommands.CommunityIsMemberOfGroup(user.UserID, group.Generalized.ObjectID);
                        if (isInGroup && !allGroups)
                        {
                            // In role and it is sufficient if at least one matches => true
                            return(true);
                        }
                    }
                }

                if (!isInGroup && allGroups)
                {
                    // Not in role, but should be in all roles
                    return(false);
                }
            }
        }

        if (allGroups)
        {
            // It means either no roles were specified or contact is in all roles
            return(true);
        }
        else
        {
            return(false);
        }
    }