diff --git a/Lombiq.ChartJs.Samples/Controllers/SampleController.cs b/Lombiq.ChartJs.Samples/Controllers/SampleController.cs index 7a8f9b7..1b3a9e1 100644 --- a/Lombiq.ChartJs.Samples/Controllers/SampleController.cs +++ b/Lombiq.ChartJs.Samples/Controllers/SampleController.cs @@ -46,17 +46,17 @@ public SampleController( public async Task Balance() => View(new BalanceViewModel { - Labels = new[] { Labels.Balance }, - DataSets = new[] - { + Labels = [Labels.Balance], + DataSets = + [ // You can find more detailed description about dataset here: // https://www.chartjs.org/docs/2.9.4/charts/bar.html#dataset-properties new ChartJsDataSet { Label = Labels.Incomes, - BackgroundColor = new[] { ChartColors.IncomesBarChartBackgroundColor }, - Data = new double?[] - { + BackgroundColor = [ChartColors.IncomesBarChartBackgroundColor], + Data = + [ (await _session.QueryIndex( index => index.Published && @@ -68,14 +68,14 @@ public async Task Balance() => .ListAsync()) .Select(index => decimal.ToDouble(index.Numeric ?? 0m)) .Sum(), - }, + ], }, new ChartJsDataSet { Label = Labels.Expenses, - BackgroundColor = new[] { ChartColors.ExpensesBarChartBackgroundColor }, - Data = new double?[] - { + BackgroundColor = [ChartColors.ExpensesBarChartBackgroundColor], + Data = + [ (await _session.QueryIndex( index => index.Published && @@ -87,9 +87,9 @@ public async Task Balance() => .ListAsync()) .Select(index => decimal.ToDouble(index.Numeric ?? 0m)) .Sum(), - }, + ], }, - }, + ], Options = new { // These options below are to simplify UI testing. @@ -114,6 +114,8 @@ public async Task Balance() => // /Lombiq.ChartJs.Samples/Sample/History public async Task History(string incomeTag = null, string expenseTag = null) { + if (!ModelState.IsValid) return BadRequest(ModelState); + var transactions = await GetMonthlyTransactionsAsync(incomeTag, expenseTag); return View(new HistoryViewModel @@ -123,13 +125,13 @@ public async Task History(string incomeTag = null, string expense .Select(item => item.ToString("MMMM yyyy", CultureInfo.InvariantCulture)), // You can find more detailed description about dataset here: // https://www.chartjs.org/docs/2.9.4/charts/line.html#dataset-properties - DataSets = new[] - { + DataSets = + [ new ChartJsDataSet { Label = Labels.Incomes, - BackgroundColor = new[] { ChartColors.Transparent }, - BorderColor = new[] { ChartColors.IncomesLineChartBorderColor }, + BackgroundColor = [ChartColors.Transparent], + BorderColor = [ChartColors.IncomesLineChartBorderColor], Data = transactions .OrderBy(item => item.Key) .Select(item => item.Value.Income), @@ -137,13 +139,13 @@ public async Task History(string incomeTag = null, string expense new ChartJsDataSet { Label = Labels.Expenses, - BackgroundColor = new[] { ChartColors.Transparent }, - BorderColor = new[] { ChartColors.ExpensesLineChartBorderColor }, + BackgroundColor = [ChartColors.Transparent], + BorderColor = [ChartColors.ExpensesLineChartBorderColor], Data = transactions .OrderBy(item => item.Key) .Select(item => item.Value.Expense), }, - }, + ], Options = new { // These options below are to simplify UI testing. @@ -203,7 +205,7 @@ await FindDateFieldIndexesByTagsFilterAsync(incomeTag, incomeTagsFilter, expense private async Task> GetItemIdsByTermIdAsync(string taxonomyId, string termId) => string.IsNullOrEmpty(termId) - ? Array.Empty() + ? [] : (await _orchardHelper.QueryCategorizedContentItemsAsync(query => query .Where(taxIndex => taxIndex.TaxonomyContentItemId == taxonomyId) .Where(taxIndex => taxIndex.TermContentItemId == termId))) diff --git a/Lombiq.ChartJs/TagHelpers/ChartTagHelper.cs b/Lombiq.ChartJs/TagHelpers/ChartTagHelper.cs index 1e4789b..ef5e90a 100644 --- a/Lombiq.ChartJs/TagHelpers/ChartTagHelper.cs +++ b/Lombiq.ChartJs/TagHelpers/ChartTagHelper.cs @@ -1,7 +1,6 @@ using Lombiq.ChartJs.Models; using Microsoft.AspNetCore.Razor.TagHelpers; using OrchardCore.DisplayManagement; -using System; using System.Collections.Generic; using System.Threading.Tasks; @@ -17,10 +16,10 @@ public class ChartTagHelper : TagHelper public string ChartType { get; set; } = "bar"; [HtmlAttributeName("labels")] - public IEnumerable Labels { get; set; } = Array.Empty(); + public IEnumerable Labels { get; set; } = []; [HtmlAttributeName("datasets")] - public IEnumerable DataSets { get; set; } = Array.Empty(); + public IEnumerable DataSets { get; set; } = []; [HtmlAttributeName("options")] public object Options { get; set; } = new();