Kentico CMS 7.0 Developer's Guide

Managing polls

Managing polls

Previous topic Next topic Mail us feedback on this topic!  

Managing polls

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

Arrow


API examples for newer versions


Please visit the latest API Examples documentation to view API examples for newer versions of Kentico.



The following example creates a poll.

 

private bool CreatePoll()
{
  // Create new poll object
  PollInfo newPoll = new PollInfo();

 
  // Set the properties
   newPoll.PollDisplayName = "My new poll";
   newPoll.PollCodeName = "MyNewPoll";
   newPoll.PollTitle = "My title";
   newPoll.PollQuestion = "My question";
   newPoll.PollResponseMessage = "My response message.";
   newPoll.PollAllowMultipleAnswers = false;
   newPoll.PollAccess = 0;

 
  // Save the poll
  PollInfoProvider.SetPollInfo(newPoll);

 
  return true;
}

 

The following example gets and updates a poll.

 

private bool GetAndUpdatePoll()
{
  // Get the poll
  PollInfo updatePoll = PollInfoProvider.GetPollInfo("MyNewPoll");

 
  if (updatePoll != null)
   {
      // Update the properties
       updatePoll.PollDisplayName = updatePoll.PollDisplayName.ToLower();

 
      // Save the changes
      PollInfoProvider.SetPollInfo(updatePoll);

 
      return true;
   }

 
  return false;
}

 

The following example gets and bulk updates polls.

 

private bool GetAndBulkUpdatePolls()
{
  // Prepare the parameters
  string where = "PollCodeName LIKE N'MyNewPoll%'";

 
  // Get the data
  DataSet polls = PollInfoProvider.GetPolls(where, null);

 
  if (!DataHelper.DataSourceIsEmpty(polls))
   {
      // Loop through the individual items
      foreach (DataRow pollDr in polls.Tables[0].Rows)
       {
          // Create object from DataRow
          PollInfo modifyPoll = new PollInfo(pollDr);

 
          // Update the properties
           modifyPoll.PollDisplayName = modifyPoll.PollDisplayName.ToUpper();

 
          // Save the changes
          PollInfoProvider.SetPollInfo(modifyPoll);
       }

 
      return true;
   }

 
  return false;
}

 

The following example adds a poll to site.

 

private bool AddPollToSite()
{
  // Get the poll
  PollInfo poll = PollInfoProvider.GetPollInfo("MyNewPoll");

 
  if (poll != null)
   {
      int pollId = poll.PollID;
      int siteId = CMSContext.CurrentSiteID;

 
      // Save the binding
      PollSiteInfoProvider.AddPollToSite(pollId, siteId);

 
      return true;
   }

 
  return false;
}

 

The following example removes a poll from site.

 

private bool RemovePollFromSite()
{
  // Get the poll
  PollInfo removePoll = PollInfoProvider.GetPollInfo("MyNewPoll");

 
  if (removePoll != null)
   {
      // Remove poll from site
      PollSiteInfoProvider.RemovePollFromSite(removePoll.PollID, CMSContext.CurrentSiteID);

 
      return true;
   }

 
  return false;
}

 

The following example deletes a poll.

 

private bool DeletePoll()
{
  // Get the poll
  PollInfo deletePoll = PollInfoProvider.GetPollInfo("MyNewPoll");

 
  // Delete the poll
  PollInfoProvider.DeletePollInfo(deletePoll);

 
  return (deletePoll != null);
}