/// <summary>
 /// Deletes given custom avatar. Does nothing when given avatar is not custom.
 /// </summary>
 /// <param name="avatar">Avatar to delete.</param>
 private static void DeleteCustomAvatar(AvatarInfo avatar)
 {
     // Delete avatar if some exists and is custom
     if ((avatar != null) && (avatar.AvatarIsCustom))
     {
         AvatarInfoProvider.DeleteAvatarFile(avatar.AvatarGUID.ToString(), avatar.AvatarFileExtension, false, false);
         AvatarInfoProvider.DeleteAvatarInfo(avatar);
     }
 }
コード例 #2
0
    /// <summary>
    /// Deletes avatar. Called when the "Delete avatar" button is pressed.
    /// Expects the CreateAvatar method to be run first.
    /// </summary>
    private bool DeleteAvatar()
    {
        // Get the avatar
        AvatarInfo deleteAvatar = AvatarInfoProvider.GetAvatarInfo("MyNewAvatar");

        // Delete the avatar
        AvatarInfoProvider.DeleteAvatarInfo(deleteAvatar);

        return(deleteAvatar != null);
    }
 protected void unigridAvatarList_OnAction(string actionName, object actionArgument)
 {
     // Edit action
     if (DataHelper.GetNotEmpty(actionName, String.Empty) == "edit")
     {
         URLHelper.Redirect(UrlResolver.ResolveUrl("Avatar_Edit.aspx?avatarid=" + (string)actionArgument));
     }
     // Delete action
     else if (DataHelper.GetNotEmpty(actionName, String.Empty) == "delete")
     {
         int avatarId = ValidationHelper.GetInteger(actionArgument, 0);
         if (avatarId > 0)
         {
             AvatarInfoProvider.DeleteAvatarInfo(avatarId);
         }
     }
 }
コード例 #4
0
    /// <summary>
    /// Deletes user picture.
    /// </summary>
    /// <param name="ui">UserInfo</param>
    public static void DeleteOldUserPicture(UserInfo ui)
    {
        // Delete old picture if needed
        if (ui.UserAvatarID != 0)
        {
            // Delete avatar info provider if needed
            AvatarInfo ai = AvatarInfoProvider.GetAvatarInfoWithoutBinary(ui.UserAvatarID);
            if (ai != null)
            {
                if (ai.AvatarIsCustom)
                {
                    AvatarInfoProvider.DeleteAvatarFile(ai.AvatarGUID.ToString(), ai.AvatarFileExtension, false, false);
                    AvatarInfoProvider.DeleteAvatarInfo(ai);
                }

                ui.UserAvatarID = 0;
                UserInfoProvider.SetUserInfo(ui);
                CMSContext.CurrentUser.UserAvatarID = 0;
            }
        }
        // Backward compatibility
        else if (ui.UserPicture != "")
        {
            try
            {
                // Remove from HDD
                string jDirectory = HttpContext.Current.Server.MapPath("~/CMSGlobalFiles/UserPictures/");
                string filename   = ui.UserPicture.Remove(ui.UserPicture.IndexOf('/'));
                if (File.Exists(jDirectory + filename))
                {
                    File.Delete(jDirectory + filename);
                }
            }
            catch
            {
            }

            ui.UserPicture = "";
            UserInfoProvider.SetUserInfo(ui);
            CMSContext.CurrentUser.UserPicture = "";
        }
    }
    /// <summary>
    /// Deletes group picture.
    /// </summary>
    /// <param name="gi">GroupInfo</param>
    public static void DeleteOldGroupPicture(GroupInfo gi)
    {
        // Delete old picture if needed
        if (gi.GroupAvatarID != 0)
        {
            // Delete avatar info provider if needed
            AvatarInfo ai = AvatarInfoProvider.GetAvatarInfoWithoutBinary(gi.GroupAvatarID);
            if (ai != null)
            {
                if (ai.AvatarIsCustom)
                {
                    AvatarInfoProvider.DeleteAvatarInfo(ai);
                    AvatarInfoProvider.DeleteAvatarFile(ai.AvatarGUID.ToString(), ai.AvatarFileExtension, false, false);
                }

                gi.GroupAvatarID = 0;
                GroupInfoProvider.SetGroupInfo(gi);
            }
        }
    }
    /// <summary>
    /// Updates picture of current group.
    /// </summary>
    /// <param name="gi">Group info object</param>
    public void UpdateGroupPicture(GroupInfo gi)
    {
        AvatarInfo ai = null;

        if (gi != null)
        {
            // Delete avatar if needed
            if (ValidationHelper.GetBoolean(hiddenDeleteAvatar.Value, false))
            {
                DeleteOldGroupPicture(gi);
            }

            // If some file was uploaded
            if ((uplFilePicture.PostedFile != null) && (uplFilePicture.PostedFile.ContentLength > 0) && ImageHelper.IsImage(Path.GetExtension(uplFilePicture.PostedFile.FileName)))
            {
                // Check if this group has some avatar and if so check if is custom
                ai = AvatarInfoProvider.GetAvatarInfoWithoutBinary(gi.GroupAvatarID);
                if ((ai != null) && ai.AvatarIsCustom)
                {
                    ReplaceExistingAvatar(ai);
                }
                else
                {
                    // Delete old picture
                    DeleteOldGroupPicture(gi);
                    ai = CreateNewAvatar();
                }

                AvatarInfoProvider.SetAvatarInfo(ai);

                // Update group info
                gi.GroupAvatarID = ai.AvatarID;
                GroupInfoProvider.SetGroupInfo(gi);


                plcImageActions.Visible = true;
            }
            // If predefined was chosen
            else if (!string.IsNullOrEmpty(hiddenAvatarGuid.Value))
            {
                // Delete old picture
                DeleteOldGroupPicture(gi);

                Guid guid = ValidationHelper.GetGuid(hiddenAvatarGuid.Value, Guid.NewGuid());
                ai = AvatarInfoProvider.GetAvatarInfoWithoutBinary(guid);

                // Update group info
                if (ai != null)
                {
                    gi.GroupAvatarID = ai.AvatarID;
                    GroupInfoProvider.SetGroupInfo(gi);
                }

                plcImageActions.Visible = true;
            }
            else
            {
                plcImageActions.Visible = false;
            }
        }
        else
        {
            bool pseudoDelete = ValidationHelper.GetBoolean(hiddenDeleteAvatar.Value, false);
            // Try to get avatar info
            if (avatarID != 0)
            {
                ai = AvatarInfoProvider.GetAvatarInfoWithoutBinary(avatarID);
            }

            // If some new picture was uploaded
            if ((uplFilePicture.PostedFile != null) && (uplFilePicture.PostedFile.ContentLength > 0) && ImageHelper.IsImage(Path.GetExtension(uplFilePicture.PostedFile.FileName)))
            {
                // Change delete to false because file will be replaced
                pseudoDelete = false;

                // If some avatar exists and is custom
                if ((ai != null) && (ai.AvatarIsCustom))
                {
                    // Delete file and upload new
                    AvatarInfoProvider.DeleteAvatarFile(ai.AvatarGUID.ToString(), ai.AvatarFileExtension, false, false);
                    ReplaceExistingAvatar(ai);
                }
                else
                {
                    ai = CreateNewAvatar();
                }

                // Update database
                AvatarInfoProvider.SetAvatarInfo(ai);
            }
            // If some predefined avatar was selected
            else if (!string.IsNullOrEmpty(hiddenAvatarGuid.Value))
            {
                // Change delete to false because file will be replaced
                pseudoDelete = false;

                // If some avatar exists and is custom
                if ((ai != null) && (ai.AvatarIsCustom))
                {
                    AvatarInfoProvider.DeleteAvatarFile(ai.AvatarGUID.ToString(), ai.AvatarFileExtension, false, false);
                    AvatarInfoProvider.DeleteAvatarInfo(ai);
                }

                Guid guid = ValidationHelper.GetGuid(hiddenAvatarGuid.Value, Guid.NewGuid());
                ai = AvatarInfoProvider.GetAvatarInfoWithoutBinary(guid);
            }

            // If file was deleted - not replaced
            if (pseudoDelete)
            {
                // Delete it
                ai = AvatarInfoProvider.GetAvatarInfoWithoutBinary(avatarID);
                if (ai != null)
                {
                    if (ai.AvatarIsCustom)
                    {
                        AvatarInfoProvider.DeleteAvatarInfo(ai);
                    }
                }

                ai       = null;
                avatarID = 0;
                plcImageActions.Visible = false;
                GroupPicture.AvatarID   = 0;
            }

            // Update avatar id
            if (ai != null)
            {
                GroupPicture.AvatarID   = avatarID = ai.AvatarID;
                plcImageActions.Visible = true;
            }
        }
    }