mirror of https://github.com/abpframework/abp.git
22 changed files with 399 additions and 18 deletions
@ -0,0 +1,16 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace Volo.Blogging.Posts |
|||
{ |
|||
public class CreatePostDto |
|||
{ |
|||
public Guid BlogId { get; set; } |
|||
|
|||
public string Title { get; set; } |
|||
|
|||
public string Content { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace Volo.Blogging.Posts |
|||
{ |
|||
public class GetPostForEditOutput : FullAuditedEntityDto<Guid> |
|||
{ |
|||
public Guid BlogId { get; set; } |
|||
|
|||
public string Title { get; set; } |
|||
|
|||
public string Content { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace Volo.Blogging.Posts |
|||
{ |
|||
public class PostWithDetailsDto : FullAuditedEntityDto<Guid> |
|||
{ |
|||
public Guid BlogId { get; set; } |
|||
|
|||
public string Title { get; set; } |
|||
|
|||
public string Content { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace Volo.Blogging.Posts |
|||
{ |
|||
public class UpdatePostDto |
|||
{ |
|||
public Guid BlogId { get; set; } |
|||
|
|||
public string Title { get; set; } |
|||
|
|||
public string Content { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
@page |
|||
@using Volo.Blogging.Pages.Blog.Posts |
|||
@model EditModel |
|||
@{ |
|||
|
|||
} |
|||
@using (Html.BeginForm(FormMethod.Post)) |
|||
{ |
|||
<div class="form-group"> |
|||
<label class="col-sm-2 control-label">Title</label> |
|||
<div class="col-sm-10"> |
|||
<input class="form-control" name="Title" value="@Model.Post.Title"> |
|||
</div> |
|||
</div> |
|||
|
|||
<div class="form-group"> |
|||
<label class="col-sm-2 control-label">Content</label> |
|||
<div class="col-sm-10"> |
|||
<textarea rows="4" class="form-control" name="Content">@Model.Post.Content</textarea> |
|||
</div> |
|||
</div> |
|||
|
|||
<input name="BlogId" value="@Model.Post.BlogId" hidden=""> |
|||
<input name="Id" value="@Model.Post.Id" hidden=""> |
|||
|
|||
<div class="form-group"> |
|||
<div class="col-sm-offset-2 col-sm-10"> |
|||
<button type="submit" class="btn btn-default">Save</button> |
|||
</div> |
|||
</div> |
|||
} |
|||
@ -0,0 +1,49 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Microsoft.AspNetCore.Mvc.RazorPages; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Blogging.Blogs; |
|||
using Volo.Blogging.Posts; |
|||
|
|||
namespace Volo.Blogging.Pages.Blog.Posts |
|||
{ |
|||
public class EditModel : PageModel |
|||
{ |
|||
private readonly IPostAppService _postAppService; |
|||
private readonly IBlogAppService _blogAppService; |
|||
|
|||
[BindProperty(SupportsGet = true)] |
|||
public string BlogShortName { get; set; } |
|||
|
|||
[BindProperty(SupportsGet = true)] |
|||
public string PostId { get; set; } |
|||
|
|||
public PostWithDetailsDto Post { get; set; } |
|||
|
|||
public BlogDto Blog { get; set; } |
|||
|
|||
public EditModel(IPostAppService postAppService, IBlogAppService blogAppService) |
|||
{ |
|||
_postAppService = postAppService; |
|||
_blogAppService = blogAppService; |
|||
} |
|||
|
|||
public async void OnGet() |
|||
{ |
|||
var blog = await _blogAppService.GetByShortNameAsync(BlogShortName); |
|||
|
|||
Post = await _postAppService.GetAsync(new Guid(PostId)); |
|||
|
|||
Blog = blog; |
|||
} |
|||
|
|||
public async Task<ActionResult> OnPost(Guid id, UpdatePostDto post) |
|||
{ |
|||
var editedPost = await _postAppService.UpdateAsync(id, post); |
|||
var blog = await _blogAppService.GetAsync(editedPost.BlogId); |
|||
|
|||
return Redirect(Url.Content($"~/blog/{blog.ShortName}/{editedPost.Title}")); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
@page |
|||
@using Volo.Blogging.Pages.Blog.Posts |
|||
@model NewModel |
|||
@{ |
|||
|
|||
} |
|||
@using (Html.BeginForm(FormMethod.Post)) |
|||
{ |
|||
<div class="form-group"> |
|||
<label class="col-sm-2 control-label">Title</label> |
|||
<div class="col-sm-10"> |
|||
<input class="form-control" name="Title" value="@Model.Post.Title"> |
|||
</div> |
|||
</div> |
|||
|
|||
<div class="form-group"> |
|||
<label class="col-sm-2 control-label">Content</label> |
|||
<div class="col-sm-10"> |
|||
<textarea rows="4" class="form-control" name="Content">@Model.Post.Content</textarea> |
|||
</div> |
|||
</div> |
|||
|
|||
<input name="BlogId" value="@Model.Post.BlogId" hidden=""> |
|||
|
|||
<div class="form-group"> |
|||
<div class="col-sm-offset-2 col-sm-10"> |
|||
<button type="submit" class="btn btn-default">Save</button> |
|||
</div> |
|||
</div> |
|||
} |
|||
@ -0,0 +1,52 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Microsoft.AspNetCore.Mvc.RazorPages; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Blogging.Blogs; |
|||
using Volo.Blogging.Posts; |
|||
|
|||
namespace Volo.Blogging.Pages.Blog.Posts |
|||
{ |
|||
public class NewModel : PageModel |
|||
{ |
|||
private readonly IPostAppService _postAppService; |
|||
private readonly IBlogAppService _blogAppService; |
|||
|
|||
[BindProperty(SupportsGet = true)] |
|||
public string BlogShortName { get; set; } |
|||
|
|||
[BindProperty(SupportsGet = true)] |
|||
public string PostId { get; set; } |
|||
|
|||
public PostWithDetailsDto Post { get; set; } |
|||
|
|||
public BlogDto Blog { get; set; } |
|||
|
|||
public NewModel(IPostAppService postAppService, IBlogAppService blogAppService) |
|||
{ |
|||
_postAppService = postAppService; |
|||
_blogAppService = blogAppService; |
|||
} |
|||
|
|||
public async void OnGet() |
|||
{ |
|||
var blog = await _blogAppService.GetByShortNameAsync(BlogShortName); |
|||
|
|||
Post = new PostWithDetailsDto() |
|||
{ |
|||
BlogId = blog.Id |
|||
}; |
|||
|
|||
Blog = blog; |
|||
} |
|||
|
|||
public async Task<ActionResult> OnPost(CreatePostDto post) |
|||
{ |
|||
var insertedPost = await _postAppService.CreateAsync(post); |
|||
var blog = await _blogAppService.GetAsync(insertedPost.BlogId); |
|||
|
|||
return Redirect(Url.Content($"~/blog/{blog.ShortName}/{insertedPost.Title}")); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,83 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Volo.Blogging.Blogs; |
|||
using Volo.Blogging.Posts; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Blogging |
|||
{ |
|||
public class PostAppService_Tests : BloggingApplicationTestBase |
|||
{ |
|||
private readonly IPostAppService _postAppService; |
|||
private readonly IBlogRepository _blogRepository; |
|||
private readonly BloggingTestData _testData; |
|||
|
|||
public PostAppService_Tests() |
|||
{ |
|||
_testData = GetRequiredService<BloggingTestData>(); |
|||
_postAppService = GetRequiredService<IPostAppService>(); |
|||
_blogRepository = GetRequiredService<IBlogRepository>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Create_A_Post() |
|||
{ |
|||
var blogId = (await _blogRepository.GetListAsync()).First().Id; |
|||
var title = "title"; |
|||
var content = "content"; |
|||
|
|||
var newPost = await _postAppService.CreateAsync(new CreatePostDto() |
|||
{ |
|||
BlogId = blogId, |
|||
Title = title, |
|||
Content = content |
|||
}); |
|||
|
|||
UsingDbContext(context => |
|||
{ |
|||
var post = context.Posts.FirstOrDefault(q => q.Title == title); |
|||
post.ShouldNotBeNull(); |
|||
post.Title.ShouldBe(title); |
|||
post.Content.ShouldBe(content); |
|||
post.BlogId.ShouldBe(blogId); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Create_And_Update_A_Post() |
|||
{ |
|||
var blogId = (await _blogRepository.GetListAsync()).First().Id; |
|||
var title = "title"; |
|||
var newTitle = "newtitle"; |
|||
var content = "content"; |
|||
|
|||
var newPost = await _postAppService.CreateAsync(new CreatePostDto() |
|||
{ |
|||
BlogId = blogId, |
|||
Title = title, |
|||
Content = content |
|||
}); |
|||
|
|||
await _postAppService.UpdateAsync(newPost.Id, new UpdatePostDto() |
|||
{ |
|||
BlogId = blogId, |
|||
Title = newTitle, |
|||
Content = content |
|||
}); |
|||
|
|||
|
|||
UsingDbContext(context => |
|||
{ |
|||
var post = context.Posts.FirstOrDefault(q => q.Id == newPost.Id); |
|||
post.ShouldNotBeNull(); |
|||
post.Title.ShouldBe(newTitle); |
|||
post.Content.ShouldBe(content); |
|||
post.BlogId.ShouldBe(blogId); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue