Setting up "Add to home page" for blog create

--HG--
branch : dev
This commit is contained in:
Nathan Heskew
2010-03-09 02:16:08 -08:00
parent 012137726e
commit 0291653273
4 changed files with 17 additions and 8 deletions

View File

@@ -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);

View File

@@ -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; }
}
}

View File

@@ -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><%
} %>

View File

@@ -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><%
} %>