aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Models
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-06-04 00:40:19 +0800
committercrupest <crupest@outlook.com>2020-06-04 00:40:19 +0800
commit189214cae17d6255989529ff47b2d963ed4c1038 (patch)
tree5e8010143dcc151dea369dd786cf060acc0c3fe4 /Timeline/Models
parente0f80f02ff60e901a20713d906ff212700861863 (diff)
downloadtimeline-189214cae17d6255989529ff47b2d963ed4c1038.tar.gz
timeline-189214cae17d6255989529ff47b2d963ed4c1038.tar.bz2
timeline-189214cae17d6255989529ff47b2d963ed4c1038.zip
chore(back): Fix some warnings.
Diffstat (limited to 'Timeline/Models')
-rw-r--r--Timeline/Models/Http/ActionContextAccessorExtensions.cs14
-rw-r--r--Timeline/Models/Http/Timeline.cs15
-rw-r--r--Timeline/Models/Http/UserInfo.cs5
3 files changed, 21 insertions, 13 deletions
diff --git a/Timeline/Models/Http/ActionContextAccessorExtensions.cs b/Timeline/Models/Http/ActionContextAccessorExtensions.cs
new file mode 100644
index 00000000..bcc55c5a
--- /dev/null
+++ b/Timeline/Models/Http/ActionContextAccessorExtensions.cs
@@ -0,0 +1,14 @@
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.Infrastructure;
+using System;
+
+namespace Timeline.Models.Http
+{
+ public static class ActionContextAccessorExtensions
+ {
+ public static ActionContext AssertActionContextForUrlFill(this IActionContextAccessor accessor)
+ {
+ return accessor.ActionContext ?? throw new InvalidOperationException(Resources.Models.Http.Exception.ActionContextNull);
+ }
+ }
+}
diff --git a/Timeline/Models/Http/Timeline.cs b/Timeline/Models/Http/Timeline.cs
index 9e2aefd0..fb767f10 100644
--- a/Timeline/Models/Http/Timeline.cs
+++ b/Timeline/Models/Http/Timeline.cs
@@ -58,11 +58,8 @@ namespace Timeline.Models.Http
public TimelineInfoLinks Resolve(Timeline source, TimelineInfo destination, TimelineInfoLinks destMember, ResolutionContext context)
{
- if (_actionContextAccessor.ActionContext == null)
- throw new InvalidOperationException("No action context, can't fill urls.");
-
- var urlHelper = _urlHelperFactory.GetUrlHelper(_actionContextAccessor.ActionContext);
-
+ var actionContext = _actionContextAccessor.AssertActionContextForUrlFill();
+ var urlHelper = _urlHelperFactory.GetUrlHelper(actionContext);
return new TimelineInfoLinks
{
@@ -85,10 +82,8 @@ namespace Timeline.Models.Http
public TimelinePostContentInfo Resolve(TimelinePost source, TimelinePostInfo destination, TimelinePostContentInfo destMember, ResolutionContext context)
{
- if (_actionContextAccessor.ActionContext == null)
- throw new InvalidOperationException("No action context, can't fill urls.");
-
- var urlHelper = _urlHelperFactory.GetUrlHelper(_actionContextAccessor.ActionContext);
+ var actionContext = _actionContextAccessor.AssertActionContextForUrlFill();
+ var urlHelper = _urlHelperFactory.GetUrlHelper(actionContext);
var sourceContent = source.Content;
@@ -113,7 +108,7 @@ namespace Timeline.Models.Http
}
else
{
- throw new InvalidOperationException("Unknown content type.");
+ throw new InvalidOperationException(Resources.Models.Http.Exception.UnknownPostContentType);
}
}
}
diff --git a/Timeline/Models/Http/UserInfo.cs b/Timeline/Models/Http/UserInfo.cs
index b4bf14c1..0acb1a80 100644
--- a/Timeline/Models/Http/UserInfo.cs
+++ b/Timeline/Models/Http/UserInfo.cs
@@ -37,10 +37,9 @@ namespace Timeline.Models.Http
public UserInfoLinks Resolve(User source, UserInfo destination, UserInfoLinks destMember, ResolutionContext context)
{
- if (_actionContextAccessor.ActionContext == null)
- throw new InvalidOperationException("No action context, can't fill urls.");
+ var actionContext = _actionContextAccessor.AssertActionContextForUrlFill();
+ var urlHelper = _urlHelperFactory.GetUrlHelper(actionContext);
- var urlHelper = _urlHelperFactory.GetUrlHelper(_actionContextAccessor.ActionContext);
var result = new UserInfoLinks
{
Self = urlHelper.ActionLink(nameof(UserController.Get), nameof(UserController)[0..^nameof(Controller).Length], new { destination.Username }),