Orchard/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogController.cs
Sebastien Ros 367066e741 Handling slashed in blog routes (with archive and rsd)
--HG--
branch : autoroute
2012-01-31 17:07:00 -08:00

84 lines
3.1 KiB
C#

using System.Linq;
using System.Web.Mvc;
using Orchard.Blogs.Extensions;
using Orchard.Blogs.Routing;
using Orchard.Blogs.Services;
using Orchard.Core.Feeds;
using Orchard.DisplayManagement;
using Orchard.Logging;
using Orchard.Mvc;
using Orchard.Themes;
using Orchard.UI.Navigation;
using Orchard.Settings;
using Orchard.ContentManagement;
using Orchard.Blogs.Models;
namespace Orchard.Blogs.Controllers {
[Themed]
public class BlogController : Controller {
private readonly IOrchardServices _services;
private readonly IBlogService _blogService;
private readonly IBlogPostService _blogPostService;
private readonly IBlogPathConstraint _blogPathConstraint;
private readonly IFeedManager _feedManager;
private readonly ISiteService _siteService;
public BlogController(
IOrchardServices services,
IBlogService blogService,
IBlogPostService blogPostService,
IBlogPathConstraint blogPathConstraint,
IFeedManager feedManager,
IShapeFactory shapeFactory,
ISiteService siteService) {
_services = services;
_blogService = blogService;
_blogPostService = blogPostService;
_blogPathConstraint = blogPathConstraint;
_feedManager = feedManager;
_siteService = siteService;
Logger = NullLogger.Instance;
Shape = shapeFactory;
}
dynamic Shape { get; set; }
protected ILogger Logger { get; set; }
public ActionResult List() {
var blogs = _blogService.Get().Select(b => _services.ContentManager.BuildDisplay(b, "Summary"));
var list = Shape.List();
list.AddRange(blogs);
dynamic viewModel = Shape.ViewModel()
.ContentItems(list);
// Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
return View((object)viewModel);
}
public ActionResult Item(int blogId, PagerParameters pagerParameters) {
Pager pager = new Pager(_siteService.GetSiteSettings(), pagerParameters);
var blogPart = _blogService.Get(blogId, VersionOptions.Published).As<BlogPart>();
if (blogPart == null)
return HttpNotFound();
_feedManager.Register(blogPart);
var blogPosts = _blogPostService.Get(blogPart, pager.GetStartIndex(), pager.PageSize)
.Select(b => _services.ContentManager.BuildDisplay(b, "Summary"));
dynamic blog = _services.ContentManager.BuildDisplay(blogPart);
var list = Shape.List();
list.AddRange(blogPosts);
blog.Content.Add(Shape.Parts_Blogs_BlogPost_List(ContentItems: list), "5");
var totalItemCount = _blogPostService.PostCount(blogPart);
blog.Content.Add(Shape.Pager(pager).TotalItemCount(totalItemCount), "Content:after");
return new ShapeResult(this, blog);
}
}
}