Browse Source

blogging module add blog fixes

pull/441/head
Yunus Emre Kalkan 8 years ago
parent
commit
8ff0069182
  1. 14
      modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Blogs/CreateBlogDto.cs
  2. 2
      modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Blogs/IBlogAppService.cs
  3. 6
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Blogs/BlogAppService.cs
  4. 3
      modules/blogging/src/Volo.Blogging.Web/AbpBloggingWebAutoMapperProfile.cs
  5. 17
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Index.cshtml.cs

14
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; }
}
}

2
modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Blogs/IBlogAppService.cs

@ -13,6 +13,6 @@ namespace Volo.Blogging.Blogs
Task<BlogDto> GetAsync(Guid id);
Task Create(BlogDto blog);
Task Create(CreateBlogDto blog);
}
}

6
modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Blogs/BlogAppService.cs

@ -43,9 +43,11 @@ namespace Volo.Blogging.Blogs
return ObjectMapper.Map<Blog, BlogDto>(blog);
}
public async Task Create(BlogDto blog)
public async Task<BlogDto> 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<Blog, BlogDto>(newBlog);
}
}
}

3
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<PostWithDetailsDto, EditPostViewModel>().Ignore(x=>x.Tags);
CreateMap<NewModel.CreatePostViewModel, CreatePostDto>();
CreateMap<IndexModel.BlogIndexViewModel, CreateBlogDto>();
}
}
}

17
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<BlogDto> 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<IActionResult> OnPostAsync()
{
await _blogAppService.Create(Blog);
await _blogAppService.Create(ObjectMapper.Map<BlogIndexViewModel, CreateBlogDto>(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; }
}
}
}
Loading…
Cancel
Save