From 029165327363530d950375b4e49e6962880c59f5 Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Tue, 9 Mar 2010 02:16:08 -0800 Subject: [PATCH] Setting up "Add to home page" for blog create --HG-- branch : dev --- .../Controllers/BlogAdminController.cs | 14 ++++++++------ .../ViewModels/CreateBlogViewModel.cs | 1 + .../Orchard.Blogs/Views/BlogAdmin/Create.ascx | 4 ++++ .../Orchard.Blogs/Views/BlogAdmin/Edit.ascx | 6 ++++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogAdminController.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogAdminController.cs index d0e5f6137..0138a4cc4 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogAdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogAdminController.cs @@ -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); diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/ViewModels/CreateBlogViewModel.cs b/src/Orchard.Web/Modules/Orchard.Blogs/ViewModels/CreateBlogViewModel.cs index c84e1e736..967158b40 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/ViewModels/CreateBlogViewModel.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/ViewModels/CreateBlogViewModel.cs @@ -4,5 +4,6 @@ using Orchard.Mvc.ViewModels; namespace Orchard.Blogs.ViewModels { public class CreateBlogViewModel : BaseViewModel { public ContentItemViewModel Blog { get; set; } + public bool PromoteToHomePage { get; set; } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Views/BlogAdmin/Create.ascx b/src/Orchard.Web/Modules/Orchard.Blogs/Views/BlogAdmin/Create.ascx index eaa9c76b9..a79ec22cc 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Views/BlogAdmin/Create.ascx +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Views/BlogAdmin/Create.ascx @@ -4,5 +4,9 @@ <% using (Html.BeginFormAntiForgeryPost()) { %> <%=Html.ValidationSummary() %> <%=Html.EditorForItem(vm => vm.Blog) %> +
+ <%=Html.EditorFor(m => m.PromoteToHomePage) %> + +
" />
<% } %> \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Views/BlogAdmin/Edit.ascx b/src/Orchard.Web/Modules/Orchard.Blogs/Views/BlogAdmin/Edit.ascx index f5b97391a..7c8c21d0f 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Views/BlogAdmin/Edit.ascx +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Views/BlogAdmin/Edit.ascx @@ -4,7 +4,9 @@ <% using (Html.BeginFormAntiForgeryPost()) { %> <%=Html.ValidationSummary() %> <%=Html.EditorForItem(m => m.Blog) %> - <%=Html.EditorFor(m => m.PromoteToHomePage) %> - +
+ <%=Html.EditorFor(m => m.PromoteToHomePage) %> + +
" />
<% } %> \ No newline at end of file