Пример #1
0
    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>
        /// This method uploads an avatar image
        /// </summary>
        /// <param name="server">HttpServerUtilityBase object. Used to map the server path</param>
        /// <param name="avatar">Contains the file bytes to save</param>
        /// <param name="id">The id to use for the image</param>
        /// <param name="avatarType">Currently canbe either Team or Player</param>
        /// <returns></returns>
        public static AvatarImage UploadFile2(HttpServerUtilityBase server, HttpPostedFileBase avatar, int id, AvatarTypeEnum avatarType)
        {
            try
            {
                String fileType = Path.GetExtension(avatar.FileName);
                String name = id + fileType;
                AvatarImage image = null;

                switch (avatar.ContentType)
                {
                    //Only accepct these content types
                    case "image/gif":
                    case "image/png":
                    case "image/jpg":
                    case "image/jpeg":
                        break;

                    //invalid file type
                    default:
                        throw new InvalidFileTypeException("Invalid File Type");
                }

                switch (avatarType)
                {
                    case AvatarTypeEnum.Team:
                        image = new TeamAvatarImage(server, name);
                        break;

                    case AvatarTypeEnum.Player:
                        image = new PlayerAvatarImage(server, name);
                        break;
                }

                try
                {
                    String absPath = image.AbsolutePath;
                    avatar.SaveAs(absPath);
                }
                catch (Exception e)
                {
                    //log
                    throw new FileUploadException("There was an error uploading the file");
                }

                return image;
            }
            catch (Exception e)
            {
                throw new GeneralException();
            }
        }
    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("~/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;
        }
    }