- Ability to promote blogs as homepage using the new homepage functionality.

--HG--
branch : dev
This commit is contained in:
Suha Can
2010-02-12 16:45:33 -08:00
parent c070e8fd20
commit dc084f48fd
5 changed files with 63 additions and 1 deletions

View File

@@ -1,5 +1,7 @@
using System;
using System.Linq;
using System.Web.Mvc;
using JetBrains.Annotations;
using Orchard.Blogs.Extensions;
using Orchard.Blogs.Models;
using Orchard.Blogs.Services;
@@ -10,6 +12,7 @@ using Orchard.Data;
using Orchard.Localization;
using Orchard.Mvc.Results;
using Orchard.Security;
using Orchard.Settings;
using Orchard.UI.Notify;
namespace Orchard.Blogs.Controllers {
@@ -33,6 +36,7 @@ namespace Orchard.Blogs.Controllers {
}
private Localizer T { get; set; }
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
public ActionResult Create() {
//TODO: (erikpo) Might think about moving this to an ActionFilter/Attribute
@@ -100,12 +104,17 @@ namespace Orchard.Blogs.Controllers {
return new NotFoundResult();
var model = new BlogEditViewModel {
Blog = _services.ContentManager.UpdateEditorModel(blog, this)
Blog = _services.ContentManager.UpdateEditorModel(blog, this),
};
if (!ModelState.IsValid)
return View(model);
string setAsHomePage = input["PromoteToHomePage"];
if (!String.IsNullOrEmpty(setAsHomePage) && !setAsHomePage.Equals("false")) {
CurrentSite.HomePage = "BlogHomePageProvider;" + model.Blog.Item.Id;
}
_notifier.Information(T("Blog information updated"));
return Redirect(Url.BlogsForAdmin());

View File

@@ -85,6 +85,7 @@
<Compile Include="Permissions.cs" />
<Compile Include="Routing\IsArchiveConstraint.cs" />
<Compile Include="Routing\IsBlogConstraint.cs" />
<Compile Include="Services\BlogHomePageProvider.cs" />
<Compile Include="Services\BlogService.cs" />
<Compile Include="Controllers\BlogController.cs" />
<Compile Include="Models\Blog.cs" />

View File

@@ -0,0 +1,49 @@
using System.Linq;
using System.Web.Mvc;
using Orchard.Blogs.Extensions;
using Orchard.Blogs.Models;
using Orchard.Blogs.ViewModels;
using Orchard.Mvc.Results;
using Orchard.Services;
using Orchard.Core.Feeds;
namespace Orchard.Blogs.Services {
public class BlogHomePageProvider : IHomePageProvider {
private readonly IBlogService _blogService;
private readonly IFeedManager _feedManager;
public BlogHomePageProvider(IOrchardServices services, IBlogService blogService, IFeedManager feedManager) {
Services = services;
_feedManager = feedManager;
_blogService = blogService;
}
public IOrchardServices Services { get; private set; }
#region Implementation of IHomePageProvider
public string GetProviderName() {
return "BlogHomePageProvider";
}
public ActionResult GetHomePage(int itemId) {
Blog blog = _blogService.Get().Where(x => x.Id == itemId).FirstOrDefault();
if (blog == null)
return new NotFoundResult();
var model = new BlogViewModel {
Blog = Services.ContentManager.BuildDisplayModel(blog, "Detail")
};
_feedManager.Register(blog);
return new ViewResult {
ViewName = "~/Modules/Orchard.Blogs/Views/Blog/Item.ascx",
ViewData = new ViewDataDictionary<BlogViewModel>(model)
};
}
#endregion
}
}

View File

@@ -4,5 +4,6 @@ using Orchard.Mvc.ViewModels;
namespace Orchard.Blogs.ViewModels {
public class BlogEditViewModel : AdminViewModel {
public ContentItemViewModel<Blog> Blog { get; set; }
public bool PromoteToHomePage { get; set; }
}
}

View File

@@ -4,5 +4,7 @@
<% 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><input class="button" type="submit" value="<%=_Encoded("Save") %>" /></fieldset><%
} %>