/// <summary>
 /// Handle the Removal of Node Categories when not bound to the document, since binding to the Nodes don't seem to operate right.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void NonBindingNodeDocument_ProcessTask_After(object sender, StagingSynchronizationEventArgs e)
 {
     if (e.TaskType == TaskTypeEnum.DeleteObject)
     {
         // Don't want to trigger updates as we set the data in the database, so we won't log synchronziations
         using (new CMSActionContext()
         {
             LogSynchronization = false,
             LogIntegration = false
         })
         {
             if (e.ObjectType.ToLower() == "cms.treecategory")
             {
                 DataTable NodeCategoryTable = e.TaskData.Tables[0];
                 // Translate tables
                 int NodeID     = RelHelper.TranslateBindingTranslateID((int)NodeCategoryTable.Rows[0]["NodeID"], e.TaskData, "cms.node");
                 int CategoryID = RelHelper.TranslateBindingTranslateID((int)NodeCategoryTable.Rows[0]["CategoryID"], e.TaskData, "cms.category");
                 if (NodeID > 0 && CategoryID > 0)
                 {
                     TreeCategoryInfoProvider.RemoveTreeFromCategory(NodeID, CategoryID);
                 }
             }
         }
     }
 }
        // GET: Polygomy
        public ActionResult Index()
        {
            Polygomy Page = DynamicRouteHelper.GetPage <Polygomy>();

            HttpContext.Kentico().PageBuilder().Initialize(Page.DocumentID);
            // Get Categories
            List <int> PageCategories = TreeCategoryInfoProvider.GetTreeCategories()
                                        .WhereEquals("NodeID", Page.NodeID)
                                        .Select(x => x.CategoryID).ToList();

            PolygomyViewModel model = new PolygomyViewModel()
            {
                MemeCategories = CategoryInfoProvider.GetCategories()
                                 .WhereIn("CategoryID", PageCategories)
                                 .Select(x => x.CategoryDisplayName).ToArray(),
            };

            if (PageCategories.Count > 0)
            {
                model.Memes = MemeProvider.GetMemes()
                              .Where(RelHelper.GetNodeCategoryWhere(PageCategories.Select(x => (object)x)))
                              .ToList();
            }
            return(View("NEWCC/Polygomy", model));
        }
        private void ProcessTask_After(object sender, StagingSynchronizationEventArgs e)
        {
            if (e.TaskType == TaskTypeEnum.UpdateDocument)
            {
                // Seems the first table is always the node's table, the table name dose change by the document page type.
                DataTable NodeTable = e.TaskData.Tables[0];
                if (NodeTable != null && NodeTable.Columns.Contains("NodeGuid"))
                {
                    // Don't want to trigger updates as we set the data in the database, so we won't log synchronziations
                    TreeNode NodeObj = new DocumentQuery().WhereEquals("NodeGUID", NodeTable.Rows[0]["NodeGuid"]).FirstOrDefault();

                    using (new CMSActionContext()
                    {
                        LogSynchronization = false,
                        LogIntegration = false
                    })
                    {
                        List <int> NewNodeCategoryIDs = RelHelper.NewBoundObjectIDs(e, TreeCategoryInfo.OBJECT_TYPE, "NodeID", "CategoryID", CategoryInfo.TYPEINFO);

                        // Now handle categories, deleting categories not found, and adding ones that are not set yet.
                        TreeCategoryInfoProvider.GetTreeCategories().WhereEquals("NodeID", NodeObj.NodeID).WhereNotIn("CategoryID", NewNodeCategoryIDs).ForEachObject(x => x.Delete());
                        List <int> CurrentCategories = TreeCategoryInfoProvider.GetTreeCategories().WhereEquals("NodeID", NodeObj.NodeID).Select(x => x.CategoryID).ToList();
                        foreach (int NewCategoryID in NewNodeCategoryIDs.Except(CurrentCategories))
                        {
                            TreeCategoryInfoProvider.AddTreeToCategory(NodeObj.NodeID, NewCategoryID);
                        }
                    }
                    if (RelHelper.IsStagingEnabled(NodeObj.NodeSiteID))
                    {
                        // Check if we need to generate a task for a server that isn't the origin server
                        RelHelper.CheckIfTaskCreationShouldOccur(NodeObj.NodeGUID);
                    }
                }
                else
                {
                    EventLogProvider.LogEvent("E", "RelationshipExended", "No Node Table Found", eventDescription: "First Table in the incoming Staging Task did not contain the Node GUID, could not processes.");
                }
            }
        }