Blog improvements

- IBlogAppService
- dtos + auto mapper configuration
- IBlogRepository & ef core repository implementation
pull/318/head
Yunus Emre Kalkan 7 years ago
parent ecde6fe792
commit 54d824959c

@ -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<ListResultDto<BlogDto>> GetListAsync();
}
}

@ -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<ListResultDto<BlogDto>> GetListAsync()
{
var blogs = await _blogRepository.GetListAsync();
return new ListResultDto<BlogDto>(
ObjectMapper.Map<List<Blog>, List<BlogDto>>(blogs)
);
}
}
}

@ -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<Blog, Guid>
{
Task<Blog> FindByShortNameAsync(string shortName);
}
}

@ -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<IBloggingDbContext, Blog, Guid>, IBlogRepository
{
public EfCoreBlogRepository(IDbContextProvider<IBloggingDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
public async Task<Blog> FindByShortNameAsync(string shortName)
{
return await DbSet.FirstOrDefaultAsync(p => p.ShortName == shortName);
}
}
}

@ -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<BlogDto> Blogs { get; private set; }
private readonly IBlogAppService _blogAppService;
public IndexModel()
public IReadOnlyList<BlogDto> Blogs { get; private set; }
public IndexModel(IBlogAppService blogAppService)
{
_blogAppService = blogAppService;
}
public async Task OnGet()
public async Task<IActionResult> OnGet()
{
Blogs = new List<BlogDto>
{
new BlogDto {Id = Guid.NewGuid(), Name = "abp", ShortName = "abp", Description = "a b p"}
};
var result = await _blogAppService.GetListAsync();
Blogs = result.Items;
return Page();
}
}
}
Loading…
Cancel
Save