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.Models;
|
||||||
using Orchard.Blogs.Services;
|
using Orchard.Blogs.Services;
|
||||||
using Orchard.Blogs.ViewModels;
|
using Orchard.Blogs.ViewModels;
|
||||||
using Orchard.ContentManagement;
|
|
||||||
using Orchard.Mvc.Results;
|
using Orchard.Mvc.Results;
|
||||||
|
|
||||||
namespace Orchard.Blogs.Controllers {
|
namespace Orchard.Blogs.Controllers {
|
||||||
[ValidateInput(false)]
|
[ValidateInput(false)]
|
||||||
public class BlogAdminController : Controller {
|
public class BlogAdminController : Controller {
|
||||||
|
private readonly IOrchardServices _services;
|
||||||
private readonly IBlogService _blogService;
|
private readonly IBlogService _blogService;
|
||||||
private readonly IContentManager _contentManager;
|
|
||||||
|
|
||||||
public BlogAdminController(IContentManager contentManager, IBlogService blogService) {
|
public BlogAdminController(IOrchardServices services, IBlogService blogService) {
|
||||||
_contentManager = contentManager;
|
_services = services;
|
||||||
_blogService = blogService;
|
_blogService = blogService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult List() {
|
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
|
//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 {
|
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);
|
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
|
//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 {
|
var model = new BlogForAdminViewModel {
|
||||||
Blog = _contentManager.BuildDisplayModel(blog, "DetailAdmin")
|
Blog = _services.ContentManager.BuildDisplayModel(blog, "DetailAdmin")
|
||||||
};
|
};
|
||||||
|
|
||||||
return View(model);
|
return View(model);
|
||||||
|
|||||||
@@ -14,18 +14,15 @@ using Orchard.UI.Notify;
|
|||||||
namespace Orchard.Blogs.Controllers {
|
namespace Orchard.Blogs.Controllers {
|
||||||
[ValidateInput(false)]
|
[ValidateInput(false)]
|
||||||
public class BlogController : Controller, IUpdateModel {
|
public class BlogController : Controller, IUpdateModel {
|
||||||
|
private readonly IOrchardServices _services;
|
||||||
private readonly ISessionLocator _sessionLocator;
|
private readonly ISessionLocator _sessionLocator;
|
||||||
private readonly IContentManager _contentManager;
|
|
||||||
private readonly IAuthorizer _authorizer;
|
private readonly IAuthorizer _authorizer;
|
||||||
private readonly INotifier _notifier;
|
private readonly INotifier _notifier;
|
||||||
private readonly IBlogService _blogService;
|
private readonly IBlogService _blogService;
|
||||||
|
|
||||||
public BlogController(
|
public BlogController(IOrchardServices services, ISessionLocator sessionLocator, IAuthorizer authorizer, INotifier notifier, IBlogService blogService) {
|
||||||
ISessionLocator sessionLocator, IContentManager contentManager,
|
_services = services;
|
||||||
IAuthorizer authorizer, INotifier notifier,
|
|
||||||
IBlogService blogService) {
|
|
||||||
_sessionLocator = sessionLocator;
|
_sessionLocator = sessionLocator;
|
||||||
_contentManager = contentManager;
|
|
||||||
_authorizer = authorizer;
|
_authorizer = authorizer;
|
||||||
_notifier = notifier;
|
_notifier = notifier;
|
||||||
_blogService = blogService;
|
_blogService = blogService;
|
||||||
@@ -36,7 +33,7 @@ namespace Orchard.Blogs.Controllers {
|
|||||||
|
|
||||||
public ActionResult List() {
|
public ActionResult List() {
|
||||||
var model = new BlogsViewModel {
|
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);
|
return View(model);
|
||||||
@@ -50,7 +47,7 @@ namespace Orchard.Blogs.Controllers {
|
|||||||
return new NotFoundResult();
|
return new NotFoundResult();
|
||||||
|
|
||||||
var model = new BlogViewModel {
|
var model = new BlogViewModel {
|
||||||
Blog = _contentManager.BuildDisplayModel(blog, "Detail")
|
Blog = _services.ContentManager.BuildDisplayModel(blog, "Detail")
|
||||||
};
|
};
|
||||||
|
|
||||||
return View(model);
|
return View(model);
|
||||||
@@ -61,13 +58,13 @@ namespace Orchard.Blogs.Controllers {
|
|||||||
if (!_authorizer.Authorize(Permissions.CreateBlog, T("Not allowed to create blogs")))
|
if (!_authorizer.Authorize(Permissions.CreateBlog, T("Not allowed to create blogs")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
Blog blog = _contentManager.New<Blog>("blog");
|
Blog blog = _services.ContentManager.New<Blog>("blog");
|
||||||
|
|
||||||
if (blog == null)
|
if (blog == null)
|
||||||
return new NotFoundResult();
|
return new NotFoundResult();
|
||||||
|
|
||||||
var model = new CreateBlogViewModel {
|
var model = new CreateBlogViewModel {
|
||||||
Blog = _contentManager.BuildEditorModel(blog)
|
Blog = _services.ContentManager.BuildEditorModel(blog)
|
||||||
};
|
};
|
||||||
|
|
||||||
return View(model);
|
return View(model);
|
||||||
@@ -79,12 +76,12 @@ namespace Orchard.Blogs.Controllers {
|
|||||||
if (!_authorizer.Authorize(Permissions.CreateBlog, T("Couldn't create blog")))
|
if (!_authorizer.Authorize(Permissions.CreateBlog, T("Couldn't create blog")))
|
||||||
return new HttpUnauthorizedResult();
|
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)
|
if (!ModelState.IsValid)
|
||||||
return View(model);
|
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
|
//TEMP: (erikpo) ensure information has committed for this record
|
||||||
var session = _sessionLocator.For(typeof(BlogRecord));
|
var session = _sessionLocator.For(typeof(BlogRecord));
|
||||||
@@ -105,7 +102,7 @@ namespace Orchard.Blogs.Controllers {
|
|||||||
return new NotFoundResult();
|
return new NotFoundResult();
|
||||||
|
|
||||||
var model = new BlogEditViewModel {
|
var model = new BlogEditViewModel {
|
||||||
Blog = _contentManager.BuildEditorModel(blog)
|
Blog = _services.ContentManager.BuildEditorModel(blog)
|
||||||
};
|
};
|
||||||
|
|
||||||
return View(model);
|
return View(model);
|
||||||
@@ -123,7 +120,7 @@ namespace Orchard.Blogs.Controllers {
|
|||||||
return new NotFoundResult();
|
return new NotFoundResult();
|
||||||
|
|
||||||
var model = new BlogEditViewModel {
|
var model = new BlogEditViewModel {
|
||||||
Blog = _contentManager.UpdateEditorModel(blog, this)
|
Blog = _services.ContentManager.UpdateEditorModel(blog, this)
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using Orchard.Blogs.Extensions;
|
|||||||
using Orchard.Blogs.Models;
|
using Orchard.Blogs.Models;
|
||||||
using Orchard.Blogs.Services;
|
using Orchard.Blogs.Services;
|
||||||
using Orchard.Blogs.ViewModels;
|
using Orchard.Blogs.ViewModels;
|
||||||
|
using Orchard.ContentManagement.Records;
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
@@ -14,6 +15,7 @@ using Orchard.UI.Notify;
|
|||||||
namespace Orchard.Blogs.Controllers {
|
namespace Orchard.Blogs.Controllers {
|
||||||
[ValidateInput(false)]
|
[ValidateInput(false)]
|
||||||
public class BlogPostController : Controller, IUpdateModel {
|
public class BlogPostController : Controller, IUpdateModel {
|
||||||
|
private readonly IOrchardServices _services;
|
||||||
private readonly ISessionLocator _sessionLocator;
|
private readonly ISessionLocator _sessionLocator;
|
||||||
private readonly IBlogService _blogService;
|
private readonly IBlogService _blogService;
|
||||||
private readonly IBlogPostService _blogPostService;
|
private readonly IBlogPostService _blogPostService;
|
||||||
@@ -23,19 +25,18 @@ namespace Orchard.Blogs.Controllers {
|
|||||||
ISessionLocator sessionLocator,
|
ISessionLocator sessionLocator,
|
||||||
IBlogService blogService,
|
IBlogService blogService,
|
||||||
IBlogPostService blogPostService) {
|
IBlogPostService blogPostService) {
|
||||||
Services = services;
|
_services = services;
|
||||||
_sessionLocator = sessionLocator;
|
_sessionLocator = sessionLocator;
|
||||||
_blogService = blogService;
|
_blogService = blogService;
|
||||||
_blogPostService = blogPostService;
|
_blogPostService = blogPostService;
|
||||||
T = NullLocalizer.Instance;
|
T = NullLocalizer.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IOrchardServices Services { get; set; }
|
|
||||||
private Localizer T { 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
|
//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) {
|
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();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
//TODO: (erikpo) Move looking up the current blog up into a modelbinder
|
//TODO: (erikpo) Move looking up the current blog up into a modelbinder
|
||||||
@@ -53,7 +54,7 @@ namespace Orchard.Blogs.Controllers {
|
|||||||
|
|
||||||
var model = new BlogPostViewModel {
|
var model = new BlogPostViewModel {
|
||||||
Blog = blog,
|
Blog = blog,
|
||||||
BlogPost = Services.ContentManager.BuildDisplayModel(post, "Detail")
|
BlogPost = _services.ContentManager.BuildDisplayModel(post, "Detail")
|
||||||
};
|
};
|
||||||
|
|
||||||
return View(model);
|
return View(model);
|
||||||
@@ -70,7 +71,7 @@ namespace Orchard.Blogs.Controllers {
|
|||||||
var model = new BlogPostArchiveViewModel {
|
var model = new BlogPostArchiveViewModel {
|
||||||
Blog = blog,
|
Blog = blog,
|
||||||
ArchiveData = archive,
|
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);
|
return View(model);
|
||||||
@@ -101,7 +102,7 @@ namespace Orchard.Blogs.Controllers {
|
|||||||
|
|
||||||
public ActionResult Create(string blogSlug) {
|
public ActionResult Create(string blogSlug) {
|
||||||
//TODO: (erikpo) Might think about moving this to an ActionFilter/Attribute
|
//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();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
//TODO: (erikpo) Move looking up the current blog up into a modelbinder
|
//TODO: (erikpo) Move looking up the current blog up into a modelbinder
|
||||||
@@ -110,7 +111,7 @@ namespace Orchard.Blogs.Controllers {
|
|||||||
if (blog == null)
|
if (blog == null)
|
||||||
return new NotFoundResult();
|
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;
|
blogPost.Item.Blog = blog;
|
||||||
|
|
||||||
var model = new CreateBlogPostViewModel {
|
var model = new CreateBlogPostViewModel {
|
||||||
@@ -122,7 +123,7 @@ namespace Orchard.Blogs.Controllers {
|
|||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ActionResult Create(string blogSlug, CreateBlogPostViewModel model) {
|
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();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
//TODO: (erikpo) Move looking up the current blog up into a modelbinder
|
//TODO: (erikpo) Move looking up the current blog up into a modelbinder
|
||||||
@@ -136,24 +137,24 @@ namespace Orchard.Blogs.Controllers {
|
|||||||
publishNow = true;
|
publishNow = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
BlogPost blogPost = Services.ContentManager.Create<BlogPost>("blogpost", publishNow ? VersionOptions.Published : VersionOptions.Draft, bp => { bp.Blog = blog; });
|
BlogPost blogPost = _services.ContentManager.Create<BlogPost>("blogpost", publishNow ? VersionOptions.Published : VersionOptions.Draft, bp => { bp.Blog = blog; });
|
||||||
model.BlogPost = Services.ContentManager.UpdateEditorModel(blogPost, this);
|
model.BlogPost = _services.ContentManager.UpdateEditorModel(blogPost, this);
|
||||||
|
|
||||||
if (!ModelState.IsValid) {
|
if (!ModelState.IsValid) {
|
||||||
Services.TransactionManager.Cancel();
|
_services.TransactionManager.Cancel();
|
||||||
|
|
||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TEMP: (erikpo) ensure information has committed for this record
|
//TEMP: (erikpo) ensure information has committed for this record
|
||||||
var session = _sessionLocator.For(typeof(BlogPostRecord));
|
var session = _sessionLocator.For(typeof(ContentItemRecord));
|
||||||
session.Flush();
|
session.Flush();
|
||||||
|
|
||||||
return Redirect(Url.BlogPost(blogSlug, model.BlogPost.Item.Slug));
|
return Redirect(Url.BlogPost(blogSlug, model.BlogPost.Item.Slug));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult Edit(string blogSlug, string postSlug) {
|
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();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
//TODO: (erikpo) Move looking up the current blog up into a modelbinder
|
//TODO: (erikpo) Move looking up the current blog up into a modelbinder
|
||||||
@@ -168,7 +169,7 @@ namespace Orchard.Blogs.Controllers {
|
|||||||
return new NotFoundResult();
|
return new NotFoundResult();
|
||||||
|
|
||||||
var model = new BlogPostEditViewModel {
|
var model = new BlogPostEditViewModel {
|
||||||
BlogPost = Services.ContentManager.BuildEditorModel(post)
|
BlogPost = _services.ContentManager.BuildEditorModel(post)
|
||||||
};
|
};
|
||||||
|
|
||||||
return View(model);
|
return View(model);
|
||||||
@@ -176,7 +177,7 @@ namespace Orchard.Blogs.Controllers {
|
|||||||
|
|
||||||
[HttpPost, ActionName("Edit")]
|
[HttpPost, ActionName("Edit")]
|
||||||
public ActionResult EditPOST(string blogSlug, string postSlug) {
|
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();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
//TODO: (erikpo) Move looking up the current blog up into a modelbinder
|
//TODO: (erikpo) Move looking up the current blog up into a modelbinder
|
||||||
@@ -201,25 +202,25 @@ namespace Orchard.Blogs.Controllers {
|
|||||||
_blogPostService.Unpublish(post);
|
_blogPostService.Unpublish(post);
|
||||||
|
|
||||||
var model = new BlogPostEditViewModel {
|
var model = new BlogPostEditViewModel {
|
||||||
BlogPost = Services.ContentManager.UpdateEditorModel(post, this)
|
BlogPost = _services.ContentManager.UpdateEditorModel(post, this)
|
||||||
};
|
};
|
||||||
|
|
||||||
TryUpdateModel(model);
|
TryUpdateModel(model);
|
||||||
|
|
||||||
if (!ModelState.IsValid) {
|
if (!ModelState.IsValid) {
|
||||||
Services.TransactionManager.Cancel();
|
_services.TransactionManager.Cancel();
|
||||||
|
|
||||||
return View(model);
|
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));
|
return Redirect(Url.BlogPostEdit(blog.Slug, post.Slug));
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ActionResult Delete(string blogSlug, string postSlug) {
|
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();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
//TODO: (erikpo) Move looking up the current blog up into a modelbinder
|
//TODO: (erikpo) Move looking up the current blog up into a modelbinder
|
||||||
@@ -235,7 +236,7 @@ namespace Orchard.Blogs.Controllers {
|
|||||||
|
|
||||||
_blogPostService.Delete(post);
|
_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));
|
return Redirect(Url.BlogForAdmin(blogSlug));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ using Orchard.ContentManagement;
|
|||||||
using Orchard.Security;
|
using Orchard.Security;
|
||||||
|
|
||||||
namespace Orchard.Blogs.Models {
|
namespace Orchard.Blogs.Models {
|
||||||
public class BlogPost : ContentPart<BlogPostRecord> {
|
public class BlogPost : ContentPart {
|
||||||
[HiddenInput(DisplayValue = false)]
|
[HiddenInput(DisplayValue = false)]
|
||||||
public int Id { get { return ContentItem.Id; } }
|
public int Id { get { return ContentItem.Id; } }
|
||||||
|
|
||||||
@@ -35,8 +35,8 @@ namespace Orchard.Blogs.Models {
|
|||||||
|
|
||||||
public DateTime? Published
|
public DateTime? Published
|
||||||
{
|
{
|
||||||
get { return Record.Published; }
|
get { return this.As<CommonAspect>().PublishedUtc; }
|
||||||
set { Record.Published = value; }
|
set { this.As<CommonAspect>().PublishedUtc = value; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,24 +1,21 @@
|
|||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Orchard.Blogs.Controllers;
|
using Orchard.Blogs.Controllers;
|
||||||
using Orchard.Core.Common.Models;
|
using Orchard.Core.Common.Models;
|
||||||
using Orchard.Data;
|
|
||||||
using Orchard.ContentManagement.Handlers;
|
using Orchard.ContentManagement.Handlers;
|
||||||
|
using Orchard.Core.Common.Records;
|
||||||
|
using Orchard.Data;
|
||||||
|
|
||||||
namespace Orchard.Blogs.Models {
|
namespace Orchard.Blogs.Models {
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public class BlogPostHandler : ContentHandler {
|
public class BlogPostHandler : ContentHandler {
|
||||||
|
public BlogPostHandler(IRepository<CommonVersionRecord> commonRepository) {
|
||||||
public BlogPostHandler(IRepository<BlogPostRecord> repository) {
|
|
||||||
|
|
||||||
Filters.Add(new ActivatingFilter<BlogPost>(BlogPostDriver.ContentType.Name));
|
Filters.Add(new ActivatingFilter<BlogPost>(BlogPostDriver.ContentType.Name));
|
||||||
Filters.Add(new ActivatingFilter<CommonAspect>(BlogPostDriver.ContentType.Name));
|
Filters.Add(new ActivatingFilter<CommonAspect>(BlogPostDriver.ContentType.Name));
|
||||||
Filters.Add(new ActivatingFilter<RoutableAspect>(BlogPostDriver.ContentType.Name));
|
Filters.Add(new ActivatingFilter<RoutableAspect>(BlogPostDriver.ContentType.Name));
|
||||||
Filters.Add(new ActivatingFilter<BodyAspect>(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++);
|
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.Data.Conventions;
|
||||||
using Orchard.ContentManagement.Records;
|
using Orchard.ContentManagement.Records;
|
||||||
|
|
||||||
namespace Orchard.Blogs.Models {
|
namespace Orchard.Blogs.Models {
|
||||||
public class BlogRecord : ContentPartRecord {
|
public class BlogRecord : ContentPartRecord {
|
||||||
[CascadeAllDeleteOrphan]
|
[CascadeAllDeleteOrphan]
|
||||||
public virtual IEnumerable<BlogPostRecord> Posts { get; set; }
|
|
||||||
public virtual string Description { get; set; }
|
public virtual string Description { get; set; }
|
||||||
//public virtual bool Enabled { get; set; }
|
//public virtual bool Enabled { get; set; }
|
||||||
public virtual int PostCount { get; set; }
|
public virtual int PostCount { get; set; }
|
||||||
|
|||||||
@@ -91,7 +91,6 @@
|
|||||||
<Compile Include="Models\BlogHandler.cs" />
|
<Compile Include="Models\BlogHandler.cs" />
|
||||||
<Compile Include="Models\BlogPost.cs" />
|
<Compile Include="Models\BlogPost.cs" />
|
||||||
<Compile Include="Models\BlogPostHandler.cs" />
|
<Compile Include="Models\BlogPostHandler.cs" />
|
||||||
<Compile Include="Models\BlogPostRecord.cs" />
|
|
||||||
<Compile Include="Models\BlogRecord.cs" />
|
<Compile Include="Models\BlogRecord.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Routes.cs" />
|
<Compile Include="Routes.cs" />
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ namespace Orchard.Blogs.Services {
|
|||||||
|
|
||||||
public BlogPost Get(Blog blog, string slug, VersionOptions versionOptions) {
|
public BlogPost Get(Blog blog, string slug, VersionOptions versionOptions) {
|
||||||
return
|
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().
|
Join<CommonRecord>().Where(cr => cr.Container == blog.Record.ContentItemRecord).List().
|
||||||
SingleOrDefault();
|
SingleOrDefault().As<BlogPost>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<BlogPost> Get(Blog blog) {
|
public IEnumerable<BlogPost> Get(Blog blog) {
|
||||||
@@ -29,7 +29,7 @@ namespace Orchard.Blogs.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<BlogPost> Get(Blog blog, VersionOptions versionOptions) {
|
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) {
|
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) &&
|
||||||
cr.CreatedUtc < new DateTime(archiveData.Year + 1, 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) {
|
public void Delete(BlogPost blogPost) {
|
||||||
@@ -71,9 +71,9 @@ namespace Orchard.Blogs.Services {
|
|||||||
blogPost.Published = null;
|
blogPost.Published = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IContentQuery<BlogPost, CommonRecord> GetBlogQuery(ContentPart<BlogRecord> blog, VersionOptions versionOptions) {
|
private IContentQuery<ContentItem, CommonRecord> GetBlogQuery(ContentPart<BlogRecord> blog, VersionOptions versionOptions) {
|
||||||
return
|
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);
|
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>();
|
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) */
|
/* Query(params string[] contentTypeNames) */
|
||||||
|
|
||||||
public static IContentQuery<ContentItem> Query(this IContentManager manager, params string[] contentTypeNames) {
|
public static IContentQuery<ContentItem> Query(this IContentManager manager, params string[] contentTypeNames) {
|
||||||
|
|||||||
Reference in New Issue
Block a user