Exemplo n.º 1
0
        public void Filter()
        {
            var f = new ObservableCollection <Book>(AllBooks);

            if (!IsNullOrWhiteSpace(FilterQuery) && !IsNullOrEmpty(FilterQuery))
            {
                var result = f.Where(x => x.Title.ToLower().Contains(FilterQuery.ToLower()));
                f = new ObservableCollection <Book>(result);
            }
            if (FilterScraped)
            {
                var result = f.Where(x => x.Scraped);
                f = new ObservableCollection <Book>(result);
            }
            if (FilterFavourites)
            {
                var result = f.Where(x => x.Favourite);
                f = new ObservableCollection <Book>(result);
            }
            if (FilterReading)
            {
                var result = f.Where(x => x.CurrentPage != null);
                f = new ObservableCollection <Book>(result);
            }
            if (FilterDescription)
            {
                var result =
                    f.Where(
                        x =>
                        x.Abstract != null && !IsNullOrEmpty(FilterQuery) &&
                        x.Abstract.ToLower().Contains(FilterQuery.ToLower()));
                f = new ObservableCollection <Book>(result);
            }
            if (FilterBookmarks)
            {
                var result = f.Where(x => x.BookMarks != null && x.BookMarks.Count > 0);
                f = new ObservableCollection <Book>(result);
            }

            // Currently only returns results that contain ALL tags
            if (Tags != null)
            {
                foreach (var word in Tags)
                {
                    if (word.Checked)
                    {
                        var result = f.Where(x => x.Title.Split(' ').Contains(word.Word));
                        f = new ObservableCollection <Book>(result);
                    }
                }
            }


            FilteredBooks = new ObservableCollection <Book>(f);
            FilterCount   = "Found " + FilteredBooks.Count;
            NotifyPropertyChanged("FilterColor");
        }