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 new file mode 100644 index 0000000000..8dd543bde5 --- /dev/null +++ b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Blogs/IBlogAppService.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Application.Services; + +namespace Volo.Blogging.Blogs +{ + public interface IBlogAppService : IApplicationService + { + Task> GetListAsync(); + } +} 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 new file mode 100644 index 0000000000..0ad5821fb2 --- /dev/null +++ b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Blogs/BlogAppService.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Application.Services; + +namespace Volo.Blogging.Blogs +{ + public class BlogAppService : ApplicationService, 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) + ); + } + } +} diff --git a/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Blogs/IBlogRepository.cs b/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Blogs/IBlogRepository.cs new file mode 100644 index 0000000000..335620d4cc --- /dev/null +++ b/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Blogs/IBlogRepository.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.Domain.Repositories; + +namespace Volo.Blogging.Blogs +{ + public interface IBlogRepository : IBasicRepository + { + Task FindByShortNameAsync(string shortName); + } +} diff --git a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Blogs/EfCoreBlogRepository.cs b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Blogs/EfCoreBlogRepository.cs new file mode 100644 index 0000000000..e36f2c3224 --- /dev/null +++ b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Blogs/EfCoreBlogRepository.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Volo.Abp.Domain.Repositories.EntityFrameworkCore; +using Volo.Abp.EntityFrameworkCore; +using Volo.Blogging.EntityFrameworkCore; + +namespace Volo.Blogging.Blogs +{ + public class EfCoreBlogRepository : EfCoreRepository, IBlogRepository + { + public EfCoreBlogRepository(IDbContextProvider dbContextProvider) + : base(dbContextProvider) + { + + } + + public async Task FindByShortNameAsync(string shortName) + { + return await DbSet.FirstOrDefaultAsync(p => p.ShortName == shortName); + } + } +} 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 4ee5654d65..7874b5352b 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,6 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; using Volo.Blogging.Blogs; @@ -8,19 +9,21 @@ namespace Volo.Blogging.Pages.Blog { public class IndexModel : AbpPageModel { - public List Blogs { get; private set; } + private readonly IBlogAppService _blogAppService; - public IndexModel() + public IReadOnlyList Blogs { get; private set; } + + public IndexModel(IBlogAppService blogAppService) { - + _blogAppService = blogAppService; } - public async Task OnGet() + public async Task OnGet() { - Blogs = new List - { - new BlogDto {Id = Guid.NewGuid(), Name = "abp", ShortName = "abp", Description = "a b p"} - }; + var result = await _blogAppService.GetListAsync(); + + Blogs = result.Items; + return Page(); } } } \ No newline at end of file