From c4285919116df6fa4877b9121edb1ea1a38ba6d4 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Fri, 3 Aug 2018 14:15:59 +0300 Subject: [PATCH] Blogging module null check --- .../Volo/Blogging/Posts/PostAppService.cs | 2 ++ .../Volo/Blogging/Posts/EfCorePostRepository.cs | 10 +++++++++- .../Pages/Blog/Posts/Detail.cshtml.cs | 7 +++---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs index 5cc2327e10..b63a817893 100644 --- a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs +++ b/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 { diff --git a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs index 307a43156c..682b71aa7e 100644 --- a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs +++ b/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 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; } } } diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml.cs index 9aab468564..abdaad9b32 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml.cs +++ b/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}); } } } \ No newline at end of file