mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 03:25:23 +08:00
Setting up "Add to home page" for blog create
--HG-- branch : dev
This commit is contained in:
@@ -49,7 +49,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Create(CreateBlogViewModel model) {
|
||||
public ActionResult Create(CreateBlogViewModel model, bool PromoteToHomePage) {
|
||||
//TODO: (erikpo) Might think about moving this to an ActionFilter/Attribute
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageBlogs, T("Couldn't create blog")))
|
||||
return new HttpUnauthorizedResult();
|
||||
@@ -61,6 +61,9 @@ namespace Orchard.Blogs.Controllers {
|
||||
|
||||
_blogService.Create(model.Blog.Item);
|
||||
|
||||
if (PromoteToHomePage)
|
||||
CurrentSite.HomePage = "BlogHomePageProvider;" + model.Blog.Item.Id;
|
||||
|
||||
return Redirect(Url.BlogForAdmin(model.Blog.Item.Slug));
|
||||
}
|
||||
|
||||
@@ -75,14 +78,15 @@ namespace Orchard.Blogs.Controllers {
|
||||
return new NotFoundResult();
|
||||
|
||||
var model = new BlogEditViewModel {
|
||||
Blog = Services.ContentManager.BuildEditorModel(blog)
|
||||
Blog = Services.ContentManager.BuildEditorModel(blog),
|
||||
PromoteToHomePage = CurrentSite.HomePage == "BlogHomePageProvider;" + blog.Id
|
||||
};
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Edit(string blogSlug, FormCollection input) {
|
||||
public ActionResult Edit(string blogSlug, bool PromoteToHomePage) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageBlogs, T("Couldn't edit blog")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
@@ -98,10 +102,8 @@ namespace Orchard.Blogs.Controllers {
|
||||
if (!ModelState.IsValid)
|
||||
return View(model);
|
||||
|
||||
string setAsHomePage = input["PromoteToHomePage"];
|
||||
if (!String.IsNullOrEmpty(setAsHomePage) && !setAsHomePage.Equals("false")) {
|
||||
if (PromoteToHomePage)
|
||||
CurrentSite.HomePage = "BlogHomePageProvider;" + model.Blog.Item.Id;
|
||||
}
|
||||
|
||||
_blogService.Edit(model.Blog.Item);
|
||||
|
||||
|
@@ -4,5 +4,6 @@ using Orchard.Mvc.ViewModels;
|
||||
namespace Orchard.Blogs.ViewModels {
|
||||
public class CreateBlogViewModel : BaseViewModel {
|
||||
public ContentItemViewModel<Blog> Blog { get; set; }
|
||||
public bool PromoteToHomePage { get; set; }
|
||||
}
|
||||
}
|
@@ -4,5 +4,9 @@
|
||||
<% using (Html.BeginFormAntiForgeryPost()) { %>
|
||||
<%=Html.ValidationSummary() %>
|
||||
<%=Html.EditorForItem(vm => vm.Blog) %>
|
||||
<fieldset>
|
||||
<%=Html.EditorFor(m => m.PromoteToHomePage) %>
|
||||
<label for="PromoteToHomePage" class="forcheckbox"><%=_Encoded("Set as home page") %></label>
|
||||
</fieldset>
|
||||
<fieldset><input class="button primaryAction" type="submit" value="<%=_Encoded("Add") %>" /></fieldset><%
|
||||
} %>
|
@@ -4,7 +4,9 @@
|
||||
<% using (Html.BeginFormAntiForgeryPost()) { %>
|
||||
<%=Html.ValidationSummary() %>
|
||||
<%=Html.EditorForItem(m => m.Blog) %>
|
||||
<%=Html.EditorFor(m => m.PromoteToHomePage) %>
|
||||
<label for="PromoteToHomePage" class="forcheckbox"><%=_Encoded("Set as home page") %></label>
|
||||
<fieldset>
|
||||
<%=Html.EditorFor(m => m.PromoteToHomePage) %>
|
||||
<label for="PromoteToHomePage" class="forcheckbox"><%=_Encoded("Set as home page") %></label>
|
||||
</fieldset>
|
||||
<fieldset><input class="button primaryAction" type="submit" value="<%=_Encoded("Save") %>" /></fieldset><%
|
||||
} %>
|
Reference in New Issue
Block a user