diff --git a/ApplicationServices/DbContexts.cs b/ApplicationServices/DbContexts.cs
index ff495b64..f860fd73 100644
--- a/ApplicationServices/DbContexts.cs
+++ b/ApplicationServices/DbContexts.cs
@@ -7,13 +7,11 @@ namespace ApplicationServices
{
public static class DbContexts
{
- //// idea for future command/query separation
- // public static LibationContext GetCommandContext() { }
- // public static LibationContext GetQueryContext() { }
-
+ /// Use for fully functional context, incl. SaveChanges(). For query-only, use the other method
public static LibationContext GetContext()
=> LibationContext.Create(SqliteStorage.ConnectionString);
+ /// Use for full library querying. No lazy loading
public static List GetLibrary_Flat_NoTracking()
{
using var context = GetContext();
diff --git a/ApplicationServices/LibraryCommands.cs b/ApplicationServices/LibraryCommands.cs
index ff7e0d69..683559da 100644
--- a/ApplicationServices/LibraryCommands.cs
+++ b/ApplicationServices/LibraryCommands.cs
@@ -155,13 +155,30 @@ namespace ApplicationServices
}
#endregion
- #region Update book details
+ #region remove books
+ public static List RemoveBooks(List idsToRemove)
+ {
+ using var context = DbContexts.GetContext();
+ var libBooks = context.GetLibrary_Flat_NoTracking();
+
+ var removeLibraryBooks = libBooks.Where(lb => idsToRemove.Contains(lb.Book.AudibleProductId)).ToList();
+ context.Library.RemoveRange(removeLibraryBooks);
+
+ var qtyChanges = context.SaveChanges();
+ if (qtyChanges > 0)
+ SearchEngineCommands.FullReIndex();
+
+ return removeLibraryBooks;
+ }
+ #endregion
+
///
/// Occurs when , , or
/// changed values are successfully persisted.
///
public static event EventHandler BookUserDefinedItemCommitted;
+ #region Update book details
public static int UpdateUserDefinedItem(Book book)
{
try
@@ -187,21 +204,6 @@ namespace ApplicationServices
}
#endregion
- #region remove books
- public static List RemoveBooks(List idsToRemove)
- {
- using var context = DbContexts.GetContext();
- var libBooks = context.GetLibrary_Flat_NoTracking();
-
- var removeLibraryBooks = libBooks.Where(lb => idsToRemove.Contains(lb.Book.AudibleProductId)).ToList();
- context.Library.RemoveRange(removeLibraryBooks);
-
- context.SaveChanges();
-
- return removeLibraryBooks;
- }
- #endregion
-
public static LiberatedStatus Liberated_Status(Book book)
=> book.Audio_Exists ? LiberatedStatus.Liberated
: FileManager.AudibleFileStorage.AaxcExists(book.AudibleProductId) ? LiberatedStatus.PartialDownload
diff --git a/ApplicationServices/SearchEngineCommands.cs b/ApplicationServices/SearchEngineCommands.cs
index 137ecd3c..9d871969 100644
--- a/ApplicationServices/SearchEngineCommands.cs
+++ b/ApplicationServices/SearchEngineCommands.cs
@@ -40,17 +40,17 @@ namespace ApplicationServices
}
}
- private static T performSearchEngineFunc_safe(Func action)
+ private static T performSearchEngineFunc_safe(Func func)
{
var engine = new SearchEngine();
try
{
- return action(engine);
+ return func(engine);
}
catch (FileNotFoundException)
{
FullReIndex(engine);
- return action(engine);
+ return func(engine);
}
}
}