From d2eaf2611758ea902761ecdb4cea209a63311cf2 Mon Sep 17 00:00:00 2001 From: Robert McRackan Date: Fri, 24 Sep 2021 10:00:52 -0400 Subject: [PATCH] Removing books * message box is too big when removing huge amounts of books. This scenario is typical when removing podcasts * removing books should remove user defined entries. eg: tags and is-liberated --- AppScaffolding/AppScaffolding.csproj | 2 +- ApplicationServices/LibraryCommands.cs | 1 + LibationWinForms/Dialogs/RemoveBooksDialog.cs | 12 +++++++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/AppScaffolding/AppScaffolding.csproj b/AppScaffolding/AppScaffolding.csproj index cb6f99e5..b957a88b 100644 --- a/AppScaffolding/AppScaffolding.csproj +++ b/AppScaffolding/AppScaffolding.csproj @@ -3,7 +3,7 @@ net5.0 - 6.1.0.1 + 6.1.1.1 diff --git a/ApplicationServices/LibraryCommands.cs b/ApplicationServices/LibraryCommands.cs index 75ae93f1..28df51b2 100644 --- a/ApplicationServices/LibraryCommands.cs +++ b/ApplicationServices/LibraryCommands.cs @@ -192,6 +192,7 @@ namespace ApplicationServices var removeLibraryBooks = libBooks.Where(lb => idsToRemove.Contains(lb.Book.AudibleProductId)).ToList(); context.LibraryBooks.RemoveRange(removeLibraryBooks); + context.Books.RemoveRange(removeLibraryBooks.Select(lb => lb.Book)); var qtyChanges = context.SaveChanges(); if (qtyChanges > 0) diff --git a/LibationWinForms/Dialogs/RemoveBooksDialog.cs b/LibationWinForms/Dialogs/RemoveBooksDialog.cs index f905c54f..7c504414 100644 --- a/LibationWinForms/Dialogs/RemoveBooksDialog.cs +++ b/LibationWinForms/Dialogs/RemoveBooksDialog.cs @@ -91,16 +91,22 @@ namespace LibationWinForms.Dialogs { var selectedBooks = SelectedEntries.ToList(); - if (selectedBooks.Count == 0) return; + if (selectedBooks.Count == 0) + return; - string titles = string.Join("\r\n", selectedBooks.Select(rge => "-" + rge.Title)); + var titles = selectedBooks.Select(rge => "- " + rge.Title).ToList(); + var titlesAgg = titles.Take(5).Aggregate((a, b) => $"{a}\r\n{b}"); + if (titles.Count == 6) + titlesAgg += $"\r\n\r\nand 1 other"; + else if (titles.Count > 6) + titlesAgg += $"\r\n\r\nand {titles.Count - 5} others"; string thisThese = selectedBooks.Count > 1 ? "these" : "this"; string bookBooks = selectedBooks.Count > 1 ? "books" : "book"; var result = MessageBox.Show( this, - $"Are you sure you want to remove {thisThese} {selectedBooks.Count} {bookBooks} from Libation's library?\r\n\r\n{titles}", + $"Are you sure you want to remove {thisThese} {selectedBooks.Count} {bookBooks} from Libation's library?\r\n\r\n{titlesAgg}", "Remove books from Libation?", MessageBoxButtons.YesNo, MessageBoxIcon.Question,