Exemple #1
0
    /// <summary>
    /// Gets and bulk updates avatars. Called when the "Get and bulk update avatars" button is pressed.
    /// Expects the CreateAvatar method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateAvatars()
    {
        // Prepare the parameters
        string where = "AvatarName LIKE N'MyNewAvatar%'";

        // Get the data
        DataSet avatars = AvatarInfoProvider.GetAvatars(where, null);

        if (!DataHelper.DataSourceIsEmpty(avatars))
        {
            // Loop through the individual items
            foreach (DataRow avatarDr in avatars.Tables[0].Rows)
            {
                // Create object from DataRow
                AvatarInfo modifyAvatar = new AvatarInfo(avatarDr);

                // Update the properties
                modifyAvatar.AvatarName = modifyAvatar.AvatarName.ToUpper();

                // Save the changes
                AvatarInfoProvider.SetAvatarInfo(modifyAvatar);
            }

            return(true);
        }

        return(false);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        ScriptHelper.RegisterWOpenerScript(Page);

        // Get resource strings
        Page.Title             = GetString("avatars.gallery.title");
        lblInfo.ResourceString = "avat.noavatarsfound";

        // Resolve avatar url
        avatarUrl = ResolveUrl("~/CMSModules/Avatars/CMSPages/GetAvatar.aspx?maxsidesize=" + maxSideSize + "&avatarguid=");
        avatarUrl = HTMLHelper.EncodeForHtmlAttribute(avatarUrl);
        // Get avatar type from querystring
        string avatarType = QueryHelper.GetString("avatartype", "all");

        AvatarType = AvatarInfoProvider.GetAvatarTypeEnum(avatarType);

        // Get all avatars form database
        var data = getAvatars();

        if (data.Any())
        {
            repAvatars.DataSource = data;
            repAvatars.DataBind();
            pnlAvatars.Visible = true;
        }
        else
        {
            lblInfo.Visible    = true;
            repAvatars.Visible = false;
        }
    }
 /// <summary>
 /// Replaces existing avatar by the new one
 /// </summary>
 /// <param name="ai">Existing avatar info</param>
 private void ReplaceExistingAvatar(AvatarInfo ai)
 {
     AvatarInfoProvider.UploadAvatar(ai, uplFilePicture.PostedFile,
                                     SettingsKeyInfoProvider.GetIntValue(site.SiteName + ".CMSGroupAvatarWidth"),
                                     SettingsKeyInfoProvider.GetIntValue(site.SiteName + ".CMSGroupAvatarHeight"),
                                     SettingsKeyInfoProvider.GetIntValue(site.SiteName + ".CMSGroupAvatarMaxSideSize"));
 }
Exemple #4
0
    /// <summary>
    /// Gets avatars from database.
    /// </summary>
    /// <returns>dataset</returns>
    private DataSet getAvatars()
    {
        // Get the data
        int currentPage = QueryHelper.GetInteger("tpage", pgrAvatars.CurrentPage);

        int currentGroup = currentPage / pgrAvatars.GroupSize + 1;
        int topN         = currentGroup * pgrAvatars.GroupSize * pgrAvatars.PageSize + pgrAvatars.PageSize;
        // Execute query
        DataSet ds = null;

        switch (this.AvatarType)
        {
        case AvatarTypeEnum.Group:
            ds = AvatarInfoProvider.GetAvatars("AvatarName, AvatarGUID", "AvatarType IN ('group','all') AND AvatarIsCustom = 0", null, topN);
            break;

        case AvatarTypeEnum.User:
            ds = AvatarInfoProvider.GetAvatars("AvatarName, AvatarGUID", "AvatarType IN ('user','all') AND AvatarIsCustom = 0", null, topN);
            break;

        case AvatarTypeEnum.All:
        default:
            ds = AvatarInfoProvider.GetAvatars("AvatarName, AvatarGUID", "AvatarType = 'all' AND AvatarIsCustom = 0", null, topN);
            break;
        }
        return(ds);
    }
    /// <summary>
    /// Processes the file.
    /// </summary>
    protected void ProcessFile()
    {
        if (fileGuid == Guid.Empty)
        {
            return;
        }

        // Get the avatar
        var avatar = AvatarInfoProvider.GetAvatarInfoWithoutBinary(fileGuid);

        if (avatar == null)
        {
            return;
        }

        bool resizeImage = (ImageHelper.IsImage(avatar.AvatarFileExtension) && AvatarInfoProvider.CanResizeImage(avatar, Width, Height, MaxSideSize));

        // Get the data
        if ((outputFile == null) || (outputFile.Avatar == null))
        {
            outputFile             = new CMSOutputAvatar(avatar, null);
            outputFile.Width       = Width;
            outputFile.Height      = Height;
            outputFile.MaxSideSize = MaxSideSize;
            outputFile.Resized     = resizeImage;
        }
    }
 /// <summary>
 /// Clears default group avatar which is assigned to avatarinfo.
 /// </summary>
 private static void ClearDefaultGroupAvatar(AvatarInfo ai)
 {
     if (ai.DefaultGroupAvatar)
     {
         AvatarInfoProvider.ClearDefaultAvatar(DefaultAvatarTypeEnum.Group);
     }
 }
 /// <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)
     {
         AvatarInfoProvider.DeleteAvatarFile(avatar.AvatarGUID.ToString(), avatar.AvatarFileExtension, false, false);
         AvatarInfo.Provider.Delete(avatar);
     }
 }
    /// <summary>
    /// Updates avatar represented by control's Value.
    /// </summary>
    private void UpdateAvatar()
    {
        // Try to get avatar info
        AvatarInfo avatar = null;

        if (avatarID > 0)
        {
            avatar = AvatarInfoProvider.GetAvatarInfoWithoutBinary(avatarID);
        }

        if (rdbMode.SelectedValue == AvatarInfoProvider.AVATAR)
        {
            // If some new picture was uploaded
            if (IsNewPictureUploaded())
            {
                avatar = StoreUploadedPicture(avatarID, EditedUser);
                hiddenDeleteAvatar.Value = String.Empty;
            }
            // If some predefined avatar was selected
            else if (!string.IsNullOrEmpty(hiddenAvatarGuid.Value))
            {
                DeleteCustomAvatar(avatar);

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

        if (ValidationHelper.GetBoolean(hiddenDeleteAvatar.Value, false))
        {
            // Avatar has to be deleted
            DeleteCustomAvatar(avatar);
            hiddenDeleteAvatar.Value = String.Empty;
            avatar = null;
        }

        // Update avatar id
        avatarID = (avatar != null) ? avatar.AvatarID : 0;
        if (EditedUser != null)
        {
            // Save avatar type for user given by basic form
            EditedUser.UserSettings.UserAvatarType = rdbMode.SelectedValue;
            EditedUser.UserAvatarID = avatarID;
            UserInfoProvider.SetUserInfo(EditedUser);

            ShowUserAvatar(EditedUser);
        }
        else if (avatarID > 0)
        {
            ShowAvatar(avatarID);
        }
        else
        {
            HideAvatar();
        }
    }
    /// <summary>
    /// Sets image  url, width and height.
    /// </summary>
    protected void SetImage()
    {
        Visible = false;

        // Only if display picture is allowed
        if (DisplayPicture)
        {
            string imageUrl = ResolveUrl("~/getavatar/{0}/avatar");

            // Is user id set? => Get user info
            if (UserID > 0)
            {
                // Get user info
                UserInfo ui = UserInfo.Provider.Get(UserID);
                if (ui != null)
                {
                    AvatarID = ui.UserAvatarID;
                }
            }


            if (AvatarID > 0)
            {
                AvatarInfo ai = AvatarInfoProvider.GetAvatarInfoWithoutBinary(AvatarID);
                if (ai != null)
                {
                    imageUrl = String.Format(imageUrl, ai.AvatarGUID);
                    imageUrl = URLHelper.AppendQuery(imageUrl, "lastModified=" + SecurityHelper.GetSHA2Hash(ai.AvatarLastModified.ToString()));
                    Visible  = true;
                }
            }


            // If item was found
            if (Visible)
            {
                if (KeepAspectRatio)
                {
                    imageUrl += "&maxsidesize=" + (Width > Height ? Width : Height);
                }
                else
                {
                    imageUrl += "&width=" + Width + "&height=" + Height;
                }

                imageUrl      = HTMLHelper.EncodeForHtmlAttribute(imageUrl);
                ltlImage.Text = "<img alt=\"" + GetString("general.avatar") + "\" src=\"" + imageUrl + "\" />";

                // Render outer div with specific CSS class
                if (RenderOuterDiv)
                {
                    ltlImage.Text = "<div class=\"" + OuterDivCSSClass + "\">" + ltlImage.Text + "</div>";
                }
            }
        }
    }
        public void UploadUserAvatar(MedioClinicUser user, byte[] avatarBinary)
        {
            var avatarInfo = AvatarInfoProvider.GetAvatarInfo(user.AvatarId);

            if (avatarInfo != null)
            {
                avatarInfo.AvatarBinary = avatarBinary;
                AvatarInfoProvider.SetAvatarInfo(avatarInfo);
            }
        }
Exemple #11
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);
    }
        public int CreateUserAvatar(string filePath, string avatarName)
        {
            var newAvatar = new AvatarInfo(filePath);

            newAvatar.AvatarName     = avatarName ?? string.Empty;
            newAvatar.AvatarType     = AvatarInfoProvider.GetAvatarTypeString(AvatarTypeEnum.User);
            newAvatar.AvatarIsCustom = true;
            AvatarInfoProvider.SetAvatarInfo(newAvatar);

            return(newAvatar.AvatarID);
        }
        public (string fileName, byte[] binary) GetUserAvatar(MedioClinicUser user)
        {
            var avatarInfo = AvatarInfoProvider.GetAvatarInfo(user.AvatarId);

            if (avatarInfo != null)
            {
                return($"{avatarInfo.AvatarGUID}{avatarInfo.AvatarFileExtension}", avatarInfo.AvatarBinary);
            }

            return(null, null);
        }
 public void RaisePostBackEvent(string eventArgument)
 {
     if (eventArgument == "shared")
     {
         if ((ai != null) && (ai.AvatarIsCustom))
         {
             ai.AvatarIsCustom = false;
             AvatarInfoProvider.SetAvatarInfo(ai);
             URLHelper.Redirect(URLHelper.AddParameterToUrl(RequestContext.CurrentURL, "saved", "1"));
         }
     }
 }
Exemple #15
0
    /// <summary>
    /// Creates avatar. Called when the "Create avatar" button is pressed.
    /// </summary>
    private bool CreateAvatar()
    {
        // Create new avatar object
        AvatarInfo newAvatar = new AvatarInfo(Server.MapPath("~\\CMSAPIExamples\\Code\\Community\\Avatars\\Files\\avatar_man.jpg"));

        // Set the properties
        newAvatar.AvatarName     = "MyNewAvatar";
        newAvatar.AvatarType     = AvatarInfoProvider.GetAvatarTypeString(AvatarTypeEnum.All);
        newAvatar.AvatarIsCustom = false;

        // Save the avatar
        AvatarInfoProvider.SetAvatarInfo(newAvatar);

        return(true);
    }
Exemple #16
0
    /// <summary>
    /// Gets the Disqus SSO payload based on whether the user is authenticated or not
    /// </summary>
    /// <returns>SSO payload</returns>
    private string GetPayload()
    {
        var user = CurrentUser;

        if (!user.IsPublic())
        {
            //TODO: Improve user profile URL (take from "Member profile path" setting) + parametrize user properties
            return(GetPayloadForAuthenticatedUser(user.UserID.ToString(), user.FullName, user.Email,
                                                  URLHelper.GetAbsoluteUrl(AvatarInfoProvider.GetUserAvatarImageUrl(user.UserAvatarID, null, null, 0, 0, 0)),
                                                  URLHelper.GetAbsoluteUrl("TODO")));
        }
        else
        {
            return(GetPayloadForAnonymousUser());
        }
    }
    /// <summary>
    /// Clears default user avatars which is assigned to avatarinfo.
    /// </summary>
    private static void ClearDefaultUserAvatars(AvatarInfo ai)
    {
        if (ai.DefaultUserAvatar)
        {
            AvatarInfoProvider.ClearDefaultAvatar(DefaultAvatarTypeEnum.User);
        }

        if (ai.DefaultMaleUserAvatar)
        {
            AvatarInfoProvider.ClearDefaultAvatar(DefaultAvatarTypeEnum.Male);
        }

        if (ai.DefaultFemaleUserAvatar)
        {
            AvatarInfoProvider.ClearDefaultAvatar(DefaultAvatarTypeEnum.Female);
        }
    }
 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);
         }
     }
 }
    /// <summary>
    /// Creates a new avatar object.
    /// </summary>
    /// <param name="ui"> Username of given user is used for avatar name.</param>
    private AvatarInfo CreateAvatar(UserInfo ui)
    {
        AvatarInfo ai = new AvatarInfo(uplFilePicture.PostedFile.ToUploadedFile(),
                                       SettingsKeyInfoProvider.GetIntValue(SiteContext.CurrentSiteName + ".CMSAvatarWidth"),
                                       SettingsKeyInfoProvider.GetIntValue(SiteContext.CurrentSiteName + ".CMSAvatarHeight"),
                                       SettingsKeyInfoProvider.GetIntValue(SiteContext.CurrentSiteName + ".CMSAvatarMaxSideSize"));

        if ((ui == null) && (MembershipContext.AuthenticatedUser != null) && AuthenticationHelper.IsAuthenticated() && PortalContext.ViewMode.IsLiveSite())
        {
            ui = MembershipContext.AuthenticatedUser;
        }

        ai.AvatarName = AvatarInfoProvider.GetUniqueAvatarName($"custom {ui.UserName}");

        ai.AvatarGUID = Guid.NewGuid();

        return(ai);
    }
Exemple #20
0
    /// <summary>
    /// Gets and updates avatar. Called when the "Get and update avatar" button is pressed.
    /// Expects the CreateAvatar method to be run first.
    /// </summary>
    private bool GetAndUpdateAvatar()
    {
        // Get the avatar
        AvatarInfo updateAvatar = AvatarInfoProvider.GetAvatarInfo("MyNewAvatar");

        if (updateAvatar != null)
        {
            // Update the properties
            updateAvatar.AvatarName = updateAvatar.AvatarName.ToLower();

            // Save the changes
            AvatarInfoProvider.SetAvatarInfo(updateAvatar);

            return(true);
        }

        return(false);
    }
Exemple #21
0
    /// <summary>
    /// Adds avatar to user. Called when the "Add avatar to user" button is pressed.
    /// Expects the CreateAvatar method to be run first.
    /// </summary>
    private bool AddAvatarToUser()
    {
        // Get the avatar and user
        AvatarInfo avatar = AvatarInfoProvider.GetAvatarInfo("MyNewAvatar");
        UserInfo   user   = UserInfoProvider.GetUserInfo(CMSContext.CurrentUser.UserName);

        if ((avatar != null) && (user != null))
        {
            user.UserAvatarID = avatar.AvatarID;

            // Save edited object
            UserInfoProvider.SetUserInfo(user);

            return(true);
        }

        return(false);
    }
    /// <summary>
    /// Deletes picture of given user.
    /// </summary>
    /// <param name="user">User info object.</param>
    public static void DeleteOldUserPicture(UserInfo user)
    {
        // Delete old picture if needed
        if (user.UserAvatarID != 0)
        {
            // Delete avatar info if needed
            AvatarInfo avatar = AvatarInfoProvider.GetAvatarInfoWithoutBinary(user.UserAvatarID);
            if (avatar != null)
            {
                DeleteCustomAvatar(avatar);

                user.UserAvatarID = 0;
                UserInfoProvider.SetUserInfo(user);
                if (user.UserID == MembershipContext.AuthenticatedUser.UserID)
                {
                    MembershipContext.AuthenticatedUser.UserAvatarID = 0;
                }
            }
        }
        // Backward compatibility
        else if (user.UserPicture != "")
        {
            try
            {
                // Remove avatar from file system
                string jDirectory = HttpContext.Current.Server.MapPath("~/CMSGlobalFiles/UserPictures/");
                string filename   = user.UserPicture.Remove(user.UserPicture.IndexOfCSafe('/'));
                if (File.Exists(jDirectory + filename))
                {
                    File.Delete(jDirectory + filename);
                }
            }
            catch
            {
            }

            user.UserPicture = "";
            UserInfoProvider.SetUserInfo(user);
            if (user.UserID == MembershipContext.AuthenticatedUser.UserID)
            {
                MembershipContext.AuthenticatedUser.UserPicture = "";
            }
        }
    }
    /// <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 = "";
        }
    }
Exemple #24
0
    protected void Page_Load(object sender, EventArgs e)
    {
        AvatarInfo ai = null;

        if (mValue > 0)
        {
            ai = AvatarInfoProvider.GetAvatarInfo(mValue);
        }

        if (ai == null)
        {
            DefaultAvatarTypeEnum defAvatar = DefaultAvatarTypeEnum.User;
            UserGenderEnum        gender    = (UserGenderEnum)ValidationHelper.GetInteger(Form.GetFieldValue("UserGender"), 0);
            switch (gender)
            {
            case UserGenderEnum.Female:
                defAvatar = DefaultAvatarTypeEnum.Female;
                break;

            case UserGenderEnum.Male:
                defAvatar = DefaultAvatarTypeEnum.Male;
                break;
            }

            ai = AvatarInfoProvider.GetDefaultAvatar(defAvatar);

            // Avatar not specified for current gender, get user default avatar
            if (ai == null)
            {
                ai = AvatarInfoProvider.GetDefaultAvatar(DefaultAvatarTypeEnum.User);
            }
        }

        if (ai != null)
        {
            imgAvatar.ImageUrl      = ResolveUrl("~/CMSModules/Avatars/CMSPages/GetAvatar.aspx?avatarguid=" + ai.AvatarGUID + "&maxsidesize=" + MaxSideSize);
            imgAvatar.AlternateText = GetString("general.avatar");
            return;
        }

        imgAvatar.Visible = false;
    }
    /// <summary>
    /// Deletes picture of given user.
    /// </summary>
    /// <param name="user">User info object.</param>
    public static void DeleteOldUserPicture(UserInfo user)
    {
        // Delete old picture if needed
        if (user.UserAvatarID != 0)
        {
            // Delete avatar info if needed
            AvatarInfo avatar = AvatarInfoProvider.GetAvatarInfoWithoutBinary(user.UserAvatarID);
            if (avatar != null)
            {
                DeleteCustomAvatar(avatar);

                user.UserAvatarID = 0;
                UserInfo.Provider.Set(user);
                if (user.UserID == MembershipContext.AuthenticatedUser.UserID)
                {
                    MembershipContext.AuthenticatedUser.UserAvatarID = 0;
                }
            }
        }
    }
    /// <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 given user's picture using values of this control.
    /// </summary>
    /// <param name="user">User info object.</param>
    public void UpdateUserPicture(UserInfo user)
    {
        AvatarInfo avatar = null;

        // Check if some avatar should be deleted
        if (ValidationHelper.GetBoolean(hiddenDeleteAvatar.Value, false))
        {
            DeleteOldUserPicture(user);
            hiddenDeleteAvatar.Value = String.Empty;
        }

        if (rdbMode.SelectedValue == AvatarInfoProvider.AVATAR)
        {
            // If some file was uploaded
            if (IsNewPictureUploaded())
            {
                avatar = StoreUploadedPictureForUser(user);
            }
            // If predefined was chosen
            else if (!string.IsNullOrEmpty(hiddenAvatarGuid.Value))
            {
                // Delete old picture
                DeleteOldUserPicture(user);

                // Get predefined avatar by GUID
                Guid guid = ValidationHelper.GetGuid(hiddenAvatarGuid.Value, Guid.NewGuid());
                avatar = AvatarInfoProvider.GetAvatarInfoWithoutBinary(guid);
                hiddenAvatarGuid.Value = String.Empty;
            }
        }

        // Save user changes and show new avatar
        user.UserSettings.UserAvatarType = rdbMode.SelectedValue;
        if (avatar != null)
        {
            avatarID = user.UserAvatarID = avatar.AvatarID;
        }

        UserInfoProvider.SetUserInfo(user);
        ShowUserAvatar(user);
    }
Exemple #28
0
    /// <summary>
    /// Processes the specified file.
    /// </summary>
    /// <param name="fileGuid">File guid</param>
    protected void ProcessFile(Guid fileGuid)
    {
        // Get the file
        AvatarInfo fileInfo = AvatarInfoProvider.GetAvatarInfoWithoutBinary(fileGuid);

        if (fileInfo != null)
        {
            bool resizeImage = (ImageHelper.IsImage(fileInfo.AvatarFileExtension) &&
                                AvatarInfoProvider.CanResizeImage(fileInfo, this.Width, this.Height, this.MaxSideSize));

            // Get the data
            if ((outputFile == null) || (outputFile.Avatar == null))
            {
                outputFile             = new CMSOutputAvatar(fileInfo, null);
                outputFile.Width       = this.Width;
                outputFile.Height      = this.Height;
                outputFile.MaxSideSize = this.MaxSideSize;
                outputFile.Resized     = resizeImage;
            }
        }
    }
Exemple #29
0
    /// <summary>
    /// Gets and bulk updates avatars. Called when the "Get and bulk update avatars" button is pressed.
    /// Expects the CreateAvatar method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateAvatars()
    {
        // Prepare the parameters
        string where = "AvatarName LIKE N'MyNewAvatar%'";

        // Get the data from database
        var avatars = AvatarInfoProvider.GetAvatars().Where(where);

        // Loop through the individual items
        foreach (AvatarInfo modifyAvatar in avatars)
        {
            // Update the properties
            modifyAvatar.AvatarName = modifyAvatar.AvatarName.ToUpper();

            // Save the changes
            AvatarInfoProvider.SetAvatarInfo(modifyAvatar);
        }

        // Return TRUE if any object was found and updated, FALSE otherwise
        return(avatars.Count > 0);
    }
    /// <summary>
    /// Gets avatars from database.
    /// </summary>
    private ObjectQuery <AvatarInfo> getAvatars()
    {
        // Get the data
        int currentPage = QueryHelper.GetInteger("tpage", pgrAvatars.CurrentPage);

        int currentGroup = currentPage / pgrAvatars.GroupSize + 1;
        int topN         = currentGroup * pgrAvatars.GroupSize * pgrAvatars.UniPager.PageSize + pgrAvatars.UniPager.PageSize;

        // Execute query
        switch (AvatarType)
        {
        case AvatarTypeEnum.Group:
            return(AvatarInfoProvider.GetAvatars().Where("AvatarType IN ('group','all') AND AvatarIsCustom = 0").TopN(topN).Columns("AvatarName, AvatarGUID"));

        case AvatarTypeEnum.User:
            return(AvatarInfoProvider.GetAvatars().Where("AvatarType IN ('user','all') AND AvatarIsCustom = 0").TopN(topN).Columns("AvatarName, AvatarGUID"));

        default:
            return(AvatarInfoProvider.GetAvatars().Where("AvatarType = 'all' AND AvatarIsCustom = 0").TopN(topN).Columns("AvatarName, AvatarGUID"));
        }
    }