mirror of https://github.com/abpframework/abp.git
16 changed files with 5833 additions and 7 deletions
File diff suppressed because one or more lines are too long
@ -0,0 +1,11 @@ |
|||||
|
using System; |
||||
|
|
||||
|
namespace Volo.Blogging.Posts |
||||
|
{ |
||||
|
public class GetPostInput |
||||
|
{ |
||||
|
public string Title { get; set; } |
||||
|
|
||||
|
public Guid BlogId { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
using Volo.Abp.Application.Services; |
||||
|
|
||||
|
namespace Volo.Blogging.Posts |
||||
|
{ |
||||
|
public interface IPostAppService : IApplicationService |
||||
|
{ |
||||
|
ListResultDto<PostDto> GetPostsByBlogId(Guid id); |
||||
|
|
||||
|
Task<PostDto> GetPost(GetPostInput input); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,14 @@ |
|||||
|
using System; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
|
||||
|
namespace Volo.Blogging.Posts |
||||
|
{ |
||||
|
public class PostDto : EntityDto<Guid> |
||||
|
{ |
||||
|
public Guid BlogId { get; protected set; } |
||||
|
|
||||
|
public string Title { get; protected set; } |
||||
|
|
||||
|
public string Content { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,34 @@ |
|||||
|
using System; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
using Volo.Abp.Application.Services; |
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace Volo.Blogging.Posts |
||||
|
{ |
||||
|
public class PostAppService : ApplicationService, IPostAppService |
||||
|
{ |
||||
|
private readonly IPostRepository _postRepository; |
||||
|
|
||||
|
public PostAppService(IPostRepository postRepository) |
||||
|
{ |
||||
|
_postRepository = postRepository; |
||||
|
} |
||||
|
|
||||
|
public ListResultDto<PostDto> GetPostsByBlogId(Guid id) |
||||
|
{ |
||||
|
var posts = _postRepository.GetPostsByBlogId(id); |
||||
|
|
||||
|
return new ListResultDto<PostDto>( |
||||
|
ObjectMapper.Map<List<Post>, List<PostDto>>(posts)); |
||||
|
} |
||||
|
|
||||
|
public async Task<PostDto> GetPost(GetPostInput input) |
||||
|
{ |
||||
|
var post = await _postRepository.GetPost(input.BlogId, input.Title); |
||||
|
|
||||
|
return ObjectMapper.Map<Post,PostDto>(post); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,14 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Domain.Repositories; |
||||
|
|
||||
|
namespace Volo.Blogging.Posts |
||||
|
{ |
||||
|
public interface IPostRepository : IBasicRepository<Post, Guid> |
||||
|
{ |
||||
|
List<Post> GetPostsByBlogId(Guid id); |
||||
|
|
||||
|
Task<Post> GetPost(Guid blogId, string title); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,32 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
||||
|
using Volo.Abp.EntityFrameworkCore; |
||||
|
using Volo.Blogging.Blogs; |
||||
|
using Volo.Blogging.EntityFrameworkCore; |
||||
|
|
||||
|
namespace Volo.Blogging.Posts |
||||
|
{ |
||||
|
public class EfCorePostRepository : EfCoreRepository<IBloggingDbContext, Post, Guid>, IPostRepository |
||||
|
{ |
||||
|
public EfCorePostRepository(IDbContextProvider<IBloggingDbContext> dbContextProvider) |
||||
|
: base(dbContextProvider) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public List<Post> GetPostsByBlogId(Guid id) |
||||
|
{ |
||||
|
return DbSet.Where(p => p.BlogId == id).ToList(); |
||||
|
} |
||||
|
|
||||
|
public async Task<Post> GetPost(Guid blogId, string title) |
||||
|
{ |
||||
|
return await DbSet.FirstOrDefaultAsync(p => p.BlogId == blogId && p.Title == title); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,4 +1,15 @@ |
|||||
@page |
@page |
||||
@model Volo.Blogging.Pages.Blog.Posts.IndexModel |
@model Volo.Blogging.Pages.Blog.Posts.IndexModel |
||||
@{ |
@{ |
||||
|
|
||||
} |
} |
||||
|
<h2> |
||||
|
Posts |
||||
|
</h2> |
||||
|
|
||||
|
<ul> |
||||
|
@foreach (var post in Model.Posts) |
||||
|
{ |
||||
|
<li><a asp-page="./Detail" asp-route-postTitle="@post.Title" asp-route-blogShortName="@Model.BlogShortName">@post.Title</a></li> |
||||
|
} |
||||
|
</ul> |
||||
|
|||||
Loading…
Reference in new issue