Simplify ManualImportModule null check

Signed-off-by: Robin Dadswell <robin@dadswell.email>
pull/770/head
Qstick 4 years ago
parent ff40d82ef1
commit 3101544484

@ -47,15 +47,11 @@ namespace Readarr.Api.V1.ManualImport
var downloadId = (string)Request.Query.downloadId;
NzbDrone.Core.Books.Author author = null;
var authorIdQuery = Request.Query.authorId;
if (authorIdQuery.HasValue)
{
var authorId = Convert.ToInt32(authorIdQuery.Value);
var authorIdQuery = Request.GetNullableIntegerQueryParameter("authorId", null);
if (authorId > 0)
{
author = _authorService.GetAuthor(authorId);
}
if (authorIdQuery.HasValue && authorIdQuery.Value > 0)
{
author = _authorService.GetAuthor(Convert.ToInt32(authorIdQuery.Value));
}
var filter = Request.GetBooleanQueryParameter("filterExistingFiles", true) ? FilterFilesType.Matched : FilterFilesType.None;

@ -66,5 +66,29 @@ namespace Readarr.Http.Extensions
return defaultValue;
}
public static Guid GetGuidQueryParameter(this Request request, string parameter, Guid defaultValue = default)
{
var parameterValue = request.Query[parameter];
if (parameterValue.HasValue)
{
return Guid.Parse(parameterValue.Value);
}
return defaultValue;
}
public static int? GetNullableIntegerQueryParameter(this Request request, string parameter, int? defaultValue = null)
{
var parameterValue = request.Query[parameter];
if (parameterValue.HasValue)
{
return int.Parse(parameterValue.Value);
}
return defaultValue;
}
}
}

Loading…
Cancel
Save