From 3a8834931bf7191d5100b46ec33b395904b9e62b 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: Fri, 12 May 2023 14:19:07 +0300 Subject: [PATCH] refactoring --- .../Volo/Blogging/Posts/PostAppService.cs | 27 ++++++++++--------- .../Pages/Blogs/Posts/Detail.cshtml | 18 ++++--------- 2 files changed, 19 insertions(+), 26 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 939dc29640..1983bd3cbf 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 @@ -203,21 +203,22 @@ namespace Volo.Blogging.Posts foreach (var postDto in postDtos) { - if (postDto.CreatorId.HasValue) + if (!postDto.CreatorId.HasValue) { - if (!userDictionary.ContainsKey(postDto.CreatorId.Value)) - { - var creatorUser = await UserLookupService.FindByIdAsync(postDto.CreatorId.Value); - if (creatorUser != null) - { - userDictionary[creatorUser.Id] = ObjectMapper.Map(creatorUser); - } - } + continue; + } - if (userDictionary.ContainsKey(postDto.CreatorId.Value)) - { - postDto.Writer = userDictionary[(Guid)postDto.CreatorId]; - } + if (userDictionary.TryGetValue(postDto.CreatorId.Value, out var creatorUserDto)) + { + postDto.Writer = creatorUserDto; + continue; + } + + var creatorUser = await UserLookupService.FindByIdAsync(postDto.CreatorId.Value); + if (creatorUser != null) + { + postDto.Writer = ObjectMapper.Map(creatorUser); + userDictionary[creatorUser.Id] = postDto.Writer; } } diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml index 43ad9abc2f..9c44b0feb2 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml @@ -129,6 +129,11 @@ +
+

+ @Html.Raw(BloggingPageHelper.RenderMarkdownToHtml(Model.Post.Content)) +

+
@@ -210,19 +215,6 @@
-
-
-
-

- @Html.Raw(BloggingPageHelper.RenderMarkdownToHtml(Model.Post.Content)) -

-
-
-
- -
-
-
@if (Model.Post.Tags.Count > 0)