예제 #1
0
        private void rptSections_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Delete" || e.CommandName == "Detach")
            {
                int     sectionId = Int32.Parse(e.CommandArgument.ToString());
                Section section   = (Section)CoreRepository.GetObjectById(typeof(Section), sectionId);

                if (e.CommandName == "Delete")
                {
                    section.Node = ActiveNode;
                    try
                    {
                        // First tell the module to remove its content.
                        ModuleBase module = ModuleLoader.GetModuleFromSection(section);
                        module.DeleteModuleContent();
                        // Make sure there is no gap in the section indexes.
                        // ABUSE: this method was not designed for this, but works fine.
                        section.ChangeAndUpdatePositionsAfterPlaceholderChange(section.PlaceholderId, section.Position,
                                                                               false);
                        // Now delete the Section.
                        ActiveNode.Sections.Remove(section);
                        CoreRepository.DeleteObject(section);
                    }
                    catch (Exception ex)
                    {
                        ShowError(ex.Message);
                        log.Error(String.Format("Error deleting section : {0}.", section.Id), ex);
                    }
                }
                if (e.CommandName == "Detach")
                {
                    try
                    {
                        // Make sure there is no gap in the section indexes.
                        // ABUSE: this method was not designed for this, but works fine.
                        section.ChangeAndUpdatePositionsAfterPlaceholderChange(section.PlaceholderId, section.Position,
                                                                               false);
                        // Now detach the Section.
                        ActiveNode.Sections.Remove(section);
                        section.Node          = null;
                        section.PlaceholderId = null;
                        CoreRepository.UpdateObject(section);
                        // Update search index to make sure the content of detached sections doesn't
                        // show up in a search.
                        SearchHelper.UpdateIndexFromSection(section);
                    }
                    catch (Exception ex)
                    {
                        ShowError(ex.Message);
                        log.Error(String.Format("Error detaching section : {0}.", section.Id), ex);
                    }
                }
                BindSections();
            }
        }