Ejemplo n.º 1
0
 public Book(GutBook book)
 {
     Id = book.GutBookId;
     Author = book.GutAuthor?.Name;
     Title = book.Title;
     HasImagesEpub = book.StandardEpubUrlImages || !string.IsNullOrWhiteSpace(book.EpubUrlImages);
     HasNoImagesEpub = book.StandardEpubUrlNoImages || !string.IsNullOrWhiteSpace(book.EpubUrlNoImages);
     Languages = string.Join("\r\n", book.GetLanguages());
 }
        private void loadBookData(EbooksContext db, GutCatDoc doc, IList<GutBook> newBooks, IList<GutAuthor> newAuthors, IList<LanguageName> newLangNames, IList<LanguageCode> newLangCodes) {
            var gutBook = db.GutBooks.SingleOrDefault(b => b.GutBookId == doc.Id);
            if (gutBook == null) {
                gutBook = new GutBook { GutBookId = doc.Id };
                newBooks.Add(gutBook);
            }
            gutBook.Title = doc.Title;
            var gutAuthor = newAuthors.SingleOrDefault(a => a.Name == doc.Author);
            if (gutAuthor == null) gutAuthor = db.GutAuthors.SingleOrDefault(a => a.Name == doc.Author);
            if (gutAuthor == null && doc.Author != null) {
                gutAuthor = new GutAuthor { Name = doc.Author };
                newAuthors.Add(gutAuthor);
            }
            gutBook.GutAuthor = gutAuthor;

            var langCode = newLangCodes.SingleOrDefault(c => c.Code == doc.Language);
            if (langCode == null) langCode = db.LanguageCodes.SingleOrDefault(c => c.Code == doc.Language);
            if (langCode == null) {
                var langName = newLangNames.SingleOrDefault(n => n.Name == doc.Language);
                if (langName == null) newLangNames.Add(langName = new LanguageName { Name = doc.Language });
                langCode = new LanguageCode { Code = doc.Language };
                langCode.LanguageNames = new Collection<LanguageName>();
                langCode.LanguageNames.Add(langName);
                newLangCodes.Add(langCode);
            }
            gutBook.Language = doc.Language;

            var getUrl = new Func<string, string, string>((url, standard) => url != null && url != standard ? url : null);
            gutBook.EpubUrlImages = getUrl(doc.EpubUrlImages, doc.StandardEpubUrlImages);
            gutBook.StandardEpubUrlImages = doc.EpubUrlImages == doc.StandardEpubUrlImages;
            gutBook.EpubUrlNoImages = getUrl(doc.EpubUrlNoImages, doc.StandardEpubUrlNoImages);
            gutBook.StandardEpubUrlNoImages = doc.EpubUrlNoImages == doc.StandardEpubUrlNoImages;
            gutBook.ThumbnailUrl = getUrl(doc.ThumbnailUrl, doc.StandardThumbnailUrl);
            gutBook.StandardThumbnailUrl = doc.ThumbnailUrl == doc.StandardThumbnailUrl;
            gutBook.CoverUrl = getUrl(doc.CoverUrl, doc.StandardCoverUrl);
            gutBook.StandardCoverUrl = doc.CoverUrl == doc.StandardCoverUrl;
        }
Ejemplo n.º 3
0
        public GutGoogleViewModel(GutBook book, IEnumerable<GoogleBook> gbooks)
        {
            GutBookId = book.GutBookId;
            Title = book.Title;
            Author = book.GutAuthor.Name;

            Books = gbooks.Select(b => new Details(b)).ToArray();
        }