diff options
| author | Shadowghost <Ghost_of_Stone@web.de> | 2023-01-31 12:18:10 +0100 |
|---|---|---|
| committer | Shadowghost <Ghost_of_Stone@web.de> | 2023-02-02 18:50:33 +0100 |
| commit | f5f890e68562e55d4bed16c454c4b4305152b296 (patch) | |
| tree | b52e3b45ceb2faa446153866600b4456fed44c8b /Jellyfin.Api/ModelBinders/LegacyDateTimeModelBinder.cs | |
| parent | 58b3945805db4f88bc069ee84013bdf85d7429b1 (diff) | |
Migrate to file-scoped namespaces
Diffstat (limited to 'Jellyfin.Api/ModelBinders/LegacyDateTimeModelBinder.cs')
| -rw-r--r-- | Jellyfin.Api/ModelBinders/LegacyDateTimeModelBinder.cs | 61 |
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; } } |
