public void Setup(IList <BookRead> books, IGeographyProvider geographyProvider)
        {
            _geographyProvider = geographyProvider;

            BooksRead.Clear();
            foreach (BookRead book in books.OrderBy(x => x.Date))
            {
                BooksRead.Add(book);
            }

            UpdateBookDeltas();
            UpdateBookPerYearDeltas();
            UpdateAuthors();
            UpdateWorldCountryLookup();
            int  booksReadWorldwide;
            uint pagesReadWorldwide;

            UpdateCountries(out booksReadWorldwide, out pagesReadWorldwide);
            UpdateLanguages(booksReadWorldwide, pagesReadWorldwide);
            BookLocationDeltas = new ObservableCollection <BookLocationDelta>();
            UpdateBookLocationDeltas();
            UpdateBooksPerMonth();
            UpdateBookTags();
            UpdateTalliedBooks();
            SelectedMonthTally = TalliedMonths.FirstOrDefault();
            _selectedMonth     = DateTime.Now;
            if (SelectedMonthTally != null)
            {
                _selectedMonth = SelectedMonthTally.MonthDate;
            }
        }
        private TalliedMonth GetSelectedMonthTally()
        {
            var selected = _mainModel.TalliedMonths.First();

            foreach (var month in _mainModel.TalliedMonths)
            {
                if (month.MonthDate.Year == _selectedMonth.Year && month.MonthDate.Month == _selectedMonth.Month)
                {
                    selected = month;
                    break;
                }
            }
            TalliedMonths.Clear();
            TalliedMonths.Add(selected);
            OnPropertyChanged(() => TalliedMonths);
            return(selected);
        }
        private void UpdateBooksPerMonth()
        {
            // clear the list and the counts
            Dictionary <DateTime, List <BookRead> > bookMonths = new Dictionary <DateTime, List <BookRead> >();

            if (BooksRead.Count < 1)
            {
                return;
            }
            DateTime startDate = BooksRead[0].Date;
            DateTime endDate   = BooksRead.Last().Date;

            endDate = new DateTime(endDate.Year, endDate.Month, endDate.Day, 23, 59, 59);

            DateTime monthStart = new DateTime(startDate.Year, startDate.Month, 1);
            DateTime monthEnd   = monthStart.AddMonths(1).AddSeconds(-1);

            // get all the months a book has been read
            while (monthStart <= endDate)
            {
                List <BookRead> monthList = new List <BookRead>();

                foreach (BookRead book in BooksRead)
                {
                    if (book.Date >= monthStart && book.Date <= monthEnd)
                    {
                        monthList.Add(book);
                    }
                }

                if (monthList.Count > 0)
                {
                    bookMonths.Add(monthStart, monthList);
                }

                monthStart = monthStart.AddMonths(1);
                monthEnd   = monthStart.AddMonths(1).AddSeconds(-1);
            }

            TalliedMonths.Clear();
            foreach (DateTime date in bookMonths.Keys.OrderBy(x => x))
            {
                TalliedMonths.Add(new TalliedMonth(date, bookMonths[date]));
            }
        }