Quantcast
Channel: Developer to developer
Viewing all articles
Browse latest Browse all 9076

How do i update values in Blocks programmatically?

$
0
0

Hi I have another specific feature i have to make:

I want to have a 'checkbox' in a block, that can be used to reset other properties of the same blocktype. I use a  page events InitializableModule that checks if a certain blocktype is updated:

 

var repo = ServiceLocator.Current.GetInstance();
            var content = repo.Get(e.ContentLink);
            try {
                if (content.ContentTypeID == Hint.Constants.PollBlockTypeID)
                {
                    PollBlock myPoll = content as PollBlock;
                    var clonePoll = (IContent) myPoll.CreateWritableClone();
                    bool resetValues = false;
                    Boolean.TryParse(clonePoll.Property["ResetVotes"].Value.ToString(), out resetValues);
                    if (resetValues)
                    {
                        clonePoll.Property["CountAnswer1"].Value = 0;
                        clonePoll.Property["CountAnswer2"].Value = 0;
                        clonePoll.Property["CountAnswer3"].Value = 0;
                        clonePoll.Property["CountAnswer4"].Value = 0;
                        clonePoll.Property["CountAnswer5"].Value = 0;
                        clonePoll.Property["CountAnswerTotal"].Value = 0;
                        clonePoll.Property["VotedBy"].Value = string.Empty;
                        clonePoll.Property["ResetVotes"].Value = false;
                        repo.Save(clonePoll, SaveAction.Publish,AccessLevel.Publish);
                        e.CancelAction = false; //??
                    }
                }
            }
            catch (Exception exc)
            {
            }

It all seems to work, however, because i change the block whilst it was active, it keeps asking me to publish the page. How can i properly update the Block and go back to previewing the block?

Thanks in advance


Viewing all articles
Browse latest Browse all 9076

Trending Articles