mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-01-23 13:22:08 +08:00
Removed publish property from BlogPostRecord to use the built in date from CommonAspect and removed BlogPostRecord since it doesn't contain any properties anymore and cleaned up some code inconsistencies in BlogController, BlogAdminController and BlogPostController.
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4045249
This commit is contained in:
@@ -3,24 +3,23 @@ using System.Web.Mvc;
|
||||
using Orchard.Blogs.Models;
|
||||
using Orchard.Blogs.Services;
|
||||
using Orchard.Blogs.ViewModels;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Mvc.Results;
|
||||
|
||||
namespace Orchard.Blogs.Controllers {
|
||||
[ValidateInput(false)]
|
||||
public class BlogAdminController : Controller {
|
||||
private readonly IOrchardServices _services;
|
||||
private readonly IBlogService _blogService;
|
||||
private readonly IContentManager _contentManager;
|
||||
|
||||
public BlogAdminController(IContentManager contentManager, IBlogService blogService) {
|
||||
_contentManager = contentManager;
|
||||
public BlogAdminController(IOrchardServices services, IBlogService blogService) {
|
||||
_services = services;
|
||||
_blogService = blogService;
|
||||
}
|
||||
|
||||
public ActionResult List() {
|
||||
//TODO: (erikpo) Need to make templatePath be more convention based so if my controller name has "Admin" in it then "Admin/{type}" is assumed
|
||||
var model = new AdminBlogsViewModel {
|
||||
Blogs = _blogService.Get().Select(b => _contentManager.BuildDisplayModel(b, "SummaryAdmin"))
|
||||
Blogs = _blogService.Get().Select(b => _services.ContentManager.BuildDisplayModel(b, "SummaryAdmin"))
|
||||
};
|
||||
|
||||
return View(model);
|
||||
@@ -35,7 +34,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
|
||||
//TODO: (erikpo) Need to make templatePath be more convention based so if my controller name has "Admin" in it then "Admin/{type}" is assumed
|
||||
var model = new BlogForAdminViewModel {
|
||||
Blog = _contentManager.BuildDisplayModel(blog, "DetailAdmin")
|
||||
Blog = _services.ContentManager.BuildDisplayModel(blog, "DetailAdmin")
|
||||
};
|
||||
|
||||
return View(model);
|
||||
|
||||
@@ -14,18 +14,15 @@ using Orchard.UI.Notify;
|
||||
namespace Orchard.Blogs.Controllers {
|
||||
[ValidateInput(false)]
|
||||
public class BlogController : Controller, IUpdateModel {
|
||||
private readonly IOrchardServices _services;
|
||||
private readonly ISessionLocator _sessionLocator;
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IAuthorizer _authorizer;
|
||||
private readonly INotifier _notifier;
|
||||
private readonly IBlogService _blogService;
|
||||
|
||||
public BlogController(
|
||||
ISessionLocator sessionLocator, IContentManager contentManager,
|
||||
IAuthorizer authorizer, INotifier notifier,
|
||||
IBlogService blogService) {
|
||||
public BlogController(IOrchardServices services, ISessionLocator sessionLocator, IAuthorizer authorizer, INotifier notifier, IBlogService blogService) {
|
||||
_services = services;
|
||||
_sessionLocator = sessionLocator;
|
||||
_contentManager = contentManager;
|
||||
_authorizer = authorizer;
|
||||
_notifier = notifier;
|
||||
_blogService = blogService;
|
||||
@@ -36,7 +33,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
|
||||
public ActionResult List() {
|
||||
var model = new BlogsViewModel {
|
||||
Blogs = _blogService.Get().Select(b => _contentManager.BuildDisplayModel(b, "Summary"))
|
||||
Blogs = _blogService.Get().Select(b => _services.ContentManager.BuildDisplayModel(b, "Summary"))
|
||||
};
|
||||
|
||||
return View(model);
|
||||
@@ -50,7 +47,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
return new NotFoundResult();
|
||||
|
||||
var model = new BlogViewModel {
|
||||
Blog = _contentManager.BuildDisplayModel(blog, "Detail")
|
||||
Blog = _services.ContentManager.BuildDisplayModel(blog, "Detail")
|
||||
};
|
||||
|
||||
return View(model);
|
||||
@@ -61,13 +58,13 @@ namespace Orchard.Blogs.Controllers {
|
||||
if (!_authorizer.Authorize(Permissions.CreateBlog, T("Not allowed to create blogs")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
Blog blog = _contentManager.New<Blog>("blog");
|
||||
Blog blog = _services.ContentManager.New<Blog>("blog");
|
||||
|
||||
if (blog == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
var model = new CreateBlogViewModel {
|
||||
Blog = _contentManager.BuildEditorModel(blog)
|
||||
Blog = _services.ContentManager.BuildEditorModel(blog)
|
||||
};
|
||||
|
||||
return View(model);
|
||||
@@ -79,12 +76,12 @@ namespace Orchard.Blogs.Controllers {
|
||||
if (!_authorizer.Authorize(Permissions.CreateBlog, T("Couldn't create blog")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
model.Blog = _contentManager.UpdateEditorModel(_contentManager.New<Blog>("blog"), this);
|
||||
model.Blog = _services.ContentManager.UpdateEditorModel(_services.ContentManager.New<Blog>("blog"), this);
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
return View(model);
|
||||
|
||||
_contentManager.Create(model.Blog.Item.ContentItem);
|
||||
_services.ContentManager.Create(model.Blog.Item.ContentItem);
|
||||
|
||||
//TEMP: (erikpo) ensure information has committed for this record
|
||||
var session = _sessionLocator.For(typeof(BlogRecord));
|
||||
@@ -105,7 +102,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
return new NotFoundResult();
|
||||
|
||||
var model = new BlogEditViewModel {
|
||||
Blog = _contentManager.BuildEditorModel(blog)
|
||||
Blog = _services.ContentManager.BuildEditorModel(blog)
|
||||
};
|
||||
|
||||
return View(model);
|
||||
@@ -123,7 +120,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
return new NotFoundResult();
|
||||
|
||||
var model = new BlogEditViewModel {
|
||||
Blog = _contentManager.UpdateEditorModel(blog, this)
|
||||
Blog = _services.ContentManager.UpdateEditorModel(blog, this)
|
||||
};
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
|
||||
@@ -5,6 +5,7 @@ using Orchard.Blogs.Extensions;
|
||||
using Orchard.Blogs.Models;
|
||||
using Orchard.Blogs.Services;
|
||||
using Orchard.Blogs.ViewModels;
|
||||
using Orchard.ContentManagement.Records;
|
||||
using Orchard.Data;
|
||||
using Orchard.Localization;
|
||||
using Orchard.ContentManagement;
|
||||
@@ -14,6 +15,7 @@ using Orchard.UI.Notify;
|
||||
namespace Orchard.Blogs.Controllers {
|
||||
[ValidateInput(false)]
|
||||
public class BlogPostController : Controller, IUpdateModel {
|
||||
private readonly IOrchardServices _services;
|
||||
private readonly ISessionLocator _sessionLocator;
|
||||
private readonly IBlogService _blogService;
|
||||
private readonly IBlogPostService _blogPostService;
|
||||
@@ -23,19 +25,18 @@ namespace Orchard.Blogs.Controllers {
|
||||
ISessionLocator sessionLocator,
|
||||
IBlogService blogService,
|
||||
IBlogPostService blogPostService) {
|
||||
Services = services;
|
||||
_services = services;
|
||||
_sessionLocator = sessionLocator;
|
||||
_blogService = blogService;
|
||||
_blogPostService = blogPostService;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public IOrchardServices Services { get; set; }
|
||||
private Localizer T { get; set; }
|
||||
|
||||
//TODO: (erikpo) Should think about moving the slug parameters and get calls and null checks up into a model binder or action filter
|
||||
public ActionResult Item(string blogSlug, string postSlug) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ViewPost, T("Couldn't view blog post")))
|
||||
if (!_services.Authorizer.Authorize(Permissions.ViewPost, T("Couldn't view blog post")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
//TODO: (erikpo) Move looking up the current blog up into a modelbinder
|
||||
@@ -53,7 +54,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
|
||||
var model = new BlogPostViewModel {
|
||||
Blog = blog,
|
||||
BlogPost = Services.ContentManager.BuildDisplayModel(post, "Detail")
|
||||
BlogPost = _services.ContentManager.BuildDisplayModel(post, "Detail")
|
||||
};
|
||||
|
||||
return View(model);
|
||||
@@ -70,7 +71,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
var model = new BlogPostArchiveViewModel {
|
||||
Blog = blog,
|
||||
ArchiveData = archive,
|
||||
BlogPosts = _blogPostService.Get(blog, archive).Select(b => Services.ContentManager.BuildDisplayModel(b, "Summary"))
|
||||
BlogPosts = _blogPostService.Get(blog, archive).Select(b => _services.ContentManager.BuildDisplayModel(b, "Summary"))
|
||||
};
|
||||
|
||||
return View(model);
|
||||
@@ -101,7 +102,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
|
||||
public ActionResult Create(string blogSlug) {
|
||||
//TODO: (erikpo) Might think about moving this to an ActionFilter/Attribute
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreatePost, T("Not allowed to create blog post")))
|
||||
if (!_services.Authorizer.Authorize(Permissions.CreatePost, T("Not allowed to create blog post")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
//TODO: (erikpo) Move looking up the current blog up into a modelbinder
|
||||
@@ -110,7 +111,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
if (blog == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
var blogPost = Services.ContentManager.BuildEditorModel(Services.ContentManager.New<BlogPost>("blogpost"));
|
||||
var blogPost = _services.ContentManager.BuildEditorModel(_services.ContentManager.New<BlogPost>("blogpost"));
|
||||
blogPost.Item.Blog = blog;
|
||||
|
||||
var model = new CreateBlogPostViewModel {
|
||||
@@ -122,7 +123,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Create(string blogSlug, CreateBlogPostViewModel model) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreatePost, T("Couldn't create blog post")))
|
||||
if (!_services.Authorizer.Authorize(Permissions.CreatePost, T("Couldn't create blog post")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
//TODO: (erikpo) Move looking up the current blog up into a modelbinder
|
||||
@@ -136,24 +137,24 @@ namespace Orchard.Blogs.Controllers {
|
||||
publishNow = true;
|
||||
}
|
||||
|
||||
BlogPost blogPost = Services.ContentManager.Create<BlogPost>("blogpost", publishNow ? VersionOptions.Published : VersionOptions.Draft, bp => { bp.Blog = blog; });
|
||||
model.BlogPost = Services.ContentManager.UpdateEditorModel(blogPost, this);
|
||||
BlogPost blogPost = _services.ContentManager.Create<BlogPost>("blogpost", publishNow ? VersionOptions.Published : VersionOptions.Draft, bp => { bp.Blog = blog; });
|
||||
model.BlogPost = _services.ContentManager.UpdateEditorModel(blogPost, this);
|
||||
|
||||
if (!ModelState.IsValid) {
|
||||
Services.TransactionManager.Cancel();
|
||||
_services.TransactionManager.Cancel();
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
//TEMP: (erikpo) ensure information has committed for this record
|
||||
var session = _sessionLocator.For(typeof(BlogPostRecord));
|
||||
var session = _sessionLocator.For(typeof(ContentItemRecord));
|
||||
session.Flush();
|
||||
|
||||
return Redirect(Url.BlogPost(blogSlug, model.BlogPost.Item.Slug));
|
||||
}
|
||||
|
||||
public ActionResult Edit(string blogSlug, string postSlug) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ModifyPost, T("Couldn't edit blog post")))
|
||||
if (!_services.Authorizer.Authorize(Permissions.ModifyPost, T("Couldn't edit blog post")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
//TODO: (erikpo) Move looking up the current blog up into a modelbinder
|
||||
@@ -168,7 +169,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
return new NotFoundResult();
|
||||
|
||||
var model = new BlogPostEditViewModel {
|
||||
BlogPost = Services.ContentManager.BuildEditorModel(post)
|
||||
BlogPost = _services.ContentManager.BuildEditorModel(post)
|
||||
};
|
||||
|
||||
return View(model);
|
||||
@@ -176,7 +177,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
|
||||
[HttpPost, ActionName("Edit")]
|
||||
public ActionResult EditPOST(string blogSlug, string postSlug) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ModifyPost, T("Couldn't edit blog post")))
|
||||
if (!_services.Authorizer.Authorize(Permissions.ModifyPost, T("Couldn't edit blog post")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
//TODO: (erikpo) Move looking up the current blog up into a modelbinder
|
||||
@@ -201,25 +202,25 @@ namespace Orchard.Blogs.Controllers {
|
||||
_blogPostService.Unpublish(post);
|
||||
|
||||
var model = new BlogPostEditViewModel {
|
||||
BlogPost = Services.ContentManager.UpdateEditorModel(post, this)
|
||||
BlogPost = _services.ContentManager.UpdateEditorModel(post, this)
|
||||
};
|
||||
|
||||
TryUpdateModel(model);
|
||||
|
||||
if (!ModelState.IsValid) {
|
||||
Services.TransactionManager.Cancel();
|
||||
_services.TransactionManager.Cancel();
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
Services.Notifier.Information(T("Blog post information updated."));
|
||||
_services.Notifier.Information(T("Blog post information updated."));
|
||||
|
||||
return Redirect(Url.BlogPostEdit(blog.Slug, post.Slug));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Delete(string blogSlug, string postSlug) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.DeletePost, T("Couldn't delete blog post")))
|
||||
if (!_services.Authorizer.Authorize(Permissions.DeletePost, T("Couldn't delete blog post")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
//TODO: (erikpo) Move looking up the current blog up into a modelbinder
|
||||
@@ -235,7 +236,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
|
||||
_blogPostService.Delete(post);
|
||||
|
||||
Services.Notifier.Information(T("Blog post was successfully deleted"));
|
||||
_services.Notifier.Information(T("Blog post was successfully deleted"));
|
||||
|
||||
return Redirect(Url.BlogForAdmin(blogSlug));
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ using Orchard.ContentManagement;
|
||||
using Orchard.Security;
|
||||
|
||||
namespace Orchard.Blogs.Models {
|
||||
public class BlogPost : ContentPart<BlogPostRecord> {
|
||||
public class BlogPost : ContentPart {
|
||||
[HiddenInput(DisplayValue = false)]
|
||||
public int Id { get { return ContentItem.Id; } }
|
||||
|
||||
@@ -35,8 +35,8 @@ namespace Orchard.Blogs.Models {
|
||||
|
||||
public DateTime? Published
|
||||
{
|
||||
get { return Record.Published; }
|
||||
set { Record.Published = value; }
|
||||
get { return this.As<CommonAspect>().PublishedUtc; }
|
||||
set { this.As<CommonAspect>().PublishedUtc = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,21 @@
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Blogs.Controllers;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Data;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Core.Common.Records;
|
||||
using Orchard.Data;
|
||||
|
||||
namespace Orchard.Blogs.Models {
|
||||
[UsedImplicitly]
|
||||
public class BlogPostHandler : ContentHandler {
|
||||
|
||||
public BlogPostHandler(IRepository<BlogPostRecord> repository) {
|
||||
|
||||
public BlogPostHandler(IRepository<CommonVersionRecord> commonRepository) {
|
||||
Filters.Add(new ActivatingFilter<BlogPost>(BlogPostDriver.ContentType.Name));
|
||||
Filters.Add(new ActivatingFilter<CommonAspect>(BlogPostDriver.ContentType.Name));
|
||||
Filters.Add(new ActivatingFilter<RoutableAspect>(BlogPostDriver.ContentType.Name));
|
||||
Filters.Add(new ActivatingFilter<BodyAspect>(BlogPostDriver.ContentType.Name));
|
||||
Filters.Add(new StorageFilter<BlogPostRecord>(repository));
|
||||
|
||||
Filters.Add(new StorageFilter<CommonVersionRecord>(commonRepository));
|
||||
|
||||
OnCreated<BlogPost>((context, bp) => bp.Blog.PostCount++);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
using System;
|
||||
using Orchard.ContentManagement.Records;
|
||||
|
||||
namespace Orchard.Blogs.Models {
|
||||
public class BlogPostRecord : ContentPartRecord {
|
||||
public virtual DateTime? Published { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Data.Conventions;
|
||||
using Orchard.ContentManagement.Records;
|
||||
|
||||
namespace Orchard.Blogs.Models {
|
||||
public class BlogRecord : ContentPartRecord {
|
||||
[CascadeAllDeleteOrphan]
|
||||
public virtual IEnumerable<BlogPostRecord> Posts { get; set; }
|
||||
public virtual string Description { get; set; }
|
||||
//public virtual bool Enabled { get; set; }
|
||||
public virtual int PostCount { get; set; }
|
||||
|
||||
@@ -91,7 +91,6 @@
|
||||
<Compile Include="Models\BlogHandler.cs" />
|
||||
<Compile Include="Models\BlogPost.cs" />
|
||||
<Compile Include="Models\BlogPostHandler.cs" />
|
||||
<Compile Include="Models\BlogPostRecord.cs" />
|
||||
<Compile Include="Models\BlogRecord.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Routes.cs" />
|
||||
|
||||
@@ -19,9 +19,9 @@ namespace Orchard.Blogs.Services {
|
||||
|
||||
public BlogPost Get(Blog blog, string slug, VersionOptions versionOptions) {
|
||||
return
|
||||
_contentManager.Query<BlogPost, BlogPostRecord>(versionOptions).Join<RoutableRecord>().Where(rr => rr.Slug == slug).
|
||||
_contentManager.Query(versionOptions, "blogpost").Join<RoutableRecord>().Where(rr => rr.Slug == slug).
|
||||
Join<CommonRecord>().Where(cr => cr.Container == blog.Record.ContentItemRecord).List().
|
||||
SingleOrDefault();
|
||||
SingleOrDefault().As<BlogPost>();
|
||||
}
|
||||
|
||||
public IEnumerable<BlogPost> Get(Blog blog) {
|
||||
@@ -29,7 +29,7 @@ namespace Orchard.Blogs.Services {
|
||||
}
|
||||
|
||||
public IEnumerable<BlogPost> Get(Blog blog, VersionOptions versionOptions) {
|
||||
return GetBlogQuery(blog, versionOptions).List();
|
||||
return GetBlogQuery(blog, versionOptions).List().Select(ci => ci.As<BlogPost>());
|
||||
}
|
||||
|
||||
public IEnumerable<BlogPost> Get(Blog blog, ArchiveData archiveData) {
|
||||
@@ -54,7 +54,7 @@ namespace Orchard.Blogs.Services {
|
||||
cr.CreatedUtc >= new DateTime(archiveData.Year, 1, 1) &&
|
||||
cr.CreatedUtc < new DateTime(archiveData.Year + 1, 1, 1));
|
||||
|
||||
return query.List();
|
||||
return query.List().Select(ci => ci.As<BlogPost>());
|
||||
}
|
||||
|
||||
public void Delete(BlogPost blogPost) {
|
||||
@@ -71,9 +71,9 @@ namespace Orchard.Blogs.Services {
|
||||
blogPost.Published = null;
|
||||
}
|
||||
|
||||
private IContentQuery<BlogPost, CommonRecord> GetBlogQuery(ContentPart<BlogRecord> blog, VersionOptions versionOptions) {
|
||||
private IContentQuery<ContentItem, CommonRecord> GetBlogQuery(ContentPart<BlogRecord> blog, VersionOptions versionOptions) {
|
||||
return
|
||||
_contentManager.Query<BlogPost, BlogPostRecord>(versionOptions).Join<CommonRecord>().Where(
|
||||
_contentManager.Query(versionOptions, "blogpost").Join<CommonRecord>().Where(
|
||||
cr => cr.Container == blog.Record.ContentItemRecord).OrderByDescending(cr => cr.CreatedUtc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,6 +89,13 @@ namespace Orchard.ContentManagement {
|
||||
return manager.Query().ForPart<TPart>().ForVersion(options).Join<TRecord>();
|
||||
}
|
||||
|
||||
public static IContentQuery<ContentItem> Query(this IContentManager manager, VersionOptions options, params string[] contentTypeNames) {
|
||||
return manager.Query().ForVersion(options).ForType(contentTypeNames);
|
||||
}
|
||||
public static IContentQuery<TPart> Query<TPart>(this IContentManager manager, VersionOptions options, params string[] contentTypeNames) where TPart : ContentPart {
|
||||
return manager.Query().ForPart<TPart>().ForVersion(options).ForType(contentTypeNames);
|
||||
}
|
||||
|
||||
/* Query(params string[] contentTypeNames) */
|
||||
|
||||
public static IContentQuery<ContentItem> Query(this IContentManager manager, params string[] contentTypeNames) {
|
||||
|
||||
Reference in New Issue
Block a user