Exemplo n.º 1
0
 public BookTally(TalliedBook talliedBook)
 {
     Book             = new Book(talliedBook.Book);
     Date             = talliedBook.Date;
     Author           = talliedBook.Author;
     Title            = talliedBook.Title;
     Pages            = (int)talliedBook.Pages;
     TotalBooks       = (int)talliedBook.TotalBooks;
     TotalBookFormat  = (int)talliedBook.TotalBookFormat;
     TotalComicFormat = (int)talliedBook.TotalComicFormat;
     TotalAudioFormat = (int)talliedBook.TotalAudioFormat;
     TotalPagesRead   = (int)talliedBook.TotalPagesRead;
 }
        private void UpdateTalliedBooks()
        {
            // clear the list and the counts
            TalliedBooks.Clear();
            UInt32 totalBooks       = 0;
            UInt32 totalPagesRead   = 0;
            UInt32 totalBookFormat  = 0;
            UInt32 totalComicFormat = 0;
            UInt32 totalAudioFormat = 0;

            // The assumption is the books arrive in order (as they do)
            List <TalliedBook> booksTally = new List <TalliedBook>();

            foreach (var book in BooksRead)
            {
                totalBooks++;
                totalPagesRead += book.Pages;
                if (book.Format == BookFormat.Book)
                {
                    totalBookFormat++;
                }
                if (book.Format == BookFormat.Comic)
                {
                    totalComicFormat++;
                }
                if (book.Format == BookFormat.Audio)
                {
                    totalAudioFormat++;
                }

                TalliedBook tally = new TalliedBook(book)
                {
                    TotalBooks       = totalBooks,
                    TotalAudioFormat = totalAudioFormat,
                    TotalBookFormat  = totalBookFormat,
                    TotalComicFormat = totalComicFormat,
                    TotalPagesRead   = totalPagesRead
                };

                booksTally.Add(tally);
            }

            // finally need to sort them into date descending
            var sortedTallies =
                (from item in booksTally orderby item.TotalBooks descending select item);

            foreach (var tallied in sortedTallies)
            {
                TalliedBooks.Add(tallied);
            }
        }