From 9b8d0848d8fc66855b3fd6fd244781a2dbb89192 Mon Sep 17 00:00:00 2001 From: Chris Kaczor Date: Tue, 31 May 2016 16:05:26 -0400 Subject: [PATCH] Fix changes not being preserved --- Application/MainWindow/CategoryList.cs | 5 ++++- Application/MainWindow/MainWindow.xaml.cs | 11 ++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Application/MainWindow/CategoryList.cs b/Application/MainWindow/CategoryList.cs index 31c1416..ef2796b 100644 --- a/Application/MainWindow/CategoryList.cs +++ b/Application/MainWindow/CategoryList.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Windows; using System.Windows.Controls; +using FeedCenter.Properties; namespace FeedCenter { @@ -78,7 +79,7 @@ namespace FeedCenter _currentCategory = category; // Get the current feed list to match the category - _feedList = _currentCategory?.Feeds.ToList() ?? _database.Feeds.ToList(); + _feedList = _currentCategory == null ? _database.Feeds : _database.Feeds.Where(feed => feed.Category.ID == _currentCategory.ID); // Reset the feed index _feedIndex = -1; @@ -92,6 +93,8 @@ namespace FeedCenter // Update the display DisplayCategory(); DisplayFeed(); + + Settings.Default.LastCategoryID = _currentCategory?.ID.ToString() ?? string.Empty; } } } diff --git a/Application/MainWindow/MainWindow.xaml.cs b/Application/MainWindow/MainWindow.xaml.cs index 5c57187..21d3e0e 100644 --- a/Application/MainWindow/MainWindow.xaml.cs +++ b/Application/MainWindow/MainWindow.xaml.cs @@ -4,7 +4,6 @@ using Common.IO; using Common.Update; using FeedCenter.Properties; using System; -using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Windows; @@ -19,7 +18,7 @@ namespace FeedCenter private int _feedIndex; private Category _currentCategory; - private ICollection _feedList; + private IQueryable _feedList; private Feed _currentFeed; public MainWindow() @@ -120,7 +119,7 @@ namespace FeedCenter private void UpdateToolbarButtonState() { // Cache the feed count to save (a little) time - var feedCount = _feedList?.Count ?? 0; + var feedCount = _feedList?.Count() ?? 0; // Set button states PreviousToolbarButton.IsEnabled = (feedCount > 1); @@ -141,7 +140,7 @@ namespace FeedCenter DisplayCategory(); // Get the current feed list to match the category - _feedList = _currentCategory?.Feeds.ToList() ?? _database.Feeds.ToList(); + _feedList = _currentCategory == null ? _database.Feeds : _database.Feeds.Where(feed => feed.Category.ID == _currentCategory.ID); UpdateToolbarButtonState(); @@ -155,7 +154,7 @@ namespace FeedCenter StartTimer(); // Don't go further if we have no feeds - if (_feedList.Count == 0) + if (!_feedList.Any()) return; // Get the first feed @@ -364,6 +363,8 @@ namespace FeedCenter // Create a new database object _database = new FeedCenterEntities(); + _feedList = _currentCategory == null ? _database.Feeds : _database.Feeds.Where(feed => feed.Category.ID == _currentCategory.ID); + UpdateToolbarButtonState(); // Get a list of feeds ordered by name