Kentico CMS 6.0 Developer's Guide

Managing answers

Managing answers

Previous topic Next topic Mail us feedback on this topic!  

Managing answers

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 an answer.

 

private bool CreateAnswer()

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

 
  if (poll != null)
   {
      // Create new answer object
      PollAnswerInfo newAnswer = new PollAnswerInfo();

 
      // Set the properties
       newAnswer.AnswerPollID = poll.PollID;
       newAnswer.AnswerText = "My new answer";
       newAnswer.AnswerEnabled = true;
       newAnswer.AnswerCount = 0;

 
      // Save the answer
      PollAnswerInfoProvider.SetPollAnswerInfo(newAnswer);

 
      return true;
   }

 
  return false;
}

 

The following example gets and updates an answer.

 

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

 
  if (updatePoll != null)
   {
      DataSet answers = PollAnswerInfoProvider.GetAnswers(updatePoll.PollID, 1, null);

 
      if (!DataHelper.DataSourceIsEmpty(answers))
       {
          PollAnswerInfo updateAnswer = new PollAnswerInfo(answers.Tables[0].Rows[0]);

 
          // Update the properties
           updateAnswer.AnswerText = updateAnswer.AnswerText.ToLower();

 
          // Save the changes
          PollAnswerInfoProvider.SetPollAnswerInfo(updateAnswer);

 
          return true;
       }
   }

 
  return false;
}

 

The following example gets and bulk updates answers.

 

private bool GetAndBulkUpdateAnswers()
{
  PollInfo updatePoll = PollInfoProvider.GetPollInfo("MyNewPoll");

 
  if (updatePoll != null)
   {
      // Get the data
      DataSet answers = PollAnswerInfoProvider.GetAnswers(updatePoll.PollID);
      if (!DataHelper.DataSourceIsEmpty(answers))
       {
          // Loop through the individual items
          foreach (DataRow answerDr in answers.Tables[0].Rows)
           {
              // Create object from DataRow
              PollAnswerInfo modifyAnswer = new PollAnswerInfo(answerDr);

 
              // Update the properties
               modifyAnswer.AnswerText = modifyAnswer.AnswerText.ToUpper();

 
              // Save the changes
              PollAnswerInfoProvider.SetPollAnswerInfo(modifyAnswer);
           }

 
          return true;
       }
   }

 
  return false;
}

 

The following example deletes an answer.

 

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

 
  if (updatePoll != null)
   {
      // Get the answer
      DataSet answers = PollAnswerInfoProvider.GetAnswers(updatePoll.PollID, 1, null);

 
      if (!DataHelper.DataSourceIsEmpty(answers))
       {
          PollAnswerInfo deleteAnswer = new PollAnswerInfo(answers.Tables[0].Rows[0]);

 
          // Delete the answer
          PollAnswerInfoProvider.DeletePollAnswerInfo(deleteAnswer);

 
          return (deleteAnswer != null);
       }
   }

 
  return false;
}