Simplify ManualImportModule null check

This commit is contained in:
Qstick 2020-09-06 22:51:25 -04:00
parent e8e4d76d73
commit 6713525757
2 changed files with 16 additions and 7 deletions

View File

@ -47,14 +47,11 @@ namespace Lidarr.Api.V1.ManualImport
var downloadId = (string)Request.Query.downloadId;
NzbDrone.Core.Music.Artist artist = null;
var artistIdQuery = Request.Query.artistId;
if (artistIdQuery.HasValue)
var artistIdQuery = Request.GetNullableIntegerQueryParameter("artistId", null);
if (artistIdQuery.HasValue && artistIdQuery.Value > 0)
{
var artistId = Convert.ToInt32(artistIdQuery.Value);
if (artistId > 0)
{
artist = _artistService.GetArtist(Convert.ToInt32(artistIdQuery.Value));
}
artist = _artistService.GetArtist(Convert.ToInt32(artistIdQuery.Value));
}
var filter = Request.GetBooleanQueryParameter("filterExistingFiles", true) ? FilterFilesType.Matched : FilterFilesType.None;

View File

@ -78,5 +78,17 @@ namespace Lidarr.Http.Extensions
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;
}
}
}