aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Api/ModelBinders/LegacyDateTimeModelBinder.cs
diff options
context:
space:
mode:
authorDominik <git@secnd.me>2023-06-15 19:38:42 +0200
committerGitHub <noreply@github.com>2023-06-15 19:38:42 +0200
commit17f1e8d19b1fd693893d66d2275ed8ae2476344e (patch)
tree7f48be975faa92042769870957587b3c7864f631 /Jellyfin.Api/ModelBinders/LegacyDateTimeModelBinder.cs
parente8ae7e5c38e28f13fa8de295e26c930cb46d9b79 (diff)
parent6771b5cabe96b4b3cbd1cd0c998d564f3dd17ed4 (diff)
Merge branch 'master' into segment-deletion
Diffstat (limited to 'Jellyfin.Api/ModelBinders/LegacyDateTimeModelBinder.cs')
-rw-r--r--Jellyfin.Api/ModelBinders/LegacyDateTimeModelBinder.cs61
1 files changed, 30 insertions, 31 deletions
diff --git a/Jellyfin.Api/ModelBinders/LegacyDateTimeModelBinder.cs b/Jellyfin.Api/ModelBinders/LegacyDateTimeModelBinder.cs
index e1cb725f3..87a30773e 100644
--- a/Jellyfin.Api/ModelBinders/LegacyDateTimeModelBinder.cs
+++ b/Jellyfin.Api/ModelBinders/LegacyDateTimeModelBinder.cs
@@ -5,45 +5,44 @@ using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ModelBinding.Binders;
using Microsoft.Extensions.Logging;
-namespace Jellyfin.Api.ModelBinders
+namespace Jellyfin.Api.ModelBinders;
+
+/// <summary>
+/// DateTime model binder.
+/// </summary>
+public class LegacyDateTimeModelBinder : IModelBinder
{
+ // Borrowed from the DateTimeModelBinderProvider
+ private const DateTimeStyles SupportedStyles = DateTimeStyles.AdjustToUniversal | DateTimeStyles.AllowWhiteSpaces;
+ private readonly DateTimeModelBinder _defaultModelBinder;
+
/// <summary>
- /// DateTime model binder.
+ /// Initializes a new instance of the <see cref="LegacyDateTimeModelBinder"/> class.
/// </summary>
- public class LegacyDateTimeModelBinder : IModelBinder
+ /// <param name="loggerFactory">Instance of the <see cref="ILoggerFactory"/> interface.</param>
+ public LegacyDateTimeModelBinder(ILoggerFactory loggerFactory)
{
- // Borrowed from the DateTimeModelBinderProvider
- private const DateTimeStyles SupportedStyles = DateTimeStyles.AdjustToUniversal | DateTimeStyles.AllowWhiteSpaces;
- private readonly DateTimeModelBinder _defaultModelBinder;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="LegacyDateTimeModelBinder"/> class.
- /// </summary>
- /// <param name="loggerFactory">Instance of the <see cref="ILoggerFactory"/> interface.</param>
- public LegacyDateTimeModelBinder(ILoggerFactory loggerFactory)
- {
- _defaultModelBinder = new DateTimeModelBinder(SupportedStyles, loggerFactory);
- }
+ _defaultModelBinder = new DateTimeModelBinder(SupportedStyles, loggerFactory);
+ }
- /// <inheritdoc />
- public Task BindModelAsync(ModelBindingContext bindingContext)
+ /// <inheritdoc />
+ public Task BindModelAsync(ModelBindingContext bindingContext)
+ {
+ var valueProviderResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
+ if (valueProviderResult.Values.Count == 1)
{
- var valueProviderResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
- if (valueProviderResult.Values.Count == 1)
+ var dateTimeString = valueProviderResult.FirstValue;
+ // Mark Played Item.
+ if (DateTime.TryParseExact(dateTimeString, "yyyyMMddHHmmss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var dateTime))
{
- var dateTimeString = valueProviderResult.FirstValue;
- // Mark Played Item.
- if (DateTime.TryParseExact(dateTimeString, "yyyyMMddHHmmss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var dateTime))
- {
- bindingContext.Result = ModelBindingResult.Success(dateTime);
- }
- else
- {
- return _defaultModelBinder.BindModelAsync(bindingContext);
- }
+ bindingContext.Result = ModelBindingResult.Success(dateTime);
+ }
+ else
+ {
+ return _defaultModelBinder.BindModelAsync(bindingContext);
}
-
- return Task.CompletedTask;
}
+
+ return Task.CompletedTask;
}
}