mirror of https://github.com/abpframework/abp.git
7 changed files with 72 additions and 4 deletions
@ -0,0 +1,35 @@ |
|||
using System.Threading.Tasks; |
|||
using AbpDesk.Blogging; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
using Volo.Abp.Domain.Repositories; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace AbpDesk.Web.Mvc.Areas.Blog.Controllers |
|||
{ |
|||
//TODO: Move this controller to a plug-in
|
|||
[Area("Blog")] |
|||
public class PostsController : AbpController |
|||
{ |
|||
private readonly IQueryableRepository<BlogPost> _blogPostRepository; |
|||
private readonly IUnitOfWorkManager _unitOfWorkManager; |
|||
|
|||
public PostsController(IQueryableRepository<BlogPost> blogPostRepository, IUnitOfWorkManager unitOfWorkManager) |
|||
{ |
|||
_blogPostRepository = blogPostRepository; |
|||
_unitOfWorkManager = unitOfWorkManager; |
|||
} |
|||
|
|||
public async Task<ActionResult> Index() |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
{ |
|||
var posts = await _blogPostRepository.GetListAsync(HttpContext.RequestAborted); |
|||
|
|||
await unitOfWork.CompleteAsync(HttpContext.RequestAborted); |
|||
|
|||
return View(posts); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
@model List<AbpDesk.Blogging.BlogPost> |
|||
|
|||
<h2>Blog Posts</h2> |
|||
|
|||
<ul> |
|||
@foreach (var post in Model) |
|||
{ |
|||
<h3>@post.Title</h3> |
|||
<p>@post.Body</p> |
|||
if (!post.Comments.Any()) |
|||
{ |
|||
<p><em>No comment yet!</em></p> |
|||
} |
|||
else |
|||
{ |
|||
<h4>Comments</h4> |
|||
foreach (var comment in post.Comments) |
|||
{ |
|||
<h5>@comment.Name</h5> |
|||
<p>@comment.Message</p> |
|||
} |
|||
} |
|||
} |
|||
</ul> |
|||
Loading…
Reference in new issue