mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-18 17:47:54 +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,29 +0,0 @@
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Blogs.Extensions;
|
||||
using Orchard.Blogs.Models;
|
||||
using Orchard.Blogs.Services;
|
||||
using Orchard.Blogs.ViewModels;
|
||||
|
||||
namespace Orchard.Blogs.Controllers {
|
||||
public class AdminController : Controller {
|
||||
private readonly IBlogService _blogService;
|
||||
|
||||
public AdminController(IBlogService blogService) {
|
||||
_blogService = blogService;
|
||||
}
|
||||
|
||||
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 });
|
||||
}
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -2,6 +2,7 @@ using Orchard.Models;
|
||||
|
||||
namespace Orchard.Blogs.Models {
|
||||
public class Blog : ContentPart<BlogRecord> {
|
||||
public int Id { get { return ContentItem.Id; } }
|
||||
public string Name { get { return Record.Name; } }
|
||||
public string Slug { get { return Record.Slug; } }
|
||||
public bool Enabled { get { return Record.Enabled; } }
|
||||
|
@@ -65,7 +65,6 @@
|
||||
<Compile Include="Extensions\BlogCreateViewModelExtensions.cs" />
|
||||
<Compile Include="Routing\IsBlogConstraint.cs" />
|
||||
<Compile Include="Services\BlogService.cs" />
|
||||
<Compile Include="Controllers\AdminController.cs" />
|
||||
<Compile Include="Controllers\BlogController.cs" />
|
||||
<Compile Include="Models\Blog.cs" />
|
||||
<Compile Include="Models\BlogProvider.cs" />
|
||||
@@ -82,12 +81,13 @@
|
||||
<Compile Include="ViewModels\BlogsViewModel.cs" />
|
||||
<Compile Include="ViewModels\BlogViewModel.cs" />
|
||||
<Compile Include="ViewModels\CreateBlogViewModel.cs" />
|
||||
<Compile Include="ViewModels\BlogEditViewModel.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Package.txt" />
|
||||
<Content Include="Views\Admin\Create.aspx" />
|
||||
<Content Include="Views\Admin\Index.aspx" />
|
||||
<Content Include="Views\Blog\Create.aspx" />
|
||||
<Content Include="Views\BlogPost\ListByBlog.aspx" />
|
||||
<Content Include="Views\Blog\Edit.aspx" />
|
||||
<Content Include="Views\Blog\Item.aspx" />
|
||||
<Content Include="Views\Blog\List.aspx" />
|
||||
<Content Include="Web.config" />
|
||||
|
@@ -23,7 +23,37 @@ namespace Orchard.Blogs {
|
||||
return new[] {
|
||||
new RouteDescriptor {
|
||||
Route = new Route(
|
||||
"Blogs",
|
||||
"Admin/Blogs/Create",
|
||||
new RouteValueDictionary {
|
||||
{"area", "Orchard.Blogs"},
|
||||
{"controller", "Blog"},
|
||||
{"action", "Create"}
|
||||
},
|
||||
new RouteValueDictionary(),
|
||||
new RouteValueDictionary {
|
||||
{"area", "Orchard.Blogs"}
|
||||
},
|
||||
new MvcRouteHandler())
|
||||
},
|
||||
new RouteDescriptor {
|
||||
Route = new Route(
|
||||
"Admin/Blogs/{blogSlug}/Edit",
|
||||
new RouteValueDictionary {
|
||||
{"area", "Orchard.Blogs"},
|
||||
{"controller", "Blog"},
|
||||
{"action", "Edit"}
|
||||
},
|
||||
new RouteValueDictionary {
|
||||
{"blogSlug", new IsBlogConstraint(_blogService)}
|
||||
},
|
||||
new RouteValueDictionary {
|
||||
{"area", "Orchard.Blogs"}
|
||||
},
|
||||
new MvcRouteHandler())
|
||||
},
|
||||
new RouteDescriptor {
|
||||
Route = new Route(
|
||||
"Admin/Blogs",
|
||||
new RouteValueDictionary {
|
||||
{"area", "Orchard.Blogs"},
|
||||
{"controller", "Blog"},
|
||||
@@ -43,7 +73,7 @@ namespace Orchard.Blogs {
|
||||
{"controller", "Blog"},
|
||||
{"action", "Item"}
|
||||
},
|
||||
new RouteValueDictionary() {
|
||||
new RouteValueDictionary {
|
||||
{"blogSlug", new IsBlogConstraint(_blogService)}
|
||||
},
|
||||
new RouteValueDictionary {
|
||||
|
@@ -0,0 +1,36 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Blogs.Models;
|
||||
using Orchard.Models;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
using Orchard.UI.Models;
|
||||
|
||||
namespace Orchard.Blogs.ViewModels {
|
||||
public class BlogEditViewModel : AdminViewModel {
|
||||
public Blog Blog { get; set; }
|
||||
public IEnumerable<ModelTemplate> Editors { get; set; }
|
||||
|
||||
[HiddenInput(DisplayValue = false)]
|
||||
public int Id {
|
||||
get { return Blog.Id; }
|
||||
}
|
||||
|
||||
[Required]
|
||||
public string Name {
|
||||
get { return Blog.As<Blog>().Record.Name; }
|
||||
set { Blog.As<Blog>().Record.Name = value; }
|
||||
}
|
||||
|
||||
[Required]
|
||||
public string Slug {
|
||||
get { return Blog.As<Blog>().Record.Slug; }
|
||||
set { Blog.As<Blog>().Record.Slug = value; }
|
||||
}
|
||||
|
||||
public bool Enabled {
|
||||
get { return Blog.As<Blog>().Record.Enabled; }
|
||||
set { Blog.As<Blog>().Record.Enabled = value; }
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<Orchard.Blogs.ViewModels.CreateBlogViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Security" %>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html" %>
|
||||
<% Html.Include("Header"); %>
|
||||
<div class="yui-u">
|
||||
<h2 class="separator">
|
||||
Add a new Blog</h2>
|
||||
|
||||
</div>
|
||||
<div class="yui-u">
|
||||
<%using (Html.BeginForm()) { %>
|
||||
<ol>
|
||||
<%= Html.ValidationSummary() %>
|
||||
<%= Html.EditorForModel() %>
|
||||
<li class="clearLayout">
|
||||
<input class="button" type="submit" value="Create" />
|
||||
<%=Html.ActionLink("Cancel", "Index", new{}, new{@class="button"}) %></li>
|
||||
</ol>
|
||||
<%}/*EndForm*/%>
|
||||
</div>
|
||||
<% Html.Include("Footer"); %>
|
25
src/Orchard.Web/Packages/Orchard.Blogs/Views/Blog/Edit.aspx
Normal file
25
src/Orchard.Web/Packages/Orchard.Blogs/Views/Blog/Edit.aspx
Normal file
@@ -0,0 +1,25 @@
|
||||
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<BlogEditViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Blogs.ViewModels"%>
|
||||
<%@ Import Namespace="Orchard.Security" %>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html" %>
|
||||
<% Html.Include("Header"); %>
|
||||
<div class="yui-u">
|
||||
<h2 class="separator">
|
||||
Edit Blog</h2>
|
||||
<p class="bottomSpacer">
|
||||
<%=Html.ActionLink("Blogs", "List", "Blog") %> > Edit #<%= Model.Id%> <strong><%=Html.Encode(Model.Name)%></strong>
|
||||
</p>
|
||||
</div>
|
||||
<div class="yui-u">
|
||||
<%using (Html.BeginForm()) { %>
|
||||
<ol>
|
||||
<%= Html.ValidationSummary() %>
|
||||
<%= Html.EditorForModel() %>
|
||||
<li class="clearLayout">
|
||||
<input class="button" type="submit" value="Save" />
|
||||
<%=Html.ActionLink("Cancel", "Index", new{}, new{@class="button"}) %>
|
||||
</li>
|
||||
</ol>
|
||||
<%}/*EndForm*/%>
|
||||
</div>
|
||||
<% Html.Include("Footer"); %>
|
Reference in New Issue
Block a user