//-------------------------------------------------------------- //private methods private static Book CreateBookWithRefs(BookInfoJson bookInfoJson, Dictionary <string, Author> authorDict) { var book = new Book { Title = bookInfoJson.title, Description = bookInfoJson.description, PublishedOn = DecodePubishDate(bookInfoJson.publishedDate), Publisher = bookInfoJson.publisher, Price = (decimal)(bookInfoJson.saleInfoListPriceAmount ?? -1), ImageUrl = bookInfoJson.imageLinksThumbnail }; byte i = 0; book.AuthorsLink = new List <BookAuthor>(); foreach (var author in bookInfoJson.authors) { book.AuthorsLink.Add(new BookAuthor { Book = book, Author = authorDict[author], Order = i++ }); } if (bookInfoJson.averageRating != null) { book.Reviews = CalculateReviewsToMatch((double)bookInfoJson.averageRating, (int)bookInfoJson.ratingsCount); } return(book); }
//-------------------------------------------------------------- //private methods private static Book CreateBookWithRefs(BookInfoJson bookInfoJson, Dictionary <string, Author> authorDict) { var authors = bookInfoJson.authors.Select(x => authorDict[x]).ToList(); var book = new Book(bookInfoJson.title, bookInfoJson.description, DecodePubishDate(bookInfoJson.publishedDate), bookInfoJson.publisher, ((decimal?)bookInfoJson.saleInfoListPriceAmount) ?? DefaultBookPrice, bookInfoJson.imageLinksThumbnail, authors); if (bookInfoJson.averageRating != null) { CalculateReviewsToMatch((double)bookInfoJson.averageRating, (int)bookInfoJson.ratingsCount).ToList() .ForEach(x => book.AddReview(x, null, "anonymous")); } return(book); }