From db285aac8034c99a42a26d2dd3c235b134683f63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Onur=20P=C4=B1=C3=A7akc=C4=B1?= <98148844+onurpicakci@users.noreply.github.com> Date: Wed, 31 May 2023 14:30:36 +0300 Subject: [PATCH] refactoring --- .../Volo/Blogging/Blogs/BlogAppService.cs | 5 +++++ .../Pages/Blogs/Posts/Index.cshtml.cs | 12 ++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) 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 index 4f4bd371ad..a65d92db30 100644 --- a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Blogs/BlogAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Blogs/BlogAppService.cs @@ -32,6 +32,11 @@ namespace Volo.Blogging.Blogs Check.NotNullOrWhiteSpace(shortName, nameof(shortName)); var blog = await BlogRepository.FindByShortNameAsync(shortName); + + if (blog == null) + { + throw new EntityNotFoundException(typeof(Blog), shortName); + } return ObjectMapper.Map(blog); } diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Index.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Index.cshtml.cs index be1bf5779b..b6cc33034a 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Index.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Index.cshtml.cs @@ -1,7 +1,9 @@ +using System; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; +using Volo.Abp.Domain.Entities; using Volo.Blogging.Blogs; using Volo.Blogging.Blogs.Dtos; using Volo.Blogging.Pages.Blogs.Shared.Helpers; @@ -43,11 +45,13 @@ namespace Volo.Blogging.Pages.Blog.Posts return NotFound(); } - Blog = await _blogAppService.GetByShortNameAsync(BlogShortName); - - if (Blog == null) + try { - return RedirectToPage("/Blogs/Index"); + Blog = await _blogAppService.GetByShortNameAsync(BlogShortName); + } + catch (EntityNotFoundException) + { + return RedirectToPage("/Blogs/Index"); } Posts = (await _postAppService.GetListByBlogIdAndTagNameAsync(Blog.Id, TagName)).Items;