minor
This commit is contained in:
parent
b4803c42a5
commit
802763a4fb
@ -7,13 +7,11 @@ namespace ApplicationServices
|
|||||||
{
|
{
|
||||||
public static class DbContexts
|
public static class DbContexts
|
||||||
{
|
{
|
||||||
//// idea for future command/query separation
|
/// <summary>Use for fully functional context, incl. SaveChanges(). For query-only, use the other method</summary>
|
||||||
// public static LibationContext GetCommandContext() { }
|
|
||||||
// public static LibationContext GetQueryContext() { }
|
|
||||||
|
|
||||||
public static LibationContext GetContext()
|
public static LibationContext GetContext()
|
||||||
=> LibationContext.Create(SqliteStorage.ConnectionString);
|
=> LibationContext.Create(SqliteStorage.ConnectionString);
|
||||||
|
|
||||||
|
/// <summary>Use for full library querying. No lazy loading</summary>
|
||||||
public static List<LibraryBook> GetLibrary_Flat_NoTracking()
|
public static List<LibraryBook> GetLibrary_Flat_NoTracking()
|
||||||
{
|
{
|
||||||
using var context = GetContext();
|
using var context = GetContext();
|
||||||
|
|||||||
@ -155,13 +155,30 @@ namespace ApplicationServices
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Update book details
|
#region remove books
|
||||||
|
public static List<LibraryBook> RemoveBooks(List<string> 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
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Occurs when <see cref="UserDefinedItem.Tags"/>, <see cref="UserDefinedItem.BookStatus"/>, or <see cref="UserDefinedItem.PdfStatus"/>
|
/// Occurs when <see cref="UserDefinedItem.Tags"/>, <see cref="UserDefinedItem.BookStatus"/>, or <see cref="UserDefinedItem.PdfStatus"/>
|
||||||
/// changed values are successfully persisted.
|
/// changed values are successfully persisted.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static event EventHandler<string> BookUserDefinedItemCommitted;
|
public static event EventHandler<string> BookUserDefinedItemCommitted;
|
||||||
|
|
||||||
|
#region Update book details
|
||||||
public static int UpdateUserDefinedItem(Book book)
|
public static int UpdateUserDefinedItem(Book book)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -187,21 +204,6 @@ namespace ApplicationServices
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region remove books
|
|
||||||
public static List<LibraryBook> RemoveBooks(List<string> 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)
|
public static LiberatedStatus Liberated_Status(Book book)
|
||||||
=> book.Audio_Exists ? LiberatedStatus.Liberated
|
=> book.Audio_Exists ? LiberatedStatus.Liberated
|
||||||
: FileManager.AudibleFileStorage.AaxcExists(book.AudibleProductId) ? LiberatedStatus.PartialDownload
|
: FileManager.AudibleFileStorage.AaxcExists(book.AudibleProductId) ? LiberatedStatus.PartialDownload
|
||||||
|
|||||||
@ -40,17 +40,17 @@ namespace ApplicationServices
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static T performSearchEngineFunc_safe<T>(Func<SearchEngine, T> action)
|
private static T performSearchEngineFunc_safe<T>(Func<SearchEngine, T> func)
|
||||||
{
|
{
|
||||||
var engine = new SearchEngine();
|
var engine = new SearchEngine();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return action(engine);
|
return func(engine);
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException)
|
catch (FileNotFoundException)
|
||||||
{
|
{
|
||||||
FullReIndex(engine);
|
FullReIndex(engine);
|
||||||
return action(engine);
|
return func(engine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user