#17261 Changing BlogSlugConstraint to BlogPathContraint to handle homepage blogs

Work Item: 17261

--HG--
branch : dev
extra : transplant_source : Y%BC%1F%0E%A2%C5%10%BE%3B%82P%21%FC%FA%ED%FE%A7%26%9B%92
This commit is contained in:
Sebastien Ros
2011-01-31 13:25:16 -08:00
parent fc261cdb3a
commit 2680f394ba
15 changed files with 122 additions and 88 deletions

View File

@@ -1,5 +1,6 @@
using System.Linq;
using Orchard.Blogs.Models;
using Orchard.Blogs.Routing;
using Orchard.Blogs.Services;
using Orchard.Blogs.ViewModels;
using Orchard.ContentManagement;
@@ -9,18 +10,22 @@ namespace Orchard.Blogs.Drivers {
public class BlogArchivesPartDriver : ContentPartDriver<BlogArchivesPart> {
private readonly IBlogService _blogService;
private readonly IBlogPostService _blogPostService;
private readonly IBlogPathConstraint _blogPathConstraint;
public BlogArchivesPartDriver(IBlogService blogService, IBlogPostService blogPostService) {
public BlogArchivesPartDriver(
IBlogService blogService,
IBlogPostService blogPostService,
IBlogPathConstraint blogPathConstraint) {
_blogService = blogService;
_blogPostService = blogPostService;
_blogPathConstraint = blogPathConstraint;
}
protected override DriverResult Display(BlogArchivesPart part, string displayType, dynamic shapeHelper) {
return ContentShape("Parts_Blogs_BlogArchives",
() => {
BlogPart blog = null;
if (!string.IsNullOrWhiteSpace(part.ForBlog))
blog = _blogService.Get(part.ForBlog);
var path = _blogPathConstraint.FindPath(part.ForBlog);
BlogPart blog = _blogService.Get(path);
if (blog == null)
return null;
@@ -31,7 +36,7 @@ namespace Orchard.Blogs.Drivers {
protected override DriverResult Editor(BlogArchivesPart part, dynamic shapeHelper) {
var viewModel = new BlogArchivesViewModel {
Slug = part.ForBlog,
Path = part.ForBlog,
Blogs = _blogService.Get().ToList().OrderBy(b => b.Name)
};
@@ -42,7 +47,7 @@ namespace Orchard.Blogs.Drivers {
protected override DriverResult Editor(BlogArchivesPart part, IUpdateModel updater, dynamic shapeHelper) {
var viewModel = new BlogArchivesViewModel();
if (updater.TryUpdateModel(viewModel, Prefix, null, null)) {
part.ForBlog = viewModel.Slug;
part.ForBlog = viewModel.Path;
}
return Editor(part, shapeHelper);