Avatars
List of examples:
- Creating an avatar
- Updating an avatar
- Updating multiple avatars
- Assigning an avatar to a user
- Removing an avatar from a user
- Deleting avatars
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);
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);
}
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);
}
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);
}
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);
}
Deleting avatars
// Gets the avatar
AvatarInfo deleteAvatar = AvatarInfoProvider.GetAvatarInfo("NewAvatar");
if (deleteAvatar != null)
{
// Deletes the avatar
AvatarInfoProvider.DeleteAvatarInfo(deleteAvatar);
}