/// <summary> /// Loads a new book into the database for the given user, reusing records wherever possible. /// </summary> /// <param name="db"></param> /// <param name="ep"></param> /// <param name="userId"></param> /// <returns></returns> /// <remarks>Does not save the changes.</remarks> public static Book Load(EbooksContext db, Epub ep, int userId) { var book = new Book { UserId = userId, Title = ep.Title, Author = Author.Get(db, ep), Publisher = Publisher.Get(db, ep), Cover = Cover.Get(db, ep), EpubFile = EpubFile.Get(db, ep), Series = Series.Get(db, ep), SeriesNbr = ep.SeriesNbr, Description = ep.Description }; book.SetTags(db, ep.Tags); book.SetIdentifiers(db, ep.Identifiers); db.Books.Add(book); return book; }