/// <summary>
    /// Handles request for deleting category.
    /// </summary>
    /// <param name="sender">Sender object.</param>
    /// <param name="e">Arguments.</param>
    public void lnkDelete_Click(object sender, EventArgs e)
    {
        CategoryInfo categoryObj = SelectedCategory;

        if ((categoryObj != null) && CanModifySelectedCategory)
        {
            // Remove deleted category from selection
            if (!string.IsNullOrEmpty(hidItem.Value))
            {
                hidItem.Value = hidItem.Value.Replace(valuesSeparator + categoryObj.CategoryID + valuesSeparator, valuesSeparator);
                pnlHidden.Update();
            }

            // Preselect parent category
            CategoryInfo parentCategory = CategoryInfoProvider.GetCategoryInfo(categoryObj.CategoryParentID);
            if (parentCategory != null)
            {
                SelectedCategoryID = parentCategory.CategoryID;
                PreselectCategory(parentCategory, true);
            }
            else
            {
                SelectedCategoryID       = 0;
                SelectedCategoryParentID = categoryObj.CategoryIsPersonal ? PERSONAL_CATEGORIES_ROOT_PARENT_ID : CATEGORIES_ROOT_PARENT_ID;
            }

            // Delete category
            CategoryInfoProvider.DeleteCategoryInfo(categoryObj);

            pnlUpdateTrees.Update();
        }
    }
Esempio n. 2
0
    private void DeleteCategory(CategoryInfo categoryObj, bool reload = false)
    {
        // Check if category
        if ((categoryObj != null) && CanModifyCategory(categoryObj.CategoryIsPersonal, categoryObj.CategoryIsGlobal))
        {
            var parentCategory = CategoryInfoProvider.GetCategoryInfo(categoryObj.CategoryParentID);
            var isPersonal     = categoryObj.CategoryIsPersonal;

            // Delete category
            CategoryInfoProvider.DeleteCategoryInfo(categoryObj);

            // Check if deleted category has parent
            if (parentCategory != null)
            {
                SelectedCategoryID = parentCategory.CategoryID;

                // Switch to editing of parent category
                catEdit.UserID   = parentCategory.CategoryUserID;
                catEdit.Category = parentCategory;

                SwitchToEdit(reload);
                PreselectCategory(parentCategory, false);
            }
            else
            {
                SelectedCategoryID       = 0;
                SelectedCategoryParentID = isPersonal ? PERSONAL_CATEGORIES_ROOT_PARENT_ID : CATEGORIES_ROOT_PARENT_ID;
                SwitchToInfo();
            }

            pnlUpdateTree.Update();
            pnlUpdateContent.Update();
        }
    }
    /// <summary>
    /// Handles request for deleting category.
    /// </summary>
    public void Delete()
    {
        CategoryInfo categoryObj = SelectedCategory;

        if ((categoryObj != null) && CanModifySelectedCategory)
        {
            // Remove deleted category from selection
            if (!string.IsNullOrEmpty(hidItem.Value))
            {
                hidItem.Value = hidItem.Value.Replace(ValuesSeparator + categoryObj.CategoryID + ValuesSeparator, ValuesSeparator);
                hidHash.Value = ValidationHelper.GetHashString(hidItem.Value, new HashSettings(mSecurityPurpose));
                pnlHidden.Update();
            }

            // Preselect parent category
            CategoryInfo parentCategory = CategoryInfoProvider.GetCategoryInfo(categoryObj.CategoryParentID);
            if (parentCategory != null)
            {
                SelectedCategoryID = parentCategory.CategoryID;
                PreselectCategory(parentCategory, true);
            }
            else
            {
                SelectedCategoryID       = 0;
                SelectedCategoryParentID = categoryObj.CategoryIsPersonal ? PERSONAL_CATEGORIES_ROOT_PARENT_ID : CATEGORIES_ROOT_PARENT_ID;
            }

            // Delete category
            CategoryInfoProvider.DeleteCategoryInfo(categoryObj);

            pnlUpdateTrees.Update();
        }
    }
Esempio n. 4
0
    /// <summary>
    /// Deletes category. Called when the "Delete category" button is pressed.
    /// Expects the CreateCategory method to be run first.
    /// </summary>
    private bool DeleteCategory()
    {
        // Get the category
        CategoryInfo deleteCategory = CategoryInfoProvider.GetCategoryInfo("MyNewCategory", CMSContext.CurrentSiteName);

        // Delete the category
        CategoryInfoProvider.DeleteCategoryInfo(deleteCategory);

        return(deleteCategory != null);
    }
    private void DeleteCategory(CategoryInfo categoryObj)
    {
        // Check if category
        if ((categoryObj != null) && CanModifyCategory(categoryObj.CategoryIsPersonal, categoryObj.CategoryIsGlobal))
        {
            CategoryInfo parentCategory = CategoryInfoProvider.GetCategoryInfo(categoryObj.CategoryParentID);

            // Check if deleted category has parent
            if (parentCategory != null)
            {
                // Switch to editing of parent category
                SwitchToEdit();
                catEdit.UserID   = parentCategory.CategoryUserID;
                catEdit.Category = parentCategory;
                catEdit.ReloadData();

                SelectedCategoryID = parentCategory.CategoryID;
                PreselectCategory(parentCategory, false);
            }
            else
            {
                SelectedCategoryID       = 0;
                SelectedCategoryParentID = categoryObj.CategoryIsPersonal ? PERSONAL_CATEGORIES_ROOT_PARENT_ID : CATEGORIES_ROOT_PARENT_ID;
                SwitchToInfo();
            }

            // Delete category
            CategoryInfoProvider.DeleteCategoryInfo(categoryObj);

            // Reload subcategories
            gridSubCategories.ReloadData();

            pnlUpdateTree.Update();
            pnlUpdateContent.Update();
        }
    }