示例#1
0
        /// <summary>
        /// Archives current poll to the pollItem.
        /// </summary>
        /// <param name="pollItem">The poll item.</param>
        public void ArchiveTo(Item pollItem)
        {
            //copy archive folder if exists
            foreach (Item item in InnerItem.Children)
            {
                if (item.TemplateID == PollConstants.PollArchiveTemplateID)
                {
                    item.CopyTo(pollItem, item.Name);
                    item.Delete();
                }
            }
            //or create archive folder
            if (pollItem.Children[PollConstants.PollArchiveFolderName] == null)
            {
                TemplateItem pollArhiveTemplate = PollConstants.DatabaseContext.Templates[PollConstants.PollArchiveTemplateID];
                Assert.IsNotNull(pollArhiveTemplate, "Poll archive template");

                pollItem.Add(PollConstants.PollArchiveFolderName, pollArhiveTemplate);
            }
            string itemName    = string.Format("{0} {1}", InnerItem.Name, DateTime.Today.ToShortDateString().Replace('.', ' '));
            string displayName = itemName;

            if (ItemUtil.GetItemNameError(itemName).Length > 0)
            {
                itemName = ItemUtil.ProposeValidItemName(itemName);
            }

            Item currentPollCopy = InnerItem.CopyTo(pollItem.Children[PollConstants.PollArchiveFolderName], itemName, Data.ID.NewID, false);

            if (displayName != itemName)
            {
                PollItem archivedPoll = new PollItem(currentPollCopy)
                {
                    DisplayName = displayName
                };
            }

            //copy all poll options
            foreach (Item item in InnerItem.Children)
            {
                item.CopyTo(currentPollCopy, item.Name);
                item.Delete();
            }
            InnerItem.Delete();
        }