EditImage.aspx.cs :  » Bloggers » SubText » Subtext » Web » Admin » Pages » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Bloggers » SubText 
SubText » Subtext » Web » Admin » Pages » EditImage.aspx.cs
#region Disclaimer/Info

///////////////////////////////////////////////////////////////////////////////////////////////////
// Subtext WebLog
// 
// Subtext is an open source weblog system that is a fork of the .TEXT
// weblog system.
//
// For updated news and information please visit http://subtextproject.com/
// Subtext is hosted at Google Code at http://code.google.com/p/subtext/
// The development mailing list is at subtext@googlegroups.com 
//
// This project is licensed under the BSD license.  See the License.txt file for more information.
///////////////////////////////////////////////////////////////////////////////////////////////////

#endregion

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Web.UI.WebControls;
using Subtext.Framework;
using Subtext.Framework.Components;
using Subtext.Framework.Web;
using Subtext.Web.Properties;
using ImageSubtext.Framework.Components.Image;

namespace Subtext.Web.Admin.Pages{
    public partial class EditImage : AdminPage
    {
        protected const string VskeyImageid = "ImageId";
        protected string GalleryTitle;
        protected Image _image;
        protected int _imageID;

        public EditImage()
        {
            TabSectionId = "Galleries";
        }

        private int ImageId
        {
            get
            {
                if(ViewState[VskeyImageid] == null || NullValue.NullInt32 == (int)ViewState[VskeyImageid])
                {
                    if(null != Request.QueryString[Keys.QRYSTR_IMAGEID])
                    {
                        ViewState[VskeyImageid] = Convert.ToInt32(Request.QueryString[Keys.QRYSTR_IMAGEID]);
                    }
                }
                return (int)ViewState[VskeyImageid];
            }
        }

        public Image Image
        {
            get
            {
                if(_image == null)
                {
                    _image = Repository.GetImage(ImageId, false /* activeOnly */);
                }

                if(_image == null)
                {
                    throw new InvalidOperationException(Resources.InvalidOperation_ImageUndefined);
                }

                return _image;
            }
        }

        public override void DataBind()
        {
            BindImage();
            base.DataBind();
        }

        private void BindImage()
        {
            ICollection<LinkCategory> selectionList = Links.GetCategories(CategoryType.ImageCollection,
                                                                          ActiveFilter.None);
            if(selectionList.Count > 0)
            {
                ddlGalleries.DataSource = selectionList;
                ddlGalleries.DataValueField = "Id";
                ddlGalleries.DataTextField = "Title";

                lnkThumbnail.ImageUrl = EvalImageUrl(Image);
                lnkThumbnail.NavigateUrl = EvalImageNavigateUrl(Image);
                lnkThumbnail.Visible = true;

                ckbPublished.Checked = Image.IsActive;

                SetGalleryInfo(Image);

                ddlGalleries.DataBind();

                ListItem listItem =
                    ddlGalleries.Items.FindByValue(_image.CategoryID.ToString(CultureInfo.InvariantCulture));
                if(listItem != null)
                {
                    ddlGalleries.SelectedIndex = ddlGalleries.Items.IndexOf(listItem);
                }
                // HACK: we're disabling this until we do something with/around the provider
                // that will let us actually move the files too.
                ddlGalleries.Enabled = false;

                if(AdminMasterPage != null)
                {
                    string title = string.Format(CultureInfo.InvariantCulture, Resources.EditGalleries_EditImage,
                                                 Image.Title);
                    AdminMasterPage.Title = title;
                }
            }
        }

        protected void SetGalleryInfo(Image image)
        {
            GalleryTitle = SubtextContext.Repository.GetLinkCategory(image.CategoryID, false).Title;
        }

        protected string EvalImageUrl(object imageObject)
        {
            if(imageObject is Image)
            {
                var image = (Image)imageObject;
                image.Blog = Blog;
                return Url.GalleryImageUrl(image);
            }
            return String.Empty;
        }

        protected string EvalImageNavigateUrl(object imageObject)
        {
            if(imageObject is Image)
            {
                var image = (Image)imageObject;
                return Url.GalleryImagePageUrl(image);
            }
            return String.Empty;
        }

        protected string GetImageGalleryUrl()
        {
            return string.Format(CultureInfo.InvariantCulture, "{0}?{1}={2}", Constants.URL_EDITGALLERIES,
                                 Keys.QRYSTR_CATEGORYID, Image.CategoryID);
        }

        private void UpdateImage()
        {
            if(Page.IsValid)
            {
                _image = Repository.GetImage(ImageId, false /* activeOnly */);
                _image.CategoryID = Convert.ToInt32(ddlGalleries.SelectedItem.Value);
                _image.Title = txbTitle.Text;
                _image.IsActive = ckbPublished.Checked;

                try
                {
                    Images.UpdateImage(_image);

                    // would need to also move files for this to work here. should happen
                    // in the provider though.

                    Messages.ShowMessage(Resources.EditGalleries_ImageUpdated);
                    BindImage();
                }
                catch(Exception ex)
                {
                    Messages.ShowError(String.Format(Constants.RES_EXCEPTION, "TODO...", ex.Message));
                }
            }
        }

        private void ReplaceImage()
        {
            if(Page.IsValid)
            {
                _image = Repository.GetImage(ImageId, false /* activeOnly */);
                _image.CategoryID = Convert.ToInt32(ddlGalleries.SelectedItem.Value);
                _image.Title = txbTitle.Text;
                _image.IsActive = ckbPublished.Checked;

                try
                {
                    _image.FileName = Path.GetFileName(ImageFile.PostedFile.FileName);
                    _image.Url = Url.ImageGalleryDirectoryUrl(Blog, _image.CategoryID);
                    _image.LocalDirectoryPath = Url.GalleryDirectoryPath(Blog, _image.CategoryID);
                    Images.Update(_image, ImageFile.PostedFile.GetFileStream());

                    Messages.ShowMessage(Resources.EditGalleries_ImageUpdated);
                    BindImage();
                }
                catch(Exception ex)
                {
                    Messages.ShowError(String.Format(Constants.RES_EXCEPTION, "TODO...", ex.Message));
                }
            }
        }

        override protected void OnInit(EventArgs e)
        {
            ViewState[VskeyImageid] = NullValue.NullInt32;
        }

        protected void lbkReplaceImage_Click(object sender, EventArgs e)
        {
            ReplaceImage();
        }

        protected void lkbUpdateImage_Click(object sender, EventArgs e)
        {
            UpdateImage();
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.