Browse Source

Blogging module null check

pull/400/head
Yunus Emre Kalkan 8 years ago
parent
commit
c428591911
  1. 2
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs
  2. 10
      modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs
  3. 7
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml.cs

2
modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs

@ -5,7 +5,9 @@ using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using System.Collections.Generic;
using Microsoft.AspNetCore.Authorization;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Users;
using Volo.Blogging.Blogs;
namespace Volo.Blogging.Posts
{

10
modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs

@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using Volo.Blogging.Blogs;
@ -26,7 +27,14 @@ namespace Volo.Blogging.Posts
public async Task<Post> GetPostByUrl(Guid blogId, string url)
{
return await DbSet.FirstOrDefaultAsync(p => p.BlogId == blogId && p.Url == url);
var post = await DbSet.FirstOrDefaultAsync(p => p.BlogId == blogId && p.Url == url);
if (post == null)
{
throw new EntityNotFoundException(typeof(Post), nameof(post));
}
return post;
}
}
}

7
modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml.cs

@ -4,6 +4,7 @@ using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Volo.Abp.Domain.Entities;
using Volo.Blogging.Blogs;
using Volo.Blogging.Posts;
@ -32,10 +33,8 @@ namespace Volo.Blogging.Pages.Blog.Posts
public async void OnGet()
{
var blog = await _blogAppService.GetByShortNameAsync(BlogShortName);
Post = await _postAppService.GetByUrlAsync(new GetPostInput {BlogId = blog.Id , Url = PostUrl});
Blog = blog;
Blog = await _blogAppService.GetByShortNameAsync(BlogShortName);
Post = await _postAppService.GetByUrlAsync(new GetPostInput {BlogId = Blog.Id , Url = PostUrl});
}
}
}
Loading…
Cancel
Save