|
150 | 150 |
|
151 | 151 | _moodCategory ??= await db.Categories.SingleOrDefaultAsync(x => x.Guid == new Guid("D90D89FB-F5B9-47CF-AE4E-3EC0D635E783")); |
152 | 152 |
|
153 | | - if (_moodCategory == null) |
| 153 | + var moodPoints = new Dictionary<DateOnly, DataPoint>(); |
| 154 | + if (_moodCategory == null || !_moodCategory.Enabled) |
154 | 155 | { |
155 | | - logger.LogError($"Mood category doesn't exist so we can't load the year."); |
156 | | - return; |
| 156 | + logger.LogError("Mood category doesn't exist or is disabled so we won't load any points."); |
| 157 | + } |
| 158 | + else |
| 159 | + { |
| 160 | + var query = db.Points |
| 161 | + .Where(p => !p.Deleted && p.Day.Date.Year == SelectedYear && p.Day.Date <= tomorrow && p.Category.Guid == _moodCategory.Guid) |
| 162 | + .Select( |
| 163 | + p => new |
| 164 | + { |
| 165 | + Date = p.Day.Date, |
| 166 | + Point = p, |
| 167 | + } |
| 168 | + ); |
| 169 | + |
| 170 | + // Sort into dictionary here instead of during the query so we can handle |
| 171 | + // duplicate dates, if that has erroneously happened, without crashing. |
| 172 | + foreach (var x in query) |
| 173 | + moodPoints[x.Date] = x.Point; |
| 174 | + |
| 175 | + logger.LogDebug($"Found {moodPoints.Count} mood points"); |
157 | 176 | } |
158 | | - |
159 | | - var query = db.Points |
160 | | - .Where(p => !p.Deleted && p.Day.Date.Year == SelectedYear && p.Day.Date <= tomorrow && p.Category.Guid == _moodCategory.Guid) |
161 | | - .Select( |
162 | | - p => new |
163 | | - { |
164 | | - Date = p.Day.Date, |
165 | | - Point = p, |
166 | | - } |
167 | | - ); |
168 | | - |
169 | | - // Sort into dictionary here instead of during the query so we can handle |
170 | | - // duplicate dates, if that has erroneously happened, without crashing. |
171 | | - var moodPoints = new Dictionary<DateOnly, DataPoint>(); |
172 | | - foreach (var x in query) |
173 | | - moodPoints[x.Date] = x.Point; |
174 | | - |
175 | | - logger.LogDebug($"Found {moodPoints.Count} mood points"); |
176 | 177 |
|
177 | 178 | _gridYear = new GridYear(SelectedYear, System.Globalization.CultureInfo.CurrentCulture, moodPoints); |
178 | 179 | logger.LogDebug("Created grid year"); |
|
0 commit comments