EntriesList.ascx.cs :  » Bloggers » SubText » Subtext » Web » Admin » UserControls » 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 » UserControls » EntriesList.ascx.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.Diagnostics;
using System.Globalization;
using System.Web.UI.WebControls;
using Subtext.Extensibility;
using Subtext.Extensibility.Interfaces;
using Subtext.Framework.Components;
using Subtext.Framework.Configuration;
using Subtext.Framework.Providers;
using Subtext.Web.Admin.Commands;
using Subtext.Web.Admin.Pages;
using Subtext.Web.Properties;
using Subtext.Web.UI.Controls;

namespace Subtext.Web.Admin.UserControls{
    public partial class EntriesList : BaseControl
    {
        private int? categoryId = null;
        private int pageIndex = 0;

        public string HeaderText
        {
            get { return (string)ViewState["HeaderText"] ?? string.Empty; }
            set { ViewState["HeaderText"] = value; }
        }

        public string ResultsUrlFormat
        {
            get { return resultsPager.UrlFormat; }
            set { resultsPager.UrlFormat = value; }
        }

        /// <summary>
        /// Gets or sets the type of the entry.
        /// </summary>
        /// <value>The type of the entry.</value>
        public PostType EntryType
        {
            get
            {
                if(ViewState["PostType"] != null)
                {
                    return (PostType)ViewState["PostType"];
                }
                return PostType.None;
            }
            set { ViewState["PostType"] = value; }
        }

        protected override void OnInit(EventArgs e)
        {
            rprSelectionList.ItemCommand += OnItemCommand;
            base.OnInit(e);
        }

        protected override void OnLoad(EventArgs e)
        {
            if(Request.QueryString[Keys.QRYSTR_PAGEINDEX] != null)
            {
                pageIndex = Convert.ToInt32(Request.QueryString[Keys.QRYSTR_PAGEINDEX]);
            }

            if(Request.QueryString[Keys.QRYSTR_CATEGORYID] != null)
            {
                categoryId = Convert.ToInt32(Request.QueryString[Keys.QRYSTR_CATEGORYID]);
            }

            resultsPager.PageSize = Preferences.ListingItemCount;
            resultsPager.PageIndex = pageIndex;

            if(categoryId != null)
            {
                string catIdQueryString = string.Format(CultureInfo.InvariantCulture, "&{0}={1}", Keys.QRYSTR_CATEGORYID,
                                                        categoryId);
                if(!resultsPager.UrlFormat.EndsWith(catIdQueryString))
                {
                    resultsPager.UrlFormat += catIdQueryString;
                }
            }

            if(!IsPostBack)
            {
                BindList();
            }

            base.OnLoad(e);
        }

        void OnItemCommand(object source, RepeaterCommandEventArgs e)
        {
            ConfirmDelete(Convert.ToInt32(e.CommandArgument));
        }

        private void ConfirmDelete(int postID)
        {
            var page = (AdminPage)Page;
            if(page != null)
            {
                var command = new DeletePostCommand(Repository, postID, page.SearchEngine);
                command.Execute();
                BindList();
            }
        }

        public string PostsEditUrl(object item)
        {
            var entry = (Entry)item;
            return AdminUrl.PostsEdit(entry.Id);
        }

        public string ArticlesEditUrl(object item)
        {
            var entry = (Entry)item;
            return AdminUrl.ArticlesEdit(entry.Id);
        }

        public string ContentEditUrl(object item)
        {
            if (((AdminPage)this.Page).TabSectionId == "Articles")
            {
                return ArticlesEditUrl(item);
            }
            else
            {
                return PostsEditUrl(item);
            }
        }

        public string ReferrersUrl(object item)
        {
            var entry = (Entry)item;
            return AdminUrl.Referrers(entry.Id);
        }

        protected string IsActiveText(object entryObject)
        {
            var entry = entryObject as Entry;

            Debug.Assert(entry != null, "Entry should never be null here");

            string active = "False";
            if(entry.IsActive)
            {
                active = "True";
                if(entry.DateSyndicated > Config.CurrentBlog.TimeZone.Now)
                {
                    active += "<em> on " + entry.DateSyndicated.ToShortDateString() + "</em>";
                }
            }
            return active;
        }

        private void BindList()
        {
            if(categoryId != null)
            {
                LinkCategory category = Repository.GetLinkCategory(categoryId, false);
                if(category != null)
                {
                    HeaderText = Resources.Label_Posts.ToUpper(CultureInfo.CurrentCulture) + " (" + category.Title + ")";
                }
            }

            IPagedCollection<EntryStatsView> selectionList = Repository.GetEntries(EntryType, categoryId, pageIndex,
                                                                                        resultsPager.PageSize);

            if(selectionList.Count > 0)
            {
                resultsPager.ItemCount = selectionList.MaxItems;
                rprSelectionList.DataSource = selectionList;
                rprSelectionList.DataBind();
                NoMessagesLabel.Visible = false;
            }

            NoMessagesLabel.Visible = selectionList.Count <= 0;
            resultsPager.Visible = rprSelectionList.Visible = selectionList.Count > 0;
        }

        protected override void OnPreRender(EventArgs e)
        {
            title.InnerText = HeaderText;
            base.OnPreRender(e);
        }

        protected EntryStatsView GetEntry(object o)
        {
            return o as EntryStatsView;
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.