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

View File

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

View File

@ -105,7 +105,8 @@ namespace DtoImporterService
item.LengthInMinutes, item.LengthInMinutes,
authors, authors,
narrators, narrators,
category) category,
Account.Locale.Name)
).Entity; ).Entity;
var publisherName = item.Publisher; var publisherName = item.Publisher;
@ -129,6 +130,7 @@ namespace DtoImporterService
book.PictureId = item.PictureId; book.PictureId = item.PictureId;
book.UpdateProductRating(item.Product_OverallStars, item.Product_PerformanceStars, item.Product_StoryStars); book.UpdateProductRating(item.Product_OverallStars, item.Product_PerformanceStars, item.Product_StoryStars);
// needed during v3 => v4 migration
book.UpdateLocale(Account.Locale.Name); 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 // 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( var libraryBook = new LibraryBook(
DbContext.Books.Local.Single(b => b.AudibleProductId == newItem.ProductId), DbContext.Books.Local.Single(b => b.AudibleProductId == newItem.ProductId),
newItem.DateAdded); newItem.DateAdded,
Account.AccountId);
DbContext.Library.Add(libraryBook); 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; var qtyNew = newItems.Count;
return qtyNew; return qtyNew;
} }

View File

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