Simplify ManualImportModule null check

Signed-off-by: Robin Dadswell <robin@dadswell.email>
This commit is contained in:
Qstick 2020-09-06 22:51:25 -04:00
parent ff40d82ef1
commit 3101544484
2 changed files with 28 additions and 8 deletions

View file

@ -47,15 +47,11 @@ private List<ManualImportResource> GetMediaFiles()
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;

View file

@ -66,5 +66,29 @@ public static int GetIntegerQueryParameter(this Request request, string paramete
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;
}
}
}