mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-24 13:33:34 +08:00
Did some more url refining for Blogs and setup and hooked up blog edit page.
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4041914
This commit is contained in:
@@ -1,25 +1,39 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Blogs.Extensions;
|
||||
using Orchard.Blogs.Models;
|
||||
using Orchard.Blogs.Services;
|
||||
using Orchard.Blogs.ViewModels;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Models;
|
||||
using Orchard.Models.Driver;
|
||||
using Orchard.Mvc.Results;
|
||||
using Orchard.Security;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Blogs.Controllers {
|
||||
public class BlogController : Controller {
|
||||
public class BlogController : Controller, IUpdateModel {
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly INotifier _notifier;
|
||||
private readonly IBlogService _blogService;
|
||||
private readonly IBlogPostService _blogPostService;
|
||||
|
||||
public BlogController(IBlogService blogService, IBlogPostService blogPostService) {
|
||||
public BlogController(IContentManager contentManager, INotifier notifier, IBlogService blogService, IBlogPostService blogPostService) {
|
||||
_contentManager = contentManager;
|
||||
_notifier = notifier;
|
||||
_blogService = blogService;
|
||||
_blogPostService = blogPostService;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public IUser CurrentUser { get; set; }
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public ActionResult List() {
|
||||
return View(new BlogsViewModel {Blogs = _blogService.Get()});
|
||||
}
|
||||
|
||||
//TODO: (erikpo) Should think about moving the slug parameter and get call and null check up into a model binder or action filter
|
||||
//TODO: (erikpo) Should move the slug parameter and get call and null check up into a model binder
|
||||
public ActionResult Item(string blogSlug) {
|
||||
Blog blog = _blogService.Get(blogSlug);
|
||||
|
||||
@@ -30,5 +44,42 @@ namespace Orchard.Blogs.Controllers {
|
||||
|
||||
return View(new BlogViewModel {Blog = blog, Posts = posts});
|
||||
}
|
||||
|
||||
public ActionResult Create() {
|
||||
return View(new CreateBlogViewModel());
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Create(CreateBlogViewModel model) {
|
||||
if (!ModelState.IsValid)
|
||||
return View(model);
|
||||
|
||||
Blog blog = _blogService.CreateBlog(model.ToCreateBlogParams());
|
||||
|
||||
return RedirectToAction("edit", new { blog.Record.Id });
|
||||
}
|
||||
|
||||
public ActionResult Edit(string blogSlug) {
|
||||
var model = new BlogEditViewModel { Blog = _blogService.Get(blogSlug) };
|
||||
model.Editors = _contentManager.GetEditors(model.Blog.ContentItem);
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Edit(string blogSlug, FormCollection input) {
|
||||
var model = new BlogEditViewModel { Blog = _blogService.Get(blogSlug) };
|
||||
model.Editors = _contentManager.UpdateEditors(model.Blog.ContentItem, this);
|
||||
|
||||
if (!TryUpdateModel(model, input.ToValueProvider()))
|
||||
return View(model);
|
||||
|
||||
_notifier.Information(T("Blog information updated"));
|
||||
|
||||
return RedirectToAction("Edit", new { blogSlug });
|
||||
}
|
||||
|
||||
bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) {
|
||||
return TryUpdateModel(model, prefix, includeProperties, excludeProperties);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user