Add authorized roles

  Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic! Mail us feedback on this topic!  

The following sample code shows how you can add roles authorized for voting.

 

[C#]

 

using CMS.Polls;

 

...

 

        string pollName = "testingpoll"// Poll code name

        string roleName = "cmseditor"// Role code name

        string siteName = "CMSTestingSite"// Role's site code name

 

        // Get poll info for the specified code name

        PollInfo pollObj = PollInfoProvider.GetPollInfo(pollName);

 

        // Get role info for specified role name and site name

        RoleInfo roleObj = RoleInfoProvider.GetRoleInfo(roleName, siteName);

 

        if ((pollObj != null) && (roleObj != null))

        {

            // Change poll access to access for specified roles only

            pollObj.PollAccess = PollInfoProvider.ACCESS_ROLES;

 

            // Save the object

            PollInfoProvider.SetPollInfo(pollObj);

 

            // Check if the role has already been added

            if (!PollInfoProvider.IsRoleAllowedForPoll(pollObj.PollID, roleName))

            {

                // Add role to the poll

                PollInfoProvider.AddRoleToPoll(roleObj.RoleID, pollObj.PollID);

            }

         }

 

Page url: http://devnet.kentico.com/docs/5_5r2/devguide/index.html?api_add_authorized_roles.htm