mirror of https://github.com/abpframework/abp
parent
f520c7e541
commit
f62ed01ac2
@ -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}"));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue