2009-11-24 00:26:24 +08:00
|
|
|
using System.Collections.Generic;
|
2009-11-21 07:31:49 +08:00
|
|
|
using System.Web.Mvc;
|
2009-11-24 01:34:46 +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;
|
2009-11-24 03:24:53 +08:00
|
|
|
using Orchard.Data;
|
2009-11-24 01:34:46 +08:00
|
|
|
using Orchard.Localization;
|
|
|
|
using Orchard.Models;
|
|
|
|
using Orchard.Models.Driver;
|
2009-11-21 07:31:49 +08:00
|
|
|
using Orchard.Mvc.Results;
|
2009-11-24 01:34:46 +08:00
|
|
|
using Orchard.UI.Notify;
|
2009-11-21 07:31:49 +08:00
|
|
|
|
|
|
|
namespace Orchard.Blogs.Controllers {
|
2009-11-25 13:45:50 +08:00
|
|
|
[ValidateInput(false)]
|
2009-11-24 01:34:46 +08:00
|
|
|
public class BlogController : Controller, IUpdateModel {
|
2009-12-02 04:24:18 +08:00
|
|
|
private readonly ISessionLocator _sessionLocator;
|
2009-11-24 01:34:46 +08:00
|
|
|
private readonly IContentManager _contentManager;
|
|
|
|
private readonly INotifier _notifier;
|
2009-11-21 07:31:49 +08:00
|
|
|
private readonly IBlogService _blogService;
|
2009-11-24 00:26:24 +08:00
|
|
|
private readonly IBlogPostService _blogPostService;
|
2009-11-21 07:31:49 +08:00
|
|
|
|
2009-12-02 04:24:18 +08:00
|
|
|
public BlogController(ISessionLocator sessionLocator, IContentManager contentManager, INotifier notifier, IBlogService blogService, IBlogPostService blogPostService) {
|
|
|
|
_sessionLocator = sessionLocator;
|
2009-11-24 01:34:46 +08:00
|
|
|
_contentManager = contentManager;
|
|
|
|
_notifier = notifier;
|
2009-11-21 07:31:49 +08:00
|
|
|
_blogService = blogService;
|
2009-11-24 00:26:24 +08:00
|
|
|
_blogPostService = blogPostService;
|
2009-11-24 01:34:46 +08:00
|
|
|
T = NullLocalizer.Instance;
|
2009-11-21 07:31:49 +08:00
|
|
|
}
|
|
|
|
|
2009-11-24 01:34:46 +08:00
|
|
|
public Localizer T { get; set; }
|
|
|
|
|
2009-12-03 09:37:45 +08:00
|
|
|
public ActionResult List() {
|
2009-12-02 14:16:22 +08:00
|
|
|
return View(new BlogsViewModel { Blogs = _blogService.Get() });
|
2009-11-21 07:31:49 +08:00
|
|
|
}
|
|
|
|
|
2009-12-03 09:37:45 +08:00
|
|
|
public ActionResult ListForAdmin() {
|
|
|
|
return View(new BlogsForAdminViewModel { Blogs = _blogService.Get() });
|
|
|
|
}
|
|
|
|
|
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-11-24 00:26:24 +08:00
|
|
|
IEnumerable<BlogPost> posts = _blogPostService.Get(blog);
|
|
|
|
|
2009-12-02 14:16:22 +08:00
|
|
|
return View(new BlogViewModel { Blog = blog, Posts = posts });
|
2009-11-21 07:31:49 +08:00
|
|
|
}
|
2009-11-24 01:34:46 +08:00
|
|
|
|
2009-12-03 12:30:34 +08:00
|
|
|
//TODO: (erikpo) Should move the slug parameter and get call and null check up into a model binder
|
|
|
|
public ActionResult ItemForAdmin(string blogSlug)
|
|
|
|
{
|
|
|
|
Blog blog = _blogService.Get(blogSlug);
|
|
|
|
|
|
|
|
if (blog == null)
|
|
|
|
return new NotFoundResult();
|
|
|
|
|
|
|
|
IEnumerable<BlogPost> posts = _blogPostService.Get(blog);
|
|
|
|
|
|
|
|
return View(new BlogForAdminViewModel { Blog = blog, Posts = posts });
|
|
|
|
}
|
|
|
|
|
2009-11-24 01:34:46 +08:00
|
|
|
public ActionResult Create() {
|
|
|
|
return View(new CreateBlogViewModel());
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
public ActionResult Create(CreateBlogViewModel model) {
|
|
|
|
if (!ModelState.IsValid)
|
|
|
|
return View(model);
|
|
|
|
|
2009-11-25 09:34:23 +08:00
|
|
|
Blog blog = _blogService.Create(model.ToCreateBlogParams());
|
2009-12-02 14:16:22 +08:00
|
|
|
|
2009-11-24 03:24:53 +08:00
|
|
|
//TEMP: (erikpo) ensure information has committed for this record
|
|
|
|
var session = _sessionLocator.For(typeof(BlogRecord));
|
|
|
|
session.Flush();
|
2009-11-24 01:34:46 +08:00
|
|
|
|
2009-12-03 09:37:45 +08:00
|
|
|
//TODO: (erikpo) This should redirect to the blog homepage in the admin once that page is created
|
|
|
|
return Redirect(Url.BlogsForAdmin());
|
2009-11-24 01:34:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public ActionResult Edit(string blogSlug) {
|
2009-12-02 04:24:18 +08:00
|
|
|
//TODO: (erikpo) Move looking up the current blog up into a modelbinder
|
|
|
|
Blog blog = _blogService.Get(blogSlug);
|
|
|
|
|
|
|
|
if (blog == null)
|
|
|
|
return new NotFoundResult();
|
|
|
|
|
|
|
|
var model = new BlogEditViewModel { Blog = blog };
|
2009-12-02 14:16:22 +08:00
|
|
|
model.ItemView = _contentManager.GetEditors(model.Blog.ContentItem, "");
|
2009-11-24 01:34:46 +08:00
|
|
|
return View(model);
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
public ActionResult Edit(string blogSlug, FormCollection input) {
|
2009-12-02 04:24:18 +08:00
|
|
|
//TODO: (erikpo) Move looking up the current blog up into a modelbinder
|
|
|
|
Blog blog = _blogService.Get(blogSlug);
|
|
|
|
|
|
|
|
if (blog == null)
|
|
|
|
return new NotFoundResult();
|
|
|
|
|
|
|
|
var model = new BlogEditViewModel { Blog = blog };
|
2009-12-02 14:16:22 +08:00
|
|
|
model.ItemView = _contentManager.UpdateEditors(model.Blog.ContentItem, "",this);
|
2009-11-24 01:34:46 +08:00
|
|
|
|
2009-11-24 03:24:53 +08:00
|
|
|
IValueProvider values = input.ToValueProvider();
|
|
|
|
if (!TryUpdateModel(model, values))
|
2009-11-24 01:34:46 +08:00
|
|
|
return View(model);
|
|
|
|
|
|
|
|
_notifier.Information(T("Blog information updated"));
|
|
|
|
|
2009-12-02 04:24:18 +08:00
|
|
|
//TODO: (erikpo) This should redirect to the blog homepage in the admin once that page is created
|
2009-12-03 09:37:45 +08:00
|
|
|
return Redirect(Url.BlogsForAdmin());
|
2009-11-24 01:34:46 +08:00
|
|
|
}
|
|
|
|
|
2009-12-04 03:50:57 +08:00
|
|
|
[HttpPost]
|
|
|
|
public ActionResult Delete(string blogSlug) {
|
|
|
|
//TODO: (erikpo) Move looking up the current blog up into a modelbinder
|
|
|
|
Blog blog = _blogService.Get(blogSlug);
|
|
|
|
|
|
|
|
if (blog == null)
|
|
|
|
return new NotFoundResult();
|
|
|
|
|
|
|
|
_blogService.Delete(blog);
|
|
|
|
|
|
|
|
_notifier.Information(T("Blog was successfully deleted"));
|
|
|
|
|
|
|
|
return Redirect(Url.Blogs());
|
|
|
|
}
|
|
|
|
|
2009-11-24 01:34:46 +08:00
|
|
|
bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) {
|
|
|
|
return TryUpdateModel(model, prefix, includeProperties, excludeProperties);
|
|
|
|
}
|
2009-11-21 07:31:49 +08:00
|
|
|
}
|
|
|
|
}
|