Kentico CMS 6.0 Developer's Guide

Managing widget categories

Managing widget categories

Previous topic Next topic Mail us feedback on this topic!  

Managing widget categories

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

Arrow


API examples for newer versions


Please visit the latest API Examples documentation to view API examples for newer versions of Kentico.



The following example creates a widget category.

 

private void CreateWidgetCategory()
{
    // Create new widget category object
    WidgetCategoryInfo newCategory = new WidgetCategoryInfo();
 
    // Set the properties
    newCategory.WidgetCategoryDisplayName = "My new category";
    newCategory.WidgetCategoryName = "MyNewCategory";
 
    // Save the widget category
    WidgetCategoryInfoProvider.SetWidgetCategoryInfo(newCategory);    
}

 

The following example gets and updates a widget category.

 

private bool GetAndUpdateWidgetCategory()
{

  // Get the widget category
  WidgetCategoryInfo updateCategory = WidgetCategoryInfoProvider.GetWidgetCategoryInfo("MyNewCategory");

    if (updateCategory != null)
    {

      // Update the properties
       updateCategory.WidgetCategoryDisplayName = updateCategory.WidgetCategoryDisplayName.ToLower();

 
        // Save the changes
        WidgetCategoryInfoProvider.SetWidgetCategoryInfo(updateCategory);
 
        return true;
    }
 
    return false;
}

 

The following example gets and bulk updates widget categories.

 

private bool GetAndBulkUpdateWidgetCategories()
{
    // Prepare the parameters
    string where = "WidgetCategoryName LIKE N'MyNewCategory%'";
    string orderBy = "";
    int topN = 0;
    string columns = "";

 

  // Get the data
  DataSet categories = WidgetCategoryInfoProvider.GetWidgetCategories(where, orderBy, topN, columns);

    if (!DataHelper.DataSourceIsEmpty(categories))
    {
        // Loop through the individual items
        foreach (DataRow categoryDr in categories.Tables[0].Rows)
        {
            // Create object from DataRow
            WidgetCategoryInfo modifyCategory = new WidgetCategoryInfo(categoryDr);

 
          // Update the properties
           modifyCategory.WidgetCategoryDisplayName = modifyCategory.WidgetCategoryDisplayName.ToUpper();

 
            // Save the changes
            WidgetCategoryInfoProvider.SetWidgetCategoryInfo(modifyCategory);
        }
 
        return true;
    }
 
    return false;
}

 

The following example deletes a widget category.

 

private bool DeleteWidgetCategory()
{

  // Get the widget category
  WidgetCategoryInfo deleteCategory = WidgetCategoryInfoProvider.GetWidgetCategoryInfo("MyNewCategory");

 
    // Delete the widget category
    WidgetCategoryInfoProvider.DeleteWidgetCategoryInfo(deleteCategory);
 
    return (deleteCategory != null);
}