mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Wrapped up the model for blog views into some view models and dumped out posts on a blog.
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4041908
This commit is contained in:
@@ -1,18 +1,22 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Orchard.Blogs.Models;
|
using Orchard.Blogs.Models;
|
||||||
using Orchard.Blogs.Services;
|
using Orchard.Blogs.Services;
|
||||||
|
using Orchard.Blogs.ViewModels;
|
||||||
using Orchard.Mvc.Results;
|
using Orchard.Mvc.Results;
|
||||||
|
|
||||||
namespace Orchard.Blogs.Controllers {
|
namespace Orchard.Blogs.Controllers {
|
||||||
public class BlogController : Controller {
|
public class BlogController : Controller {
|
||||||
private readonly IBlogService _blogService;
|
private readonly IBlogService _blogService;
|
||||||
|
private readonly IBlogPostService _blogPostService;
|
||||||
|
|
||||||
public BlogController(IBlogService blogService) {
|
public BlogController(IBlogService blogService, IBlogPostService blogPostService) {
|
||||||
_blogService = blogService;
|
_blogService = blogService;
|
||||||
|
_blogPostService = blogPostService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult List() {
|
public ActionResult List() {
|
||||||
return View(_blogService.Get());
|
return View(new BlogsViewModel {Blogs = _blogService.Get()});
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: (erikpo) Should think about moving the slug parameter and get call and null check up into a model binder or action filter
|
//TODO: (erikpo) Should think about moving the slug parameter and get call and null check up into a model binder or action filter
|
||||||
@@ -22,7 +26,9 @@ namespace Orchard.Blogs.Controllers {
|
|||||||
if (blog == null)
|
if (blog == null)
|
||||||
return new NotFoundResult();
|
return new NotFoundResult();
|
||||||
|
|
||||||
return View(blog);
|
IEnumerable<BlogPost> posts = _blogPostService.Get(blog);
|
||||||
|
|
||||||
|
return View(new BlogViewModel {Blog = blog, Posts = posts});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,6 +79,8 @@
|
|||||||
<Compile Include="Services\IBlogPostService.cs" />
|
<Compile Include="Services\IBlogPostService.cs" />
|
||||||
<Compile Include="Services\CreateBlogParams.cs" />
|
<Compile Include="Services\CreateBlogParams.cs" />
|
||||||
<Compile Include="Services\IBlogService.cs" />
|
<Compile Include="Services\IBlogService.cs" />
|
||||||
|
<Compile Include="ViewModels\BlogsViewModel.cs" />
|
||||||
|
<Compile Include="ViewModels\BlogViewModel.cs" />
|
||||||
<Compile Include="ViewModels\CreateBlogViewModel.cs" />
|
<Compile Include="ViewModels\CreateBlogViewModel.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Orchard.Blogs.Models;
|
||||||
|
using Orchard.Mvc.ViewModels;
|
||||||
|
|
||||||
|
namespace Orchard.Blogs.ViewModels {
|
||||||
|
public class BlogViewModel : BaseViewModel {
|
||||||
|
public Blog Blog { get; set; }
|
||||||
|
public IEnumerable<BlogPost> Posts { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Orchard.Blogs.Models;
|
||||||
|
|
||||||
|
namespace Orchard.Blogs.ViewModels {
|
||||||
|
public class BlogsViewModel {
|
||||||
|
public IEnumerable<Blog> Blogs { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,19 @@
|
|||||||
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<Blog>" %>
|
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<BlogViewModel>" %>
|
||||||
|
<%@ Import Namespace="Orchard.Blogs.ViewModels"%>
|
||||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||||
<%@ Import Namespace="Orchard.Mvc.Html"%>
|
<%@ Import Namespace="Orchard.Mvc.Html"%>
|
||||||
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
||||||
<% Html.Include("Header"); %>
|
<% Html.Include("Header"); %>
|
||||||
<div class="yui-g">
|
<div class="yui-g">
|
||||||
<h2>Blog</h2>
|
<h2>Blog</h2>
|
||||||
<div><%=Html.Encode(Model.Name) %></div>
|
<div><%=Html.Encode(Model.Blog.Name) %></div><%
|
||||||
|
//TODO: (erikpo) Move this into a helper
|
||||||
|
if (Model.Posts.Count() > 0) { %>
|
||||||
|
<ul><%
|
||||||
|
foreach (BlogPost post in Model.Posts) { %>
|
||||||
|
<li><%=post.Title %></li><%
|
||||||
|
} %>
|
||||||
|
</ul><%
|
||||||
|
} %>
|
||||||
</div>
|
</div>
|
||||||
<% Html.Include("Footer"); %>
|
<% Html.Include("Footer"); %>
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Blog>>" %>
|
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<BlogsViewModel>" %>
|
||||||
|
<%@ Import Namespace="Orchard.Blogs.ViewModels"%>
|
||||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||||
<%@ Import Namespace="Orchard.Mvc.Html"%>
|
<%@ Import Namespace="Orchard.Mvc.Html"%>
|
||||||
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
||||||
@@ -6,9 +7,9 @@
|
|||||||
<div class="yui-g">
|
<div class="yui-g">
|
||||||
<h2>Blogs</h2><%
|
<h2>Blogs</h2><%
|
||||||
//TODO: (erikpo) Replace this with an Html extension method of some sort (ListForModel?)
|
//TODO: (erikpo) Replace this with an Html extension method of some sort (ListForModel?)
|
||||||
if (Model.Count() > 0) { %>
|
if (Model.Blogs.Count() > 0) { %>
|
||||||
<ul><%
|
<ul><%
|
||||||
foreach (Blog blog in Model) { %>
|
foreach (Blog blog in Model.Blogs) { %>
|
||||||
<li><a href="<%=Url.Action("Item", "Blog", new {blogSlug = blog.Slug}) %>"><%=Html.Encode(blog.Name) %></a></li><%
|
<li><a href="<%=Url.Action("Item", "Blog", new {blogSlug = blog.Slug}) %>"><%=Html.Encode(blog.Name) %></a></li><%
|
||||||
} %>
|
} %>
|
||||||
</ul><%
|
</ul><%
|
||||||
|
|||||||
Reference in New Issue
Block a user