Avatars


List of examples:

Creating an avatar




// Creates a new avatar object based on an image file
AvatarInfo newAvatar = new AvatarInfo(System.Web.HttpContext.Current.Server.MapPath("~\\Avatars\\Files\\avatar_man.jpg"));

// Sets the avatar properties
newAvatar.AvatarName = "NewAvatar";
newAvatar.AvatarType = AvatarInfoProvider.GetAvatarTypeString(AvatarTypeEnum.All);
newAvatar.AvatarIsCustom = false;

// Saves the avatar to the database
AvatarInfoProvider.SetAvatarInfo(newAvatar);


> Back to list of examples

Updating an avatar




// Gets the avatar
AvatarInfo updateAvatar = AvatarInfoProvider.GetAvatarInfo("NewAvatar");
if (updateAvatar != null)
{
    // Updates the avatar properties
    updateAvatar.AvatarName = updateAvatar.AvatarName.ToLower();

    // Saves the changes to the database
    AvatarInfoProvider.SetAvatarInfo(updateAvatar);
}


> Back to list of examples

Updating multiple avatars




// Gets all avatars whose name starts with 'New'
var avatars = AvatarInfoProvider.GetAvatars().WhereStartsWith("AvatarName", "New");

// Loops through individual avatars
foreach (AvatarInfo modifyAvatar in avatars)
{
    // Updates the avatar properties
    modifyAvatar.AvatarName = modifyAvatar.AvatarName.ToUpper();

    // Saves the changes to the database
    AvatarInfoProvider.SetAvatarInfo(modifyAvatar);
}


> Back to list of examples

Assigning an avatar to a user




// Gets the avatar and the user
AvatarInfo avatar = AvatarInfoProvider.GetAvatarInfo("NewAvatar");
UserInfo user = UserInfoProvider.GetUserInfo("Andy");

if ((avatar != null) && (user != null))
{
    // Assigns the avatar to the user
    user.UserAvatarID = avatar.AvatarID;

    // Saves the updated user to the database
    UserInfoProvider.SetUserInfo(user);
}


> Back to list of examples

Removing an avatar from a user




// Gets the user
UserInfo user = UserInfoProvider.GetUserInfo("Andy");

if (user != null)
{
    // Removes the user's current avatar
    user.UserAvatarID = 0;

    // Saves the updated user to the database
    UserInfoProvider.SetUserInfo(user);
}


> Back to list of examples

Deleting avatars




// Gets the avatar
AvatarInfo deleteAvatar = AvatarInfoProvider.GetAvatarInfo("NewAvatar");

if (deleteAvatar != null)
{
    // Deletes the avatar
    AvatarInfoProvider.DeleteAvatarInfo(deleteAvatar);
}


> Back to list of examples