mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 10:54:50 +08:00
Hooked up viewing the posts by Blog (front end) and viewing a BlogPost.
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4042252
This commit is contained in:
@@ -42,7 +42,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
if (post == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
return View(post);
|
||||
return View(new BlogPostViewModel {Blog = blog, Post = post});
|
||||
}
|
||||
|
||||
public ActionResult Create(string blogSlug)
|
||||
|
@@ -1,9 +1,15 @@
|
||||
using System;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Models;
|
||||
using Orchard.Security;
|
||||
|
||||
namespace Orchard.Blogs.Models {
|
||||
public class BlogPost : ContentPart<BlogPostRecord> {
|
||||
public Blog Blog { get; set; }
|
||||
//public Blog Blog { get; set; }
|
||||
public string Title { get { return this.As<RoutableAspect>().Title; } }
|
||||
public string Body { get { return this.As<BodyAspect>().Body; } }
|
||||
public string Slug { get { return this.As<RoutableAspect>().Slug; } }
|
||||
public IUser Creator { get { return this.As<CommonAspect>().OwnerField.Value; } }
|
||||
public DateTime? Published { get { return Record.Published; } }
|
||||
}
|
||||
}
|
@@ -11,7 +11,7 @@ namespace Orchard.Blogs.Models {
|
||||
Filters.Add(new ActivatingFilter<RoutableAspect>("blogpost"));
|
||||
Filters.Add(new ActivatingFilter<BodyAspect>("blogpost"));
|
||||
Filters.Add(new StorageFilter<BlogPostRecord>(repository));
|
||||
AddOnLoaded<BlogPost>((context, bp) => bp.Blog = contentManager.Get<Blog>(context.ContentItem.Id));
|
||||
//AddOnLoaded<BlogPost>((context, bp) => bp.Blog = contentManager.Get<Blog>(context.ContentItem.Id));
|
||||
}
|
||||
}
|
||||
}
|
@@ -88,6 +88,7 @@
|
||||
<Compile Include="Services\IBlogService.cs" />
|
||||
<Compile Include="ViewModels\BlogsViewModel.cs" />
|
||||
<Compile Include="ViewModels\BlogViewModel.cs" />
|
||||
<Compile Include="ViewModels\BlogPostViewModel.cs" />
|
||||
<Compile Include="ViewModels\CreateBlogPostViewModel.cs" />
|
||||
<Compile Include="ViewModels\CreateBlogViewModel.cs" />
|
||||
<Compile Include="ViewModels\BlogEditViewModel.cs" />
|
||||
@@ -95,6 +96,7 @@
|
||||
<ItemGroup>
|
||||
<Content Include="Package.txt" />
|
||||
<Content Include="Views\BlogPost\Create.aspx" />
|
||||
<Content Include="Views\BlogPost\Item.aspx" />
|
||||
<Content Include="Views\Blog\Create.aspx" />
|
||||
<Content Include="Views\BlogPost\ListByBlog.aspx" />
|
||||
<Content Include="Views\Blog\Edit.aspx" />
|
||||
|
@@ -97,6 +97,22 @@ namespace Orchard.Blogs {
|
||||
},
|
||||
new MvcRouteHandler())
|
||||
},
|
||||
new RouteDescriptor {
|
||||
Route = new Route(
|
||||
"{blogSlug}/{postSlug}",
|
||||
new RouteValueDictionary {
|
||||
{"area", "Orchard.Blogs"},
|
||||
{"controller", "BlogPost"},
|
||||
{"action", "Item"}
|
||||
},
|
||||
new RouteValueDictionary {
|
||||
{"blogSlug", new IsBlogConstraint(_blogService)}
|
||||
},
|
||||
new RouteValueDictionary {
|
||||
{"area", "Orchard.Blogs"}
|
||||
},
|
||||
new MvcRouteHandler())
|
||||
},
|
||||
new RouteDescriptor {
|
||||
Route = new Route(
|
||||
"{blogSlug}",
|
||||
|
@@ -21,7 +21,7 @@ namespace Orchard.Blogs.Services {
|
||||
_routableRepository.Get(r => r.ContentItem.ContentType.Name == "blogpost" && r.Slug == slug);
|
||||
BlogPost blogPost = record != null ? _contentManager.Get<BlogPost>(record.Id) : null;
|
||||
|
||||
return blogPost != null && blogPost.Blog.ContentItem.Id == blog.ContentItem.Id ? blogPost : null;
|
||||
return blogPost != null && blogPost.Record.Blog.Id == blog.ContentItem.Id ? blogPost : null;
|
||||
}
|
||||
|
||||
public IEnumerable<BlogPost> Get(Blog blog) {
|
||||
@@ -30,10 +30,10 @@ namespace Orchard.Blogs.Services {
|
||||
_routableRepository.Fetch(rr => rr.ContentItem.ContentType.Name == "blogpost"
|
||||
/*, bpr => bpr.Asc(bpr2 => bpr2.Published.GetValueOrDefault(new DateTime(2099, 1, 1)))*/);
|
||||
|
||||
//TODO: (erikpo) Need to filter by blog in the line above instead of manually here
|
||||
//TODO: (erikpo) Need to filter by blog in the line above instead of filtering here
|
||||
return
|
||||
records.Select(r => _contentManager.Get(r.Id).As<BlogPost>()).Where(
|
||||
bp => bp.Blog.ContentItem.Id == blog.ContentItem.Id);
|
||||
bp => bp.Record.Blog.Id == blog.ContentItem.Id);
|
||||
}
|
||||
|
||||
public BlogPost Create(CreateBlogPostParams parameters) {
|
||||
|
@@ -0,0 +1,9 @@
|
||||
using Orchard.Blogs.Models;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
|
||||
namespace Orchard.Blogs.ViewModels {
|
||||
public class BlogPostViewModel : BaseViewModel {
|
||||
public Blog Blog { get; set; }
|
||||
public BlogPost Post { get; set; }
|
||||
}
|
||||
}
|
@@ -14,7 +14,7 @@
|
||||
if (Model.Posts.Count() > 0) { %>
|
||||
<ul><%
|
||||
foreach (BlogPost post in Model.Posts) { %>
|
||||
<li><a href="<%=Url.BlogPost(post.Blog.Slug, post.As<RoutableAspect>().Slug) %>"><%=Html.Encode(post.As<RoutableAspect>().Title) %></a></li><%
|
||||
<li><a href="<%=Url.BlogPost(Model.Blog.Slug, post.As<RoutableAspect>().Slug) %>"><%=Html.Encode(post.As<RoutableAspect>().Title) %></a></li><%
|
||||
} %>
|
||||
</ul><%
|
||||
} %>
|
||||
|
@@ -0,0 +1,15 @@
|
||||
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<BlogPostViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Core.Common.Models"%>
|
||||
<%@ Import Namespace="Orchard.Models"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.ViewModels"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html"%>
|
||||
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
||||
<% Html.Include("Header"); %>
|
||||
<div class="yui-g">
|
||||
<h2><%=Html.Encode(Model.Post.Title) %></h2>
|
||||
<div>Posted by <%=Html.Encode(Model.Post.Creator.UserName) %> on {M d yyyy h:mm tt}</div>
|
||||
<%=Model.Post.Body %>
|
||||
</div>
|
||||
<% Html.Include("Footer"); %>
|
@@ -1,4 +1,5 @@
|
||||
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IEnumerable<BlogPost>>" %>
|
||||
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<BlogViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Blogs.ViewModels"%>
|
||||
<%@ Import Namespace="Orchard.Core.Common.Models"%>
|
||||
<%@ Import Namespace="Orchard.Models"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
|
||||
@@ -9,10 +10,10 @@
|
||||
<div class="yui-g">
|
||||
<h2>Posts</h2><%
|
||||
//TODO: (erikpo) Replace this with an Html extension method of some sort (ListForModel?)
|
||||
if (Model.Count() > 0) { %>
|
||||
if (Model.Posts.Count() > 0) { %>
|
||||
<ul><%
|
||||
foreach (BlogPost post in Model) { %>
|
||||
<li><a href="<%=Url.BlogPost(post.Blog.Slug, post.As<RoutableAspect>().Slug) %>"><%=Html.Encode(post.As<RoutableAspect>().Title) %></a></li><%
|
||||
foreach (BlogPost post in Model.Posts) { %>
|
||||
<li><a href="<%=Url.BlogPost(Model.Blog.Slug, post.As<RoutableAspect>().Slug) %>"><%=Html.Encode(post.As<RoutableAspect>().Title) %></a></li><%
|
||||
} %>
|
||||
</ul><%
|
||||
} %>
|
||||
|
Reference in New Issue
Block a user