The following example assigns a badge to a specific user.
privatebool AddBadgeToUser() { // Get user object UserInfo user = UserInfoProvider.GetUserInfo(CMSContext.CurrentUser.UserName); // Get badge object BadgeInfo myBadge = BadgeInfoProvider.GetBadgeInfo("MyNewBadge"); if ((user != null) && (myBadge != null)) { // Add badge to user settings user.UserSettings.UserBadgeID = myBadge.BadgeID; // Update user object in database UserInfoProvider.SetUserInfo(user); returntrue; } returnfalse; }
The following example updates the activity points of a specific user.
privatebool UpdateActivityPoints() { // Get user UserInfo user = UserInfoProvider.GetUserInfo(CMSContext.CurrentUser.UserName); // If user exists if (user != null) {
// Update activity points of the user BadgeInfoProvider.UpdateActivityPointsToUser(ActivityPointsEnum.BlogCommentPost, user.UserID, CMSContext.CurrentSiteName, true);
returntrue; } returnfalse; }
The following example removes a user's badge.
privatebool RemoveBadgeFromUser() {
// Get user UserInfo user = UserInfoProvider.GetUserInfo(CMSContext.CurrentUser.UserName);
// If user exists if (user != null) { user.UserSettings.UserBadgeID = 0; // Save updates UserInfoProvider.SetUserInfo(user); returntrue; } returnfalse; }