Browse Source

Refactoring #16941

pull/16941/head
Engincan VESKE 3 years ago
parent
commit
7720a868ba
  1. 18
      modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/BloggingPageHelper.cs
  2. 6
      modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml
  3. 6
      modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Index.cshtml

18
modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/BloggingPageHelper.cs

@ -98,7 +98,7 @@ namespace Volo.Blogging.Pages.Blog
.Build()); .Build());
} }
public LocalizedHtmlString ConvertDatetimeToTimeAgo(DateTime dt) public LocalizedHtmlString GetLocalizedTimeAgoText(DateTime dt)
{ {
var timeDiff = DateTime.Now - dt; var timeDiff = DateTime.Now - dt;
@ -107,13 +107,13 @@ namespace Volo.Blogging.Pages.Blog
switch (diffInDays) switch (diffInDays)
{ {
case >= 365: case >= 365:
return GetLocalizedTimeAgoText("YearsAgo", "YearAgo", diffInDays / 365); return GetLocalizedTextAsSingularOrPlural("YearsAgo", "YearAgo", diffInDays / 365);
case >= 30: case >= 30:
return GetLocalizedTimeAgoText("MonthsAgo", "MonthAgo", diffInDays / 30); return GetLocalizedTextAsSingularOrPlural("MonthsAgo", "MonthAgo", diffInDays / 30);
case >= 7: case >= 7:
return GetLocalizedTimeAgoText("WeeksAgo", "WeekAgo", diffInDays / 7); return GetLocalizedTextAsSingularOrPlural("WeeksAgo", "WeekAgo", diffInDays / 7);
case >= 1: case >= 1:
return GetLocalizedTimeAgoText("DaysAgo", "DayAgo", diffInDays); return GetLocalizedTextAsSingularOrPlural("DaysAgo", "DayAgo", diffInDays);
} }
var diffInSeconds = (int) timeDiff.TotalSeconds; var diffInSeconds = (int) timeDiff.TotalSeconds;
@ -121,17 +121,17 @@ namespace Volo.Blogging.Pages.Blog
switch (diffInSeconds) switch (diffInSeconds)
{ {
case >= 3600: case >= 3600:
return GetLocalizedTimeAgoText("HoursAgo", "HourAgo", diffInSeconds / 3600); return GetLocalizedTextAsSingularOrPlural("HoursAgo", "HourAgo", diffInSeconds / 3600);
case >= 60: case >= 60:
return GetLocalizedTimeAgoText("MinutesAgo", "MinuteAgo", diffInSeconds / 60); return GetLocalizedTextAsSingularOrPlural("MinutesAgo", "MinuteAgo", diffInSeconds / 60);
case >= 1: case >= 1:
return GetLocalizedTimeAgoText("SecondsAgo", "SecondAgo", diffInSeconds); return GetLocalizedTextAsSingularOrPlural("SecondsAgo", "SecondAgo", diffInSeconds);
default: default:
return L["Now"]; return L["Now"];
} }
} }
protected virtual LocalizedHtmlString GetLocalizedTimeAgoText(string pluralKey, string singularKey, int value) protected virtual LocalizedHtmlString GetLocalizedTextAsSingularOrPlural(string pluralKey, string singularKey, int value)
{ {
return value != 1 ? L[pluralKey, value] : L[singularKey, value]; return value != 1 ? L[pluralKey, value] : L[singularKey, value];
} }

6
modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml

@ -79,7 +79,7 @@
<a href="/Members/@Model.Post.Writer.UserName"> <a href="/Members/@Model.Post.Writer.UserName">
@(Model.Post.Writer.UserName) @(Model.Post.Writer.UserName)
</a> </a>
<span>@BloggingPageHelper.ConvertDatetimeToTimeAgo(Model.Post.CreationTime)</span> <span>@BloggingPageHelper.GetLocalizedTimeAgoText(Model.Post.CreationTime)</span>
</h5> </h5>
} }
@ -262,7 +262,7 @@
<div class="media-body"> <div class="media-body">
<h5 class="comment-owner"> <h5 class="comment-owner">
@(commentWithRepliesDto.Comment.Writer == null ? "" : commentWithRepliesDto.Comment.Writer.UserName) @(commentWithRepliesDto.Comment.Writer == null ? "" : commentWithRepliesDto.Comment.Writer.UserName)
<span>@BloggingPageHelper.ConvertDatetimeToTimeAgo(commentWithRepliesDto.Comment.CreationTime)</span> <span>@BloggingPageHelper.GetLocalizedTimeAgoText(commentWithRepliesDto.Comment.CreationTime)</span>
</h5> </h5>
<p id="@commentWithRepliesDto.Comment.Id"> <p id="@commentWithRepliesDto.Comment.Id">
@commentWithRepliesDto.Comment.Text @commentWithRepliesDto.Comment.Text
@ -342,7 +342,7 @@
<div class="media-body"> <div class="media-body">
<h5 class="comment-owner"> <h5 class="comment-owner">
@(reply.Writer == null ? "" : reply.Writer.UserName) @(reply.Writer == null ? "" : reply.Writer.UserName)
<span>@BloggingPageHelper.ConvertDatetimeToTimeAgo(reply.CreationTime)</span> <span>@BloggingPageHelper.GetLocalizedTimeAgoText(reply.CreationTime)</span>
</h5> </h5>
<p id="@reply.Id"> <p id="@reply.Id">
@reply.Text @reply.Text

6
modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Index.cshtml

@ -69,7 +69,7 @@
<a href="/Members/@post.Writer.UserName"> <a href="/Members/@post.Writer.UserName">
@post.Writer.UserName @post.Writer.UserName
</a> </a>
<span>@BloggingPageHelper.ConvertDatetimeToTimeAgo(post.CreationTime)</span> <span>@BloggingPageHelper.GetLocalizedTimeAgoText(post.CreationTime)</span>
</h5> </h5>
<i class="fa fa-eye"></i> @L["WiewsWithCount", post.ReadCount] <i class="fa fa-eye"></i> @L["WiewsWithCount", post.ReadCount]
@*<span class="vs-seperator">|</span> @*<span class="vs-seperator">|</span>
@ -130,7 +130,7 @@
<a href="/Members/@post.Writer.UserName"> <a href="/Members/@post.Writer.UserName">
@post.Writer.UserName @post.Writer.UserName
</a> </a>
<span>@BloggingPageHelper.ConvertDatetimeToTimeAgo(post.CreationTime)</span> <span>@BloggingPageHelper.GetLocalizedTimeAgoText(post.CreationTime)</span>
</h5> </h5>
} }
<i class="fa fa-eye"></i> @L["WiewsWithCount", post.ReadCount] <i class="fa fa-eye"></i> @L["WiewsWithCount", post.ReadCount]
@ -199,7 +199,7 @@
<a href="/Members/@post.Writer.UserName"> <a href="/Members/@post.Writer.UserName">
@post.Writer.UserName @post.Writer.UserName
</a> </a>
<span>@BloggingPageHelper.ConvertDatetimeToTimeAgo(post.CreationTime)</span> <span>@BloggingPageHelper.GetLocalizedTimeAgoText(post.CreationTime)</span>
</h5> </h5>
<i class="fa fa-eye"></i> @L["WiewsWithCount", post.ReadCount] <i class="fa fa-eye"></i> @L["WiewsWithCount", post.ReadCount]
@*<span class="vs-seperator">|</span> @*<span class="vs-seperator">|</span>

Loading…
Cancel
Save