From c6f37a916820a957d3fab165cbeaeab18937b4cb Mon Sep 17 00:00:00 2001 From: Bogdan Date: Thu, 11 May 2023 20:17:55 +0300 Subject: [PATCH] Fix saving without changing book edition --- src/Readarr.Api.V1/Books/BookController.cs | 2 +- src/Readarr.Api.V1/Books/BookResource.cs | 4 ++-- src/Readarr.Api.V1/Books/EditionResource.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Readarr.Api.V1/Books/BookController.cs b/src/Readarr.Api.V1/Books/BookController.cs index bd7762d57..935714d7a 100644 --- a/src/Readarr.Api.V1/Books/BookController.cs +++ b/src/Readarr.Api.V1/Books/BookController.cs @@ -167,7 +167,7 @@ namespace Readarr.Api.V1.Books var model = bookResource.ToModel(book); _bookService.UpdateBook(model); - _editionService.UpdateMany(model.Editions.Value); + _editionService.UpdateMany(model.Editions.Value ?? new List()); BroadcastResourceChange(ModelAction.Updated, model.Id); diff --git a/src/Readarr.Api.V1/Books/BookResource.cs b/src/Readarr.Api.V1/Books/BookResource.cs index c8fa6e9f7..19bac16dd 100644 --- a/src/Readarr.Api.V1/Books/BookResource.cs +++ b/src/Readarr.Api.V1/Books/BookResource.cs @@ -49,7 +49,7 @@ namespace Readarr.Api.V1.Books return null; } - var selectedEdition = model.Editions?.Value.Where(x => x.Monitored).SingleOrDefault(); + var selectedEdition = model.Editions?.Value?.SingleOrDefault(x => x.Monitored); var title = selectedEdition?.Title ?? model.Title; var authorTitle = $"{model.Author?.Value?.Metadata?.Value?.SortNameLastFirst} {title}"; @@ -120,7 +120,7 @@ namespace Readarr.Api.V1.Books public static List ToModel(this IEnumerable resources) { - return resources.Select(ToModel).ToList(); + return resources?.Select(ToModel).ToList(); } } } diff --git a/src/Readarr.Api.V1/Books/EditionResource.cs b/src/Readarr.Api.V1/Books/EditionResource.cs index 8e76b4130..b142e74d6 100644 --- a/src/Readarr.Api.V1/Books/EditionResource.cs +++ b/src/Readarr.Api.V1/Books/EditionResource.cs @@ -109,7 +109,7 @@ namespace Readarr.Api.V1.Books public static List ToModel(this IEnumerable resources) { - return resources.Select(ToModel).ToList(); + return resources?.Select(ToModel).ToList(); } } }