BlogPostDriver.cs :  » Web-Frameworks » Orchard » Orchard » Blogs » Drivers » 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 » Web Frameworks » Orchard 
Orchard » Orchard » Blogs » Drivers » BlogPostDriver.cs
using System;
using System.Web.Routing;
using JetBrains.Annotations;
using Orchard.Blogs.Models;
using Orchard.Blogs.Services;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.Core.Common.Services;
using Orchard.Localization;

namespace Orchard.Blogs.Drivers{
    [UsedImplicitly]                                                                                                                                                                                        
    public class BlogPostDriver : ContentItemDriver<BlogPost> {
        public IOrchardServices Services { get; set; }
        private readonly IBlogPostService _blogPostService;
        private readonly IRoutableService _routableService;

        public readonly static ContentType ContentType = new ContentType {
                                                                             Name = "blogpost",
                                                                             DisplayName = "Blog Post"
                                                                         };

        public BlogPostDriver(IOrchardServices services, IBlogService blogService, IBlogPostService blogPostService, IRoutableService routableService) {
            Services = services;
            _blogPostService = blogPostService;
            _routableService = routableService;
            T = NullLocalizer.Instance;
        }

        private Localizer T { get; set; }

        protected override ContentType GetContentType() {
            return ContentType;
        }

        protected override string Prefix { get { return ""; } }

        protected override string GetDisplayText(BlogPost post) {
            return post.Title;
        }

        public override RouteValueDictionary GetDisplayRouteValues(BlogPost post) {
            return new RouteValueDictionary {
                                                {"Area", "Orchard.Blogs"},
                                                {"Controller", "BlogPost"},
                                                {"Action", "Item"},
                                                {"blogSlug", post.Blog.Slug},
                                                {"postSlug", post.Slug},
                                            };
        }

        public override RouteValueDictionary GetEditorRouteValues(BlogPost post) {
            return new RouteValueDictionary {
                                                {"Area", "Orchard.Blogs"},
                                                {"Controller", "BlogPostAdmin"},
                                                {"Action", "Edit"},
                                                {"blogSlug", post.Blog.Slug},
                                                {"postId", post.Id},
                                            };
        }

        protected override DriverResult Display(BlogPost post, string displayType) {
            return Combined(
                ContentItemTemplate("Items/Blogs.BlogPost").LongestMatch(displayType, "Summary", "SummaryAdmin"),
                ContentPartTemplate(post, "Parts/Blogs.BlogPost.Metadata").LongestMatch(displayType, "Summary", "SummaryAdmin").Location("meta"));
        }

        protected override DriverResult Editor(BlogPost post) {
            return Combined(
                ContentItemTemplate("Items/Blogs.BlogPost"),
                ContentPartTemplate(post, "Parts/Blogs.BlogPost.Publish").Location("secondary", "1"));
        }

        protected override DriverResult Editor(BlogPost post, IUpdateModel updater) {
            updater.TryUpdateModel(post, Prefix, null, null);

            DateTime scheduled;
            if (DateTime.TryParse(string.Format("{0} {1}", post.ScheduledPublishUtcDate, post.ScheduledPublishUtcTime), out scheduled))
                post.ScheduledPublishUtc = scheduled;

            return Editor(post);
        }
    }
}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.