Kentico CMS 7.0 Developer's Guide

Managing badges

Managing badges

Previous topic Next topic Mail us feedback on this topic!  

Managing badges

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 badge.

 

private void CreateBadge()
{
    // Create new badge object
    BadgeInfo newBadge = new BadgeInfo();
 
    // Set the properties
    newBadge.BadgeDisplayName = "My new badge";
    newBadge.BadgeName = "MyNewBadge";
    newBadge.BadgeTopLimit = 50;

   newBadge.BadgeImageURL = "~/App_Themes/Default/Images/Objects/CMS_Badge/Default/siteadmin.gif";

    newBadge.BadgeIsAutomatic = true;
 
    // Save the badge
    BadgeInfoProvider.SetBadgeInfo(newBadge);
}

 

The following example gets and updates a badge.

 

private bool GetAndUpdateBadge()
{
    // Get the badge
    BadgeInfo updateBadge = BadgeInfoProvider.GetBadgeInfo("MyNewBadge");
    if (updateBadge != null)
    {
        // Update the properties
        updateBadge.BadgeDisplayName = updateBadge.BadgeDisplayName.ToLower();
 
        // Save the changes
        BadgeInfoProvider.SetBadgeInfo(updateBadge);
 
        return true;
    }
 
    return false;
}

 

The following example gets and bulk updates badges.

 

private bool GetAndBulkUpdateBadges()
{
    // Prepare the parameters
    string where = "BadgeName LIKE N'MyNewBadge%'";
 
    // Get the data
    DataSet badges = BadgeInfoProvider.GetBadges(where, null);
    if (!DataHelper.DataSourceIsEmpty(badges))
    {
        // Loop through the individual items
        foreach (DataRow badgeDr in badges.Tables[0].Rows)
        {
            // Create object from DataRow
            BadgeInfo modifyBadge = new BadgeInfo(badgeDr);

 
          // Update the properties
           modifyBadge.BadgeDisplayName = modifyBadge.BadgeDisplayName.ToUpper();

 
            // Save the changes
            BadgeInfoProvider.SetBadgeInfo(modifyBadge);
        }
 
        return true;
    }
 
    return false;
}

 

The following example deletes a badge.

 

private bool DeleteBadge()
{
    // Get the badge
    BadgeInfo deleteBadge = BadgeInfoProvider.GetBadgeInfo("MyNewBadge");
 
    // Delete the badge
    BadgeInfoProvider.DeleteBadgeInfo(deleteBadge);
 
    return (deleteBadge != null);
}