From a639857ec6631bd752e8c941ee18b25b0ec05eb7 Mon Sep 17 00:00:00 2001 From: Robert McRackan Date: Fri, 20 Aug 2021 16:06:01 -0400 Subject: [PATCH] Book details changes liberated status in db and search engine. Minor changes to audible api to hopefully fix the weird log-in edge cases --- ApplicationServices/LibraryCommands.cs | 20 ++++++++++++++++---- LibationLauncher/LibationLauncher.csproj | 2 +- LibationWinForms/ProductsGrid.cs | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/ApplicationServices/LibraryCommands.cs b/ApplicationServices/LibraryCommands.cs index c8f1a05f..b27d5693 100644 --- a/ApplicationServices/LibraryCommands.cs +++ b/ApplicationServices/LibraryCommands.cs @@ -162,7 +162,7 @@ namespace ApplicationServices #endregion #region Update book details - public static int UpdateTags(Book book, string newTags) + public static int UpdateUserDefinedItem(Book book, string newTags, LiberatedStatus bookStatus, LiberatedStatus? pdfStatus) { try { @@ -170,16 +170,28 @@ namespace ApplicationServices var udi = book.UserDefinedItem; - if (udi.Tags == newTags) + var tagsChanged = udi.Tags != newTags; + var bookStatusChanged = udi.BookStatus != bookStatus; + var pdfStatusChanged = udi.PdfStatus != pdfStatus; + + if (!tagsChanged && !bookStatusChanged && !pdfStatusChanged) return 0; - // Attach() NoTracking entities before SaveChanges() udi.Tags = newTags; + udi.BookStatus = bookStatus; + udi.PdfStatus = pdfStatus; + + // Attach() NoTracking entities before SaveChanges() context.Attach(udi).State = Microsoft.EntityFrameworkCore.EntityState.Modified; var qtyChanges = context.SaveChanges(); - if (qtyChanges > 0) + if (qtyChanges == 0) + return 0; + + if (tagsChanged) SearchEngineCommands.UpdateBookTags(book); + if (bookStatusChanged || pdfStatusChanged) + SearchEngineCommands.UpdateLiberatedStatus(book); return qtyChanges; } diff --git a/LibationLauncher/LibationLauncher.csproj b/LibationLauncher/LibationLauncher.csproj index adda89af..ee621d18 100644 --- a/LibationLauncher/LibationLauncher.csproj +++ b/LibationLauncher/LibationLauncher.csproj @@ -13,7 +13,7 @@ win-x64 - 5.5.1.3 + 5.5.1.5 diff --git a/LibationWinForms/ProductsGrid.cs b/LibationWinForms/ProductsGrid.cs index bed5c441..1aea5520 100644 --- a/LibationWinForms/ProductsGrid.cs +++ b/LibationWinForms/ProductsGrid.cs @@ -95,7 +95,7 @@ namespace LibationWinForms if (bookDetailsForm.ShowDialog() != DialogResult.OK) return; - var qtyChanges = LibraryCommands.UpdateTags(libraryBook.Book, bookDetailsForm.NewTags); + var qtyChanges = LibraryCommands.UpdateUserDefinedItem(libraryBook.Book, bookDetailsForm.NewTags, bookDetailsForm.BookLiberatedStatus, bookDetailsForm.PdfLiberatedStatus); if (qtyChanges == 0) return;