diff --git a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Blogs/CreateBlogDto.cs b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Blogs/CreateBlogDto.cs new file mode 100644 index 0000000000..b0f4318401 --- /dev/null +++ b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Blogs/CreateBlogDto.cs @@ -0,0 +1,14 @@ +using System; +using Volo.Abp.Application.Dtos; + +namespace Volo.Blogging.Blogs +{ + public class CreateBlogDto + { + public string Name { get; set; } + + public string ShortName { get; set; } + + public string Description { get; set; } + } +} \ No newline at end of file diff --git a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Blogs/IBlogAppService.cs b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Blogs/IBlogAppService.cs index cf4a9aeb29..5d57440a22 100644 --- a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Blogs/IBlogAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Blogs/IBlogAppService.cs @@ -13,6 +13,6 @@ namespace Volo.Blogging.Blogs Task GetAsync(Guid id); - Task Create(BlogDto blog); + Task Create(CreateBlogDto blog); } } diff --git a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Blogs/BlogAppService.cs b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Blogs/BlogAppService.cs index a7dc86dec6..adce94c9ab 100644 --- a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Blogs/BlogAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Blogs/BlogAppService.cs @@ -43,9 +43,11 @@ namespace Volo.Blogging.Blogs return ObjectMapper.Map(blog); } - public async Task Create(BlogDto blog) + public async Task Create(CreateBlogDto input) { - await _blogRepository.InsertAsync(new Blog(GuidGenerator.Create(), blog.Name, blog.ShortName)); + var newBlog = await _blogRepository.InsertAsync(new Blog(GuidGenerator.Create(), input.Name, input.ShortName){Description = input.Description}); + + return ObjectMapper.Map(newBlog); } } } diff --git a/modules/blogging/src/Volo.Blogging.Web/AbpBloggingWebAutoMapperProfile.cs b/modules/blogging/src/Volo.Blogging.Web/AbpBloggingWebAutoMapperProfile.cs index e5d40c6be3..aa100bf8e0 100644 --- a/modules/blogging/src/Volo.Blogging.Web/AbpBloggingWebAutoMapperProfile.cs +++ b/modules/blogging/src/Volo.Blogging.Web/AbpBloggingWebAutoMapperProfile.cs @@ -1,7 +1,9 @@ using AutoMapper; using Volo.Abp.AutoMapper; +using Volo.Blogging.Blogs; using Volo.Blogging.Pages.Blog.Posts; using Volo.Blogging.Posts; +using IndexModel = Volo.Blogging.Pages.Blog.IndexModel; namespace Volo.Blogging { @@ -11,6 +13,7 @@ namespace Volo.Blogging { CreateMap().Ignore(x=>x.Tags); CreateMap(); + CreateMap(); } } } diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Index.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Index.cshtml.cs index 893657e3c8..d33e3bdb29 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Index.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Index.cshtml.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; @@ -13,7 +14,7 @@ namespace Volo.Blogging.Pages.Blog public IReadOnlyList Blogs { get; private set; } [BindProperty] - public BlogDto Blog { get; set; } + public BlogIndexViewModel Blog { get; set; } public IndexModel(IBlogAppService blogAppService) { @@ -37,8 +38,7 @@ namespace Volo.Blogging.Pages.Blog public async Task OnPostAsync() { - await _blogAppService.Create(Blog); - + await _blogAppService.Create(ObjectMapper.Map(Blog)); var result = await _blogAppService.GetListAsync(); @@ -52,5 +52,16 @@ namespace Volo.Blogging.Pages.Blog return Page(); } + + public class BlogIndexViewModel + { + [Required] + public string Name { get; set; } + + [Required] + public string ShortName { get; set; } + + public string Description { get; set; } + } } } \ No newline at end of file