コード例 #1
0
ファイル: MemberController.cs プロジェクト: MJBackes/BookSite
        private List <Book> GetRelatedBooks(Book book)
        {
            List <Collection> collections = db.CollectionBooks.Include("Collection")
                                            .Where(cb => cb.BookId == book.Id)
                                            .Select(cb => cb.Collection)
                                            .ToList();
            List <Book> books = new List <Book>();

            foreach (Collection c in collections)
            {
                books = books.Concat(db.CollectionBooks.Include("Book")
                                     .Where(cb => cb.CollectionId == c.Id && cb.Book.Thumbnail != null)
                                     .Select(cb => cb.Book))
                        .ToList();
            }
            books = books.GroupBy(b => b.GoogleVolumeId, (googleId, Books) => new
            {
                Key   = googleId,
                Count = Books.Count(),
                Value = Books.FirstOrDefault()
            }).OrderByDescending(g => g.Count)
                    .Select(g => g.Value)
                    .Take(6)
                    .ToList();
            books.Remove(book);
            return(books);
        }
コード例 #2
0
ファイル: ClubController.cs プロジェクト: MJBackes/BookSite
        private void AddBooksToClubIndexViewModel(ClubIndexViewModel viewModel)
        {
            List <Book> books = GetBooksForClubIndexViewModel(viewModel.Members);

            viewModel.Books = books.GroupBy(b => b.GoogleVolumeId, (googleId, Books) => new {
                Count = Books.Count(),
                Key   = googleId,
                Value = Books.FirstOrDefault()
            }).OrderByDescending(g => g.Count).Select(g => g.Value).ToList();
        }
コード例 #3
0
        public override string ToString()
        {
            StringBuilder RetVal = new StringBuilder();

            RetVal.AppendLine(TextBox.BuildDynamic($"Repository {Name}, location={RootPath}"));
            RetVal.AppendLine($"Found {Books.Count()} books");
            RetVal.AppendLine($"Found {CollectionCount} different collections");
            RetVal.AppendLine($"{CollectionLessCount} books have no collection assigned");
            return(RetVal.ToString());
        }
コード例 #4
0
 public List <Book> getBooks(int from, int to)
 {
     if (from < 0 || from >= Books.Count())
     {
         from = 0;
     }
     if (to < 0 || to >= Books.Count())
     {
         to = Books.Count() - 1;
     }
     return(Books.ToList().Skip(from)
            .Take(to - from + 1).ToList());
 }
コード例 #5
0
        public string GetPurchaseLink(Book item)
        {
            item.CheckNotNull(nameof(item));

            if (string.IsNullOrEmpty(item.Url) || Books.Count() > 3)
            {
                return("");
            }
            else
            {
                return("<a href='{0}' target='_blank'>{1}</a>".FormatInvariant(
                           item.Url,
                           (item.Url.StartsWith("http://amzn.to", StringComparison.InvariantCultureIgnoreCase) || item.Url.Contains("amazon", StringComparison.InvariantCultureIgnoreCase)) ? "View on Amazon" : "View"));
            }
        }
コード例 #6
0
ファイル: MemberController.cs プロジェクト: MJBackes/BookSite
        private List <Book> GetFriendsBooks(List <Member> friends, List <Book> myBooks)
        {
            List <Guid> friendIds = friends.Select(m => m.Id).ToList();
            List <Guid> myBookIds = myBooks.Select(b => b.Id).ToList();

            return(db.CollectionBooks.Include("Collection")
                   .Include("Book")
                   .Where(cb => friendIds.Contains(cb.Collection.MemberId))
                   .Select(cb => cb.Book)
                   .GroupBy(b => b.GoogleVolumeId, (googleId, Books) => new {
                Key = googleId,
                Count = Books.Count(),
                Value = Books.FirstOrDefault()
            })
                   .OrderByDescending(g => g.Count)
                   .Select(g => g.Value)
                   .AsEnumerable()
                   .SkipWhile(b => myBookIds.Contains(b.Id))
                   .Take(5)
                   .ToList());
        }
コード例 #7
0
        private List <Book> GetRelatedBooks(Book book)
        {
            List <Guid> collectionIds = db.CollectionBooks.Include("Collection")
                                        .Where(cb => cb.BookId == book.Id)
                                        .Select(cb => cb.Collection.Id)
                                        .ToList();

            return(db.CollectionBooks.Include("Book")
                   .Where(cb => collectionIds.Contains(cb.CollectionId))
                   .Select(cb => cb.Book)
                   .GroupBy(b => b.GoogleVolumeId, (googleId, Books) => new
            {
                Key = googleId,
                Count = Books.Count(),
                Value = Books.FirstOrDefault()
            }).OrderByDescending(g => g.Count)
                   .Select(g => g.Value)
                   .AsEnumerable()
                   .SkipWhile(b => b.Id == book.Id)
                   .Take(5)
                   .ToList());
        }
コード例 #8
0
 public void OnGet(int authorId)
 {
     Author        = catalog.GetAuthorById(authorId);
     Books         = catalog.GetBooksByAuthor(authorId);
     NumberOfBooks = Books.Count();
 }
コード例 #9
0
 public Book AddBook(Book book)
 {
     book.Id = Books.Count() == 0 ? "1" : (Books.Max(b => Convert.ToInt32(b.Id)) + 1).ToString();
     Books.Add(book);
     return(book);
 }
コード例 #10
0
        private void grdmain_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Left)
            {
                //check # of chapters in book
                //if last chapter get next book
                //back one chapter

                var prevChapter = (CurrentVerseSelection.curr.chapter - 1);
                if (prevChapter >= 1)
                {
                    GoTo(CurrentVerseSelection.curr.book, prevChapter, 1);
                }
                else
                {
                    var bookIndex = Books.FindIndex(x => x.abbrev == CurrentVerseSelection.curr.book) - 1;
                    if (bookIndex >= 0)
                    {
                        var prevBook = Books[bookIndex];
                        GoTo(prevBook.abbrev, 1, 1);
                    }
                }
            }
            if (e.Key == Key.Right)
            {
                var nextChapter = (CurrentVerseSelection.curr.chapter + 1);
                if (nextChapter <= Chapters.Count())
                {
                    GoTo(CurrentVerseSelection.curr.book, nextChapter, 1);
                }
                else
                {
                    var bookIndex = Books.FindIndex(x => x.abbrev == CurrentVerseSelection.curr.book) + 1;
                    if (bookIndex <= Books.Count())
                    {
                        var nextBook = Books[bookIndex];
                        GoTo(nextBook.abbrev, 1, 1);
                    }
                }
            }
            if (e.Key == Key.Up)
            {
                // back one verse
                if (CurrentVerseSelection.prev == null)
                {
                    return;
                }
                GoTo(CurrentVerseSelection.curr.book, CurrentVerseSelection.curr.chapter, CurrentVerseSelection.prev.verse);
                SelectedChapter = CurrentVerseSelection.curr.chapter;
                SelectedVerse   = CurrentVerseSelection.curr.verse;
            }
            if (e.Key == Key.Down)
            {
                if (CurrentVerseSelection.next == null)
                {
                    return;
                }
                GoTo(CurrentVerseSelection.curr.book, CurrentVerseSelection.curr.chapter, CurrentVerseSelection.next.verse);

                SelectedChapter = CurrentVerseSelection.curr.chapter;
                SelectedVerse   = CurrentVerseSelection.curr.verse;
            }
        }
コード例 #11
0
 public void AddBook(Book book)
 {
     book.Id = Books.Count() == 0 ? 1 : Books.Max(b => b.Id) + 1;
     Books.Add(book);
 }