2009-12-08 07:37:47 +08:00
|
|
|
using System.Linq;
|
2009-11-21 07:31:49 +08:00
|
|
|
using System.Web.Mvc;
|
2010-01-28 07:52:07 +08:00
|
|
|
using Orchard.Blogs.Extensions;
|
2009-11-21 07:31:49 +08:00
|
|
|
using Orchard.Blogs.Models;
|
|
|
|
using Orchard.Blogs.Services;
|
2009-11-24 00:26:24 +08:00
|
|
|
using Orchard.Blogs.ViewModels;
|
2010-01-19 14:29:58 +08:00
|
|
|
using Orchard.Core.Feeds;
|
2009-11-21 07:31:49 +08:00
|
|
|
using Orchard.Mvc.Results;
|
|
|
|
|
|
|
|
namespace Orchard.Blogs.Controllers {
|
2010-01-12 06:07:03 +08:00
|
|
|
public class BlogController : Controller {
|
2010-01-12 05:05:24 +08:00
|
|
|
private readonly IOrchardServices _services;
|
2009-11-21 07:31:49 +08:00
|
|
|
private readonly IBlogService _blogService;
|
2010-01-19 14:29:58 +08:00
|
|
|
private readonly IFeedManager _feedManager;
|
2009-11-21 07:31:49 +08:00
|
|
|
|
2010-01-19 14:29:58 +08:00
|
|
|
public BlogController(
|
|
|
|
IOrchardServices services,
|
|
|
|
IBlogService blogService,
|
|
|
|
IFeedManager feedManager) {
|
2010-01-12 05:05:24 +08:00
|
|
|
_services = services;
|
2009-11-21 07:31:49 +08:00
|
|
|
_blogService = blogService;
|
2010-01-19 14:29:58 +08:00
|
|
|
_feedManager = feedManager;
|
2009-11-21 07:31:49 +08:00
|
|
|
}
|
|
|
|
|
2009-12-03 09:37:45 +08:00
|
|
|
public ActionResult List() {
|
2009-12-08 17:21:13 +08:00
|
|
|
var model = new BlogsViewModel {
|
2010-01-12 05:05:24 +08:00
|
|
|
Blogs = _blogService.Get().Select(b => _services.ContentManager.BuildDisplayModel(b, "Summary"))
|
2009-12-08 17:21:13 +08:00
|
|
|
};
|
2009-12-08 14:31:44 +08:00
|
|
|
|
2009-12-08 17:21:13 +08:00
|
|
|
return View(model);
|
2009-11-21 07:31:49 +08:00
|
|
|
}
|
|
|
|
|
2009-11-24 01:34:46 +08:00
|
|
|
//TODO: (erikpo) Should move the slug parameter and get call and null check up into a model binder
|
2009-11-21 08:38:41 +08:00
|
|
|
public ActionResult Item(string blogSlug) {
|
|
|
|
Blog blog = _blogService.Get(blogSlug);
|
2009-11-21 07:31:49 +08:00
|
|
|
|
|
|
|
if (blog == null)
|
|
|
|
return new NotFoundResult();
|
|
|
|
|
2009-12-08 17:21:13 +08:00
|
|
|
var model = new BlogViewModel {
|
2010-01-12 05:05:24 +08:00
|
|
|
Blog = _services.ContentManager.BuildDisplayModel(blog, "Detail")
|
2009-12-08 17:21:13 +08:00
|
|
|
};
|
|
|
|
|
2010-01-19 14:29:58 +08:00
|
|
|
_feedManager.Register(blog);
|
|
|
|
|
2009-12-08 17:21:13 +08:00
|
|
|
return View(model);
|
2009-11-21 07:31:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|