Exemple #1
0
 private List <CandidateEdition> GetDbCandidatesByBook(Book book, bool includeExisting)
 {
     // Sort by most voted so less likely to swap to a random release
     return(GetDbCandidatesByEdition(_editionService.GetEditionsByBook(book.Id)
                                     .OrderByDescending(x => x.Ratings.Votes)
                                     .ToList(), includeExisting));
 }
Exemple #2
0
        private void AddDbIds(string authorId, Book book, Dictionary <string, AuthorMetadata> authors)
        {
            var dbBook = _bookService.FindById(book.ForeignBookId);

            if (dbBook != null)
            {
                book.UseDbFieldsFrom(dbBook);

                var editions = _editionService.GetEditionsByBook(dbBook.Id).ToDictionary(x => x.ForeignEditionId);

                // If we have any database editions, exactly one will be monitored.
                // So unmonitor all the found editions and let the UseDbFieldsFrom set
                // the monitored status
                foreach (var edition in book.Editions.Value)
                {
                    edition.Monitored = false;
                    if (editions.TryGetValue(edition.ForeignEditionId, out var dbEdition))
                    {
                        edition.UseDbFieldsFrom(dbEdition);
                    }
                }

                // Double check at least one edition is monitored
                if (book.Editions.Value.Any() && !book.Editions.Value.Any(x => x.Monitored))
                {
                    var mostPopular = book.Editions.Value.OrderByDescending(x => x.Ratings.Popularity).First();
                    mostPopular.Monitored = true;
                }
            }

            var author = _authorService.FindById(authorId);

            if (author == null)
            {
                if (!authors.TryGetValue(authorId, out var metadata))
                {
                    throw new BookInfoException(string.Format("Expected author metadata for id [{0}] in book data {1}", authorId, book));
                }

                author = new Author
                {
                    CleanName = Parser.Parser.CleanAuthorName(metadata.Name),
                    Metadata  = metadata
                };
            }

            book.Author           = author;
            book.AuthorMetadata   = author.Metadata.Value;
            book.AuthorMetadataId = author.AuthorMetadataId;
        }
Exemple #3
0
        public List <EditionResource> GetEditions(int bookId)
        {
            var editions = _editionService.GetEditionsByBook(bookId);

            return(editions.ToResource());
        }