using Microsoft.AspNetCore.Authorization; using System; using System.Collections.Generic; using System.Threading.Tasks; using Volo.Abp.Application.Dtos; using Volo.Abp.Domain.Entities; using Volo.Blogging.Blogs.Dtos; namespace Volo.Blogging.Blogs { public class BlogAppService : BloggingAppServiceBase, IBlogAppService { private readonly IBlogRepository _blogRepository; public BlogAppService(IBlogRepository blogRepository) { _blogRepository = blogRepository; } public async Task> GetListAsync() { var blogs = await _blogRepository.GetListAsync(); return new ListResultDto( ObjectMapper.Map, List>(blogs) ); } public async Task GetByShortNameAsync(string shortName) { var blog = await _blogRepository.FindByShortNameAsync(shortName); if (blog == null) { throw new EntityNotFoundException(typeof(Blog), shortName); } return ObjectMapper.Map(blog); } public async Task GetAsync(Guid id) { var blog = await _blogRepository.GetAsync(id); return ObjectMapper.Map(blog); } [Authorize(BloggingPermissions.Blogs.Create)] public async Task Create(CreateBlogDto input) { var newBlog = await _blogRepository.InsertAsync(new Blog(GuidGenerator.Create(), input.Name, input.ShortName) { Description = input.Description }); return ObjectMapper.Map(newBlog); } [Authorize(BloggingPermissions.Blogs.Update)] public async Task Update(Guid id, UpdateBlogDto input) { var blog = await _blogRepository.GetAsync(id); blog.SetName(input.Name); blog.SetShortName(input.ShortName); blog.Description = input.Description; return ObjectMapper.Map(blog); } [Authorize(BloggingPermissions.Blogs.Delete)] public async Task Delete(Guid id) { await _blogRepository.DeleteAsync(id); } } }