Library to store book's account in db

This commit is contained in:
Robert McRackan 2020-08-20 17:03:55 -04:00
parent 80017ce9fd
commit cfa938360a
5 changed files with 23 additions and 6 deletions

View File

@ -66,7 +66,7 @@ namespace DataLayer
int lengthInMinutes,
IEnumerable<Contributor> authors,
IEnumerable<Contributor> narrators,
Category category)
Category category, string localeName)
{
// validate
ArgumentValidator.EnsureNotNull(audibleProductId, nameof(audibleProductId));
@ -75,6 +75,7 @@ namespace DataLayer
// assign as soon as possible. stuff below relies on this
AudibleProductId = productId;
Locale = localeName;
ArgumentValidator.EnsureNotNullOrWhiteSpace(title, nameof(title));
@ -243,6 +244,7 @@ namespace DataLayer
Category = category;
}
// needed for v3 => v4 upgrade
public void UpdateLocale(string localeName)
=> Locale ??= localeName;

View File

@ -14,13 +14,20 @@ namespace DataLayer
public string Account { get; private set; }
private LibraryBook() { }
public LibraryBook(Book book, DateTime dateAdded)
public LibraryBook(Book book, DateTime dateAdded, string account)
{
ArgumentValidator.EnsureNotNull(book, nameof(book));
ArgumentValidator.EnsureNotNull(account, nameof(account));
Book = book;
DateAdded = dateAdded;
Account = account;
}
public override string ToString() => $"{DateAdded:d} {Book}";
// needed for v3 => v4 upgrade
public void UpdateAccount(string account)
=> Account ??= account;
public override string ToString() => $"{DateAdded:d} {Book}";
}
}

View File

@ -105,7 +105,8 @@ namespace DtoImporterService
item.LengthInMinutes,
authors,
narrators,
category)
category,
Account.Locale.Name)
).Entity;
var publisherName = item.Publisher;
@ -129,6 +130,7 @@ namespace DtoImporterService
book.PictureId = item.PictureId;
book.UpdateProductRating(item.Product_OverallStars, item.Product_PerformanceStars, item.Product_StoryStars);
// needed during v3 => v4 migration
book.UpdateLocale(Account.Locale.Name);
// important to update user-specific info. this will have changed if user has rated/reviewed the book since last library import

View File

@ -30,10 +30,16 @@ namespace DtoImporterService
{
var libraryBook = new LibraryBook(
DbContext.Books.Local.Single(b => b.AudibleProductId == newItem.ProductId),
newItem.DateAdded);
newItem.DateAdded,
Account.AccountId);
DbContext.Library.Add(libraryBook);
}
// needed for v3 => v4 upgrade
var toUpdate = DbContext.Library.Where(l => l.Account == null);
foreach (var u in toUpdate)
u.UpdateAccount(Account.AccountId);
var qtyNew = newItems.Count;
return qtyNew;
}

View File

@ -13,7 +13,7 @@
<!-- <PublishSingleFile>true</PublishSingleFile> -->
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<Version>3.1.12.140</Version>
<Version>3.1.12.142</Version>
</PropertyGroup>
<ItemGroup>