From 5764e68ff12c4968aed4bc38fd2c817f7daf1620 Mon Sep 17 00:00:00 2001 From: Gianluigi Liguori Date: Mon, 26 Aug 2024 12:40:27 +0200 Subject: [PATCH] Resolve null warnings --- .../ApiKeyAuthenticationBuilder.cs | 4 +-- .../MaterializedMoneyItemsController.cs | 26 ++++++++++++---- .../RecurrencyAdjustementsController.cs | 2 +- .../RecurrentMoneyItemsController.cs | 2 +- .../Controllers/SavingsController.cs | 4 +-- src/Savings.API/Program.cs | 2 +- src/Savings.API/Savings.API.csproj | 1 + .../Services/ProjectionCalculator.cs | 30 +++++++++---------- .../CustomAuthorizationMessageHandler.cs | 2 +- .../Components/InputSelectNumber.cs | 14 ++++----- .../Pages/ConfigurationEdit.razor.cs | 6 ++-- src/Savings.SPA/Pages/FixedItemEdit.razor.cs | 18 +++++------ src/Savings.SPA/Pages/FixedItems.razor | 2 +- src/Savings.SPA/Pages/FixedItems.razor.cs | 17 +++++------ src/Savings.SPA/Pages/History.razor.cs | 6 ++-- src/Savings.SPA/Pages/Projection.razor.cs | 18 +++++------ .../Pages/RecurrencyAdjustment.razor.cs | 8 ++--- .../Pages/RecurrentItemEdit.razor.cs | 18 +++++------ src/Savings.SPA/Pages/RecurrentItems.razor.cs | 22 +++++++------- src/Savings.SPA/Pages/Reports.razor.cs | 22 +++++++------- src/Savings.SPA/Pages/ReportsDetail.razor.cs | 10 +++---- src/Savings.SPA/Program.cs | 4 +-- src/Savings.SPA/Shared/NavMenu.razor | 2 +- 23 files changed, 122 insertions(+), 118 deletions(-) diff --git a/src/Savings.API/Authentication/ApiKeyAuthenticationBuilder.cs b/src/Savings.API/Authentication/ApiKeyAuthenticationBuilder.cs index 0788dd3..32f9d78 100644 --- a/src/Savings.API/Authentication/ApiKeyAuthenticationBuilder.cs +++ b/src/Savings.API/Authentication/ApiKeyAuthenticationBuilder.cs @@ -28,8 +28,8 @@ public class ApiKeyAuthOptions : AuthenticationSchemeOptions public class CustomAuthHandler : AuthenticationHandler { - public CustomAuthHandler(IOptionsMonitor options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock) - : base(options, logger, encoder, clock) + public CustomAuthHandler(IOptionsMonitor options, ILoggerFactory logger, UrlEncoder encoder) + : base(options, logger, encoder) { } diff --git a/src/Savings.API/Controllers/MaterializedMoneyItemsController.cs b/src/Savings.API/Controllers/MaterializedMoneyItemsController.cs index df185f6..0373159 100644 --- a/src/Savings.API/Controllers/MaterializedMoneyItemsController.cs +++ b/src/Savings.API/Controllers/MaterializedMoneyItemsController.cs @@ -20,11 +20,18 @@ public MaterializedMoneyItemsController(SavingsContext context) public async Task PostLastMaterializedMoneyItemPeriod(DateTime date, decimal amount) { var res = await _context.MaterializedMoneyItems.Where(x => x.EndPeriod).OrderByDescending(x => x.Date).FirstOrDefaultAsync(); - res.Date = date; - res.Amount = amount; - res.Projection = amount; - await _context.SaveChangesAsync(); - return Ok(); + if (res != null) + { + res.Date = date; + res.Amount = amount; + res.Projection = amount; + await _context.SaveChangesAsync(); + return Ok(); + } + else + { + return NotFound(); + } } @@ -33,7 +40,14 @@ public async Task PostLastMaterializedMoneyItemPeriod(DateTime dat public async Task> GetLastMaterializedMoneyItemPeriod() { var res = await _context.MaterializedMoneyItems.Where(x => x.EndPeriod).OrderByDescending(x => x.Date).FirstOrDefaultAsync(); - return res; + if(res == null) + { + return NotFound(); + } + else + { + return res; + } } // GET: api/MaterializedMoneyItems diff --git a/src/Savings.API/Controllers/RecurrencyAdjustementsController.cs b/src/Savings.API/Controllers/RecurrencyAdjustementsController.cs index 35bf5d7..ea21d3a 100644 --- a/src/Savings.API/Controllers/RecurrencyAdjustementsController.cs +++ b/src/Savings.API/Controllers/RecurrencyAdjustementsController.cs @@ -31,7 +31,7 @@ public async Task>> GetRecurrenc // GET: api/RecurrencyAdjustements/ByIDRecurrencyAndDate [HttpGet("ByIDRecurrencyAndDate", Name = "ByIDRecurrencyAndDate")] - public async Task> GetByIDRecurrency(long idRecurrency, DateTime date) + public async Task> GetByIDRecurrency(long idRecurrency, DateTime date) { return await _context.RecurrencyAdjustements.Where(x => x.RecurrentMoneyItemID == idRecurrency && (x.RecurrencyNewDate.HasValue && x.RecurrencyNewDate == date.Date || !x.RecurrencyNewDate.HasValue && x.RecurrencyDate == date.Date)).FirstOrDefaultAsync(); } diff --git a/src/Savings.API/Controllers/RecurrentMoneyItemsController.cs b/src/Savings.API/Controllers/RecurrentMoneyItemsController.cs index 7cf232b..0698f61 100644 --- a/src/Savings.API/Controllers/RecurrentMoneyItemsController.cs +++ b/src/Savings.API/Controllers/RecurrentMoneyItemsController.cs @@ -109,7 +109,7 @@ public async Task> InsertCreditFixedMoneyItem(F DateTime targetDate = DateTime.Now.AddMonths(1); targetDate = new DateTime(targetDate.Year, targetDate.Month, defaultCreditMoneyItem.StartDate.Day); - var recurrentMoneyItem = new RecurrentMoneyItem { CategoryID = fixedItem.CategoryID, Amount = fixedItem.Amount.Value, Note = fixedItem.Note, RecurrentMoneyItemID = defaultCreditMoneyItem.ID, StartDate = targetDate, EndDate = targetDate }; + var recurrentMoneyItem = new RecurrentMoneyItem { CategoryID = fixedItem.CategoryID, Amount = fixedItem.Amount!.Value, Note = fixedItem.Note, RecurrentMoneyItemID = defaultCreditMoneyItem.ID, StartDate = targetDate, EndDate = targetDate }; _context.RecurrentMoneyItems.Add(recurrentMoneyItem); await _context.SaveChangesAsync(); diff --git a/src/Savings.API/Controllers/SavingsController.cs b/src/Savings.API/Controllers/SavingsController.cs index 805e53b..a762d4c 100644 --- a/src/Savings.API/Controllers/SavingsController.cs +++ b/src/Savings.API/Controllers/SavingsController.cs @@ -38,11 +38,11 @@ public async Task PostSavingsToHistory(DateTime date) public async Task GetBackup() { byte[] fileContent; - using (var fs = new FileStream(configuration["DatabasePath"], FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + using (var fs = new FileStream(configuration["DatabasePath"]!, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (var ms = new MemoryStream()) { - fs.CopyTo(ms); + await fs.CopyToAsync(ms); fileContent = ms.ToArray(); } } diff --git a/src/Savings.API/Program.cs b/src/Savings.API/Program.cs index 9214fed..592cdb5 100644 --- a/src/Savings.API/Program.cs +++ b/src/Savings.API/Program.cs @@ -41,7 +41,7 @@ options.DefaultAuthenticateScheme = ApiKeyAuthOptions.ApiKeySchemaName; options.DefaultChallengeScheme = ApiKeyAuthOptions.ApiKeySchemaName; }) - .AddApiKeyAuth(options => options.AuthKeys = builder.Configuration[ApiKeys].Split(",")); + .AddApiKeyAuth(options => options.AuthKeys = builder.Configuration[ApiKeys]?.Split(",")); } builder.Services.AddTransient(); diff --git a/src/Savings.API/Savings.API.csproj b/src/Savings.API/Savings.API.csproj index ce62db4..f0ab6e3 100644 --- a/src/Savings.API/Savings.API.csproj +++ b/src/Savings.API/Savings.API.csproj @@ -2,6 +2,7 @@ net8.0 + enable enable diff --git a/src/Savings.API/Services/ProjectionCalculator.cs b/src/Savings.API/Services/ProjectionCalculator.cs index ad971fe..1fdeec9 100644 --- a/src/Savings.API/Services/ProjectionCalculator.cs +++ b/src/Savings.API/Services/ProjectionCalculator.cs @@ -111,7 +111,7 @@ public async Task> CalculateAsync(DateTime? f var recurrentItems = await context.RecurrentMoneyItems .Include(x => x.Adjustements).Include(x => x.AssociatedItems).Include(x => x.Category) .Where(x => (x.StartDate <= periodEnd && (!x.EndDate.HasValue || periodStart <= x.EndDate) && x.RecurrentMoneyItemID == null) || - (x.Adjustements.Count() > 0 && x.Adjustements.First().RecurrencyNewDate.HasValue && x.Adjustements.First().RecurrencyNewDate.Value >= periodStart && x.Adjustements.First().RecurrencyNewDate.Value <= periodEnd)) + (x.Adjustements.Count() > 0 && x.Adjustements.First().RecurrencyNewDate.HasValue && x.Adjustements.First().RecurrencyNewDate!.Value >= periodStart && x.Adjustements.First().RecurrencyNewDate!.Value <= periodEnd)) .AsNoTracking().ToListAsync(); if (onlyInstallment) recurrentItems = recurrentItems.Where(x => x.Type == MoneyType.InstallmentPayment).ToList(); @@ -131,14 +131,14 @@ public async Task> CalculateAsync(DateTime? f { Date = fixedItem.Date, CategoryID = fixedItem?.Category?.ID, - Amount = fixedItem.Amount ?? 0, + Amount = fixedItem?.Amount ?? 0, EndPeriod = false, - Note = fixedItem.Note, + Note = fixedItem?.Note, Type = MoneyType.Others, - TimelineWeight = fixedItem.TimelineWeight, + TimelineWeight = fixedItem?.TimelineWeight ?? 0, IsRecurrent = false, - FixedMoneyItemID = fixedItem.ID, - Cash = fixedItem.Cash + FixedMoneyItemID = fixedItem?.ID, + Cash = fixedItem?.Cash ?? false }); } @@ -169,13 +169,13 @@ public async Task> CalculateAsync(DateTime? f foreach (var installment in installments) { //Check the adjustements - var currentAdjustment = recurrentItem.Adjustements?.Where(x => x.RecurrencyDate == installment.currentDate || x.RecurrencyNewDate.HasValue && x.RecurrencyNewDate == installment.currentDate).FirstOrDefault(); + var currentAdjustment = recurrentItem?.Adjustements?.Where(x => x.RecurrencyDate == installment.currentDate || x.RecurrencyNewDate.HasValue && x.RecurrencyNewDate == installment.currentDate).FirstOrDefault(); var currentInstallmentDate = currentAdjustment?.RecurrencyNewDate ?? installment.original; - var currentInstallmentAmount = currentAdjustment?.RecurrencyNewAmount ?? recurrentItem.Amount; - var currentInstallmentNote = recurrentItem.Note; + var currentInstallmentAmount = currentAdjustment?.RecurrencyNewAmount ?? recurrentItem!.Amount; + var currentInstallmentNote = recurrentItem?.Note; //Check if is a budget for subtract the accumulated - if (recurrentItem.Type == MoneyType.PeriodicBudget) + if (recurrentItem!.Type == MoneyType.PeriodicBudget) { decimal accumulatorToSubtract = accumulatedForBudgetLeft < currentInstallmentAmount ? currentInstallmentAmount : accumulatedForBudgetLeft; accumulatedForBudgetLeft -= accumulatorToSubtract; @@ -216,10 +216,10 @@ public async Task> CalculateAsync(DateTime? f Amount = currentInstallmentAmount, EndPeriod = false, Note = currentInstallmentNote, - Type = recurrentItem.Type, - TimelineWeight = recurrentItem.TimelineWeight, + Type = recurrentItem?.Type ?? MoneyType.Others, + TimelineWeight = recurrentItem?.TimelineWeight ?? 0, IsRecurrent = true, - RecurrentMoneyItemID = recurrentItem.ID, + RecurrentMoneyItemID = recurrentItem?.ID, Subitems = lstSubItemsRecurrent }); } @@ -232,7 +232,7 @@ public async Task> CalculateAsync(DateTime? f periodStart = periodEnd.AddDays(1); } //Calculate the projection - var lastProjectionValue = context.MaterializedMoneyItems.Where(x => x.Date <= fromDate).OrderByDescending(x => x.Date).ThenByDescending(x => x.EndPeriod).AsNoTracking().FirstOrDefault().Projection; + var lastProjectionValue = context.MaterializedMoneyItems.Where(x => x.Date <= fromDate).OrderByDescending(x => x.Date).ThenByDescending(x => x.EndPeriod).AsNoTracking().FirstOrDefault()!.Projection; res = res.OrderBy(x => x.Date).ThenByDescending(x => x.TimelineWeight).ToList(); foreach (var resItem in res) { @@ -266,7 +266,7 @@ private static DateTime CalculateActualInstallmentDate(RecurrentMoneyItem item, DateTime currentInstallmentDate; var adjustment = item.Adjustements?.Where(x => x.RecurrencyDate == currentInstallmentOriginal && x.RecurrencyNewDate.HasValue).FirstOrDefault(); if (adjustment != null) - currentInstallmentDate = adjustment.RecurrencyNewDate.Value; + currentInstallmentDate = adjustment.RecurrencyNewDate!.Value; else currentInstallmentDate = currentInstallmentOriginal; return currentInstallmentDate; diff --git a/src/Savings.SPA/Authorization/CustomAuthorizationMessageHandler.cs b/src/Savings.SPA/Authorization/CustomAuthorizationMessageHandler.cs index b2488e1..bafc18c 100644 --- a/src/Savings.SPA/Authorization/CustomAuthorizationMessageHandler.cs +++ b/src/Savings.SPA/Authorization/CustomAuthorizationMessageHandler.cs @@ -10,7 +10,7 @@ public CustomAuthorizationMessageHandler(IConfiguration configuration, IAccessTo : base(provider, navigationManager) { ConfigureHandler( - authorizedUrls: new[] { configuration["SavingsApiServiceUrl"] }); + authorizedUrls: new[] { configuration["SavingsApiServiceUrl"] ?? throw new ArgumentNullException("SavingsApiServiceUrl") }); } } } \ No newline at end of file diff --git a/src/Savings.SPA/Components/InputSelectNumber.cs b/src/Savings.SPA/Components/InputSelectNumber.cs index 2d25d40..a8cb2c1 100644 --- a/src/Savings.SPA/Components/InputSelectNumber.cs +++ b/src/Savings.SPA/Components/InputSelectNumber.cs @@ -1,39 +1,35 @@ using Microsoft.AspNetCore.Components.Forms; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace Savings.SPA.Components { public class InputSelectNumber : InputSelect { - protected override bool TryParseValueFromString(string value, out T result, out string validationErrorMessage) + protected override bool TryParseValueFromString(string? value, out T result, out string validationErrorMessage) { if (typeof(T) == typeof(int) || typeof(T) == typeof(long?)) { if (typeof(T) == typeof(int) && int.TryParse(value, out var resultInt)) { result = (T)(object)resultInt; - validationErrorMessage = null; + validationErrorMessage = string.Empty; return true; } else if (typeof(T) == typeof(long?) && long.TryParse(value, out var resultLong)) { result = (T)(object)resultLong; - validationErrorMessage = null; + validationErrorMessage = string.Empty; return true; } else { - result = default; + result = default!; validationErrorMessage = "The chosen value is not a valid number."; return false; } } else { - return base.TryParseValueFromString(value, out result, out validationErrorMessage); + return base.TryParseValueFromString(value, out result!, out validationErrorMessage!); } } } diff --git a/src/Savings.SPA/Pages/ConfigurationEdit.razor.cs b/src/Savings.SPA/Pages/ConfigurationEdit.razor.cs index df06ea5..ef606af 100644 --- a/src/Savings.SPA/Pages/ConfigurationEdit.razor.cs +++ b/src/Savings.SPA/Pages/ConfigurationEdit.razor.cs @@ -8,11 +8,11 @@ public partial class ConfigurationEdit : ComponentBase { [Inject] - private ISavingsApi savingsAPI { get; set; } + private ISavingsApi savingsAPI { get; set; } = default!; - private Configuration Configuration { get; set; } + private Configuration Configuration { get; set; } = default!; - public MoneyCategory[] Categories { get; set; } + public MoneyCategory[] Categories { get; set; } = default!; public DateTime LastMaterializedDate { get; set; } diff --git a/src/Savings.SPA/Pages/FixedItemEdit.razor.cs b/src/Savings.SPA/Pages/FixedItemEdit.razor.cs index fd8163f..d99da44 100644 --- a/src/Savings.SPA/Pages/FixedItemEdit.razor.cs +++ b/src/Savings.SPA/Pages/FixedItemEdit.razor.cs @@ -10,16 +10,16 @@ public partial class FixedItemEdit : ComponentBase { [Inject] - public ISavingsApi savingsAPI { get; set; } + public ISavingsApi savingsAPI { get; set; } = default!; [Inject] - DialogService dialogService { get; set; } + DialogService dialogService { get; set; } = default!; [Inject] - public NotificationService notificationService { get; set; } + public NotificationService notificationService { get; set; } = default!; [Parameter] - public FixedMoneyItem fixedItemToEdit { get; set; } + public FixedMoneyItem fixedItemToEdit { get; set; } = default!; public bool Incoming { get; set; } @@ -30,9 +30,9 @@ public partial class FixedItemEdit : ComponentBase public bool OperationRunning { get; set; } = false; - public MoneyCategory[] Categories { get; set; } + public MoneyCategory[]? Categories { get; set; } - InputNumber amountInputNumber; + InputNumber? amountInputNumber; protected override void OnInitialized() { @@ -49,7 +49,7 @@ protected override async void OnAfterRender(bool firstRender) if (firstRender) { await Task.Delay(500); - await amountInputNumber.Element.Value.FocusAsync(); + await amountInputNumber!.Element!.Value.FocusAsync(); } } @@ -105,11 +105,11 @@ private async void OnValidSubmit() if (!ValidateData()) return; if (Incoming) { - fixedItemToEdit.Amount = Math.Abs(fixedItemToEdit.Amount.Value); + fixedItemToEdit.Amount = Math.Abs(fixedItemToEdit.Amount!.Value); } else { - fixedItemToEdit.Amount = -Math.Abs(fixedItemToEdit.Amount.Value); + fixedItemToEdit.Amount = -Math.Abs(fixedItemToEdit.Amount!.Value); } if (isNew) { diff --git a/src/Savings.SPA/Pages/FixedItems.razor b/src/Savings.SPA/Pages/FixedItems.razor index e50fbc3..c4d1f00 100644 --- a/src/Savings.SPA/Pages/FixedItems.razor +++ b/src/Savings.SPA/Pages/FixedItems.razor @@ -76,7 +76,7 @@ else @item.Date.ToString("dd/MM/yyyy") @((item.Amount ?? 0).ToString("N2")) @item?.Category?.Icon?.ToString() @item?.Category?.Description?.ToString() - @item.Note + @item?.Note } diff --git a/src/Savings.SPA/Pages/FixedItems.razor.cs b/src/Savings.SPA/Pages/FixedItems.razor.cs index 6e079f2..6e0db5c 100644 --- a/src/Savings.SPA/Pages/FixedItems.razor.cs +++ b/src/Savings.SPA/Pages/FixedItems.razor.cs @@ -2,9 +2,6 @@ using Radzen; using Savings.Model; using Savings.SPA.Services; -using System; -using System.Collections.Generic; -using System.Threading.Tasks; namespace Savings.SPA.Pages { @@ -12,14 +9,14 @@ public partial class FixedItems : ComponentBase { [Inject] - public ISavingsApi savingsAPI { get; set; } + public ISavingsApi savingsAPI { get; set; } = default!; [Inject] - public DialogService dialogService { get; set; } + public DialogService dialogService { get; set; } = default!; - public Configuration CurrentConfiguration { get; set; } + public Configuration CurrentConfiguration { get; set; } = default!; - private FixedMoneyItem[] fixedMoneyItems; + private FixedMoneyItem[] fixedMoneyItems = default!; public DateTime? FilterDateFrom { get; set; } @@ -27,14 +24,14 @@ public partial class FixedItems : ComponentBase public long? FilterCategory { get; set; } - public MoneyCategory[] Categories { get; set; } + public MoneyCategory[] Categories { get; set; } = default!; protected override async Task OnInitializedAsync() { FilterDateFrom = DateTime.Now.Date.AddMonths(-2); FilterDateTo = DateTime.Now.Date.AddDays(15); Categories = await savingsAPI.GetMoneyCategories(); - CurrentConfiguration = (await savingsAPI.GetConfigurations()).FirstOrDefault(); + CurrentConfiguration = (await savingsAPI.GetConfigurations()).First(); await InitializeList(); } @@ -46,7 +43,7 @@ async void Change(DateTime? value, string name) async Task FilterCategoryChanged(ChangeEventArgs e) { - var selectedString = e.Value.ToString(); + var selectedString = e.Value?.ToString(); FilterCategory = string.IsNullOrWhiteSpace(selectedString) ? null : long.Parse(selectedString); await InitializeList(); diff --git a/src/Savings.SPA/Pages/History.razor.cs b/src/Savings.SPA/Pages/History.razor.cs index 6e7d667..22302d8 100644 --- a/src/Savings.SPA/Pages/History.razor.cs +++ b/src/Savings.SPA/Pages/History.razor.cs @@ -9,12 +9,12 @@ public partial class History : ComponentBase { [Inject] - public ISavingsApi savingsAPI { get; set; } + public ISavingsApi savingsAPI { get; set; } = default!; - private MaterializedMoneyItem[] materializedMoneyItems; + private MaterializedMoneyItem[]? materializedMoneyItems; [Inject] - public DialogService dialogService { get; set; } + public DialogService dialogService { get; set; } = default!; public DateTime? FilterDateFrom { get; set; } public DateTime? FilterDateTo { get; set; } diff --git a/src/Savings.SPA/Pages/Projection.razor.cs b/src/Savings.SPA/Pages/Projection.razor.cs index e9ebfd9..10cf0af 100644 --- a/src/Savings.SPA/Pages/Projection.razor.cs +++ b/src/Savings.SPA/Pages/Projection.razor.cs @@ -1,23 +1,19 @@ using Microsoft.AspNetCore.Components; +using Radzen; using Savings.Model; using Savings.SPA.Services; -using System; -using System.Threading.Tasks; -using Radzen; -using System.Collections.Generic; -using Microsoft.AspNetCore.Components.WebAssembly.Authentication; namespace Savings.SPA.Pages { public partial class Projection : ComponentBase { [Inject] - public ISavingsApi savingsAPI { get; set; } + public ISavingsApi savingsAPI { get; set; } = default!; - private MaterializedMoneyItem[] materializedMoneyItems; + private MaterializedMoneyItem[] materializedMoneyItems = default!; [Inject] - public DialogService dialogService { get; set; } + public DialogService dialogService { get; set; } = default!; public bool ShowPastItems { get; set; } = false; @@ -25,13 +21,13 @@ public partial class Projection : ComponentBase public DateTime? FilterDateTo { get; set; } - public Configuration CurrentConfiguration { get; set; } + public Configuration CurrentConfiguration { get; set; } = default!; protected override async Task OnInitializedAsync() { FilterDateTo = DateTime.Now.Date.AddYears(1); await InitializeList(); - CurrentConfiguration = (await savingsAPI.GetConfigurations()).FirstOrDefault(); + CurrentConfiguration = (await savingsAPI.GetConfigurations()).First(); } @@ -73,7 +69,7 @@ async Task InitializeList() materializedMoneyItems = materializedMoneyItems[Array.IndexOf(materializedMoneyItems, lastBeforeToday)..]; } } - + } async Task AdjustRecurrency(MaterializedMoneyItem item) diff --git a/src/Savings.SPA/Pages/RecurrencyAdjustment.razor.cs b/src/Savings.SPA/Pages/RecurrencyAdjustment.razor.cs index caa756e..5639476 100644 --- a/src/Savings.SPA/Pages/RecurrencyAdjustment.razor.cs +++ b/src/Savings.SPA/Pages/RecurrencyAdjustment.razor.cs @@ -8,13 +8,13 @@ namespace Savings.SPA.Pages public partial class RecurrencyAdjustment : ComponentBase { [Inject] - public ISavingsApi savingsAPI { get; set; } + public ISavingsApi savingsAPI { get; set; } = default!; [Inject] - DialogService dialogService { get; set; } + DialogService dialogService { get; set; } = default!; [Parameter] - public MaterializedMoneyItem materializedItem { get; set; } + public MaterializedMoneyItem materializedItem { get; set; } = default!; [Parameter] public RecurrencyAdjustement adjustement { get; set; } = new RecurrencyAdjustement(); @@ -25,7 +25,7 @@ public partial class RecurrencyAdjustment : ComponentBase protected override async Task OnInitializedAsync() { - var existentAdjustment = await this.savingsAPI.GetRecurrencyAdjustementByIDRecurrencyAndDate(materializedItem.RecurrentMoneyItemID.Value, materializedItem.Date.Date); + var existentAdjustment = await this.savingsAPI.GetRecurrencyAdjustementByIDRecurrencyAndDate(materializedItem.RecurrentMoneyItemID!.Value, materializedItem.Date.Date); if (existentAdjustment != null) { this.adjustement = existentAdjustment; diff --git a/src/Savings.SPA/Pages/RecurrentItemEdit.razor.cs b/src/Savings.SPA/Pages/RecurrentItemEdit.razor.cs index e3421f2..51f384d 100644 --- a/src/Savings.SPA/Pages/RecurrentItemEdit.razor.cs +++ b/src/Savings.SPA/Pages/RecurrentItemEdit.razor.cs @@ -11,18 +11,18 @@ namespace Savings.SPA.Pages public partial class RecurrentItemEdit : ComponentBase { [Inject] - public ISavingsApi savingsAPI { get; set; } + public ISavingsApi savingsAPI { get; set; } = default!; [Inject] - DialogService dialogService { get; set; } + DialogService dialogService { get; set; } = default!; [Inject] - public NotificationService notificationService { get; set; } + public NotificationService notificationService { get; set; } = default!; [Parameter] - public RecurrentMoneyItem recurrentItemToEdit { get; set; } + public RecurrentMoneyItem recurrentItemToEdit { get; set; } = default!; - public MoneyCategory[] Categories { get; set; } + public MoneyCategory[] Categories { get; set; } = default!; [Parameter] public bool isNew { get; set; } @@ -31,9 +31,9 @@ public partial class RecurrentItemEdit : ComponentBase public long? parentItemID { get; set; } = null; [Parameter] - public RecurrentMoneyItem parentItem { get; set; } = null; + public RecurrentMoneyItem? parentItem { get; set; } = null; - InputNumber amountInputNumber; + InputNumber? amountInputNumber; public bool OperationRunning { get; set; } = false; @@ -43,7 +43,7 @@ protected override async void OnAfterRender(bool firstRender) if (firstRender) { await Task.Delay(500); - await amountInputNumber.Element.Value.FocusAsync(); + await amountInputNumber!.Element!.Value.FocusAsync(); } } @@ -55,7 +55,7 @@ protected override void OnInitialized() if (parentItemID.HasValue) { DateTime targetDate = DateTime.Now.AddMonths(1); - targetDate = new DateTime(targetDate.Year, targetDate.Month, parentItem.StartDate.Day); + targetDate = new DateTime(targetDate.Year, targetDate.Month, parentItem!.StartDate.Day); recurrentItemToEdit.StartDate = targetDate; recurrentItemToEdit.EndDate = targetDate; diff --git a/src/Savings.SPA/Pages/RecurrentItems.razor.cs b/src/Savings.SPA/Pages/RecurrentItems.razor.cs index 6e5c70b..786dce2 100644 --- a/src/Savings.SPA/Pages/RecurrentItems.razor.cs +++ b/src/Savings.SPA/Pages/RecurrentItems.razor.cs @@ -9,22 +9,22 @@ public partial class RecurrentItems : ComponentBase { [Inject] - public ISavingsApi savingsAPI { get; set; } + public ISavingsApi? savingsAPI { get; set; } [Inject] - public DialogService dialogService { get; set; } + public DialogService? dialogService { get; set; } [Inject] - public NotificationService notificationService { get; set; } + public NotificationService? notificationService { get; set; } - private RecurrentMoneyItem[] recurrentMoneyItems; + private RecurrentMoneyItem[]? recurrentMoneyItems; [Parameter] public long? parentItemID { get; set; } = null; [Parameter] - public RecurrentMoneyItem parentItem { get; set; } = null; + public RecurrentMoneyItem? parentItem { get; set; } = null; public bool ShowOnlyActive { get; set; } = true; public DateTime? FilterOnlyActiveDateFrom { get; set; } @@ -49,14 +49,14 @@ protected override async Task OnInitializedAsync() async Task InitializeList() { - recurrentMoneyItems = await savingsAPI.GetRecurrentMoneyItems(parentItemID, ShowOnlyActive, FilterOnlyActiveDateFrom, FilterOnlyActiveDateTo); + recurrentMoneyItems = await savingsAPI!.GetRecurrentMoneyItems(parentItemID, ShowOnlyActive, FilterOnlyActiveDateFrom, FilterOnlyActiveDateTo); } async Task AddNew() { - bool? res = await dialogService.OpenAsync($"Add new", - new Dictionary() { { "recurrentItemToEdit", new Savings.Model.RecurrentMoneyItem() }, { "isNew", true }, { "parentItemID", parentItemID }, { "parentItem", parentItem } }, + bool? res = await dialogService!.OpenAsync($"Add new", + new Dictionary() { { "recurrentItemToEdit", new Savings.Model.RecurrentMoneyItem() }, { "isNew", true }, { "parentItemID", parentItemID! }, { "parentItem", parentItem! } }, new DialogOptions() { Width = "600px" }); if (res.HasValue && res.Value) { @@ -67,8 +67,8 @@ async Task AddNew() async Task Edit(RecurrentMoneyItem item) { - bool? res = await dialogService.OpenAsync($"Edit item", - new Dictionary() { { "recurrentItemToEdit", item }, { "isNew", false }, { "parentItemID", parentItemID } }, + bool? res = await dialogService!.OpenAsync($"Edit item", + new Dictionary() { { "recurrentItemToEdit", item }, { "isNew", false }, { "parentItemID", parentItemID! } }, new DialogOptions() { Width = "600px" }); if (res.HasValue && res.Value) { @@ -80,7 +80,7 @@ async Task Edit(RecurrentMoneyItem item) async Task ViewChild(RecurrentMoneyItem item) { - var res = await dialogService.OpenAsync($"Associated Items - {item.Note}", + var res = await dialogService!.OpenAsync($"Associated Items - {item.Note}", new Dictionary() { { "parentItemID", item.ID }, { "parentItem", item } }, new DialogOptions() { Width = "800px", Height = "600px" }); await InitializeList(); diff --git a/src/Savings.SPA/Pages/Reports.razor.cs b/src/Savings.SPA/Pages/Reports.razor.cs index e65a3e3..92c7027 100644 --- a/src/Savings.SPA/Pages/Reports.razor.cs +++ b/src/Savings.SPA/Pages/Reports.razor.cs @@ -10,16 +10,16 @@ public partial class Reports : ComponentBase { [Inject] - private ISavingsApi savingsAPI { get; set; } + private ISavingsApi savingsAPI { get; set; } = default!; [Inject] - public DialogService dialogService { get; set; } + public DialogService dialogService { get; set; } = default!; - private RecurrentMoneyItem[] RecurrentItems { get; set; } + private RecurrentMoneyItem[] RecurrentItems { get; set; } = default!; - private MaterializedMoneyItem[] Installments { get; set; } + private MaterializedMoneyItem[] Installments { get; set; } = default!; - private MaterializedMoneyItem[] EndPeriods { get; set; } + private MaterializedMoneyItem[] EndPeriods { get; set; } = default!; public string FilterCategoryGroupByPeriod { get; set; } = "yy/MM"; @@ -27,7 +27,7 @@ public partial class Reports : ComponentBase public DateTime FilterDateTo { get; set; } - ReportCategory[] statistics; + ReportCategory[] statistics = default!; async void DateTimeDateChanged(DateTime? value, string name) { @@ -38,8 +38,8 @@ async void DateTimeDateChanged(DateTime? value, string name) async Task FilterGroupByCategoryPeriodChanged(ChangeEventArgs e) { - var selectedString = e.Value.ToString(); - FilterCategoryGroupByPeriod = string.IsNullOrWhiteSpace(selectedString) ? null : selectedString; + var selectedString = e.Value?.ToString(); + FilterCategoryGroupByPeriod = string.IsNullOrWhiteSpace(selectedString) ? string.Empty : selectedString; await InitializeCategoryResume(); StateHasChanged(); @@ -63,7 +63,7 @@ async Task InitializeInstallmentResume() DateTime endDate = DateTime.Now.AddMonths(1); if (RecurrentItems.Any()) { - endDate = RecurrentItems.Max(x => x.EndDate.Value); + endDate = RecurrentItems.Max(x => x.EndDate!.Value); } var projections = await savingsAPI.GetSavings(null, endDate, true); Installments = projections.Where(x => x.RecurrentMoneyItemID.HasValue && x.Amount != 0 && x.Date >= DateTime.Now).ToArray(); @@ -91,7 +91,7 @@ async Task OpenDetails(long? category, string period) new Dictionary() { { "FilterDateFrom", FilterDateFrom }, { "FilterDateTo", FilterDateTo }, - { "category", (long?)category }, + { "category", category! }, { "periodPattern", FilterCategoryGroupByPeriod }, { "period", period } }, @@ -140,7 +140,7 @@ string FormatAsAmount(object value) return ((double)value).ToString("N2"); } - string FormatAsMonth(object value) + string? FormatAsMonth(object value) { return value?.ToString(); } diff --git a/src/Savings.SPA/Pages/ReportsDetail.razor.cs b/src/Savings.SPA/Pages/ReportsDetail.razor.cs index a6443ea..b518cbe 100644 --- a/src/Savings.SPA/Pages/ReportsDetail.razor.cs +++ b/src/Savings.SPA/Pages/ReportsDetail.razor.cs @@ -8,7 +8,7 @@ public partial class ReportsDetail : ComponentBase { [Inject] - public ISavingsApi savingsAPI { get; set; } + public ISavingsApi savingsAPI { get; set; } = default!; [Parameter] public DateTime FilterDateFrom { get; set; } @@ -20,12 +20,12 @@ public partial class ReportsDetail : ComponentBase public long? category { get; set; } = null; [Parameter] - public string periodPattern { get; set; } = null; + public string? periodPattern { get; set; } = string.Empty; [Parameter] - public string period { get; set; } = null; + public string? period { get; set; } = string.Empty; - public ReportDetail[] ReportCategoryDetails { get; set; } + public ReportDetail[]? ReportCategoryDetails { get; set; } protected override async Task OnInitializedAsync() { @@ -34,7 +34,7 @@ protected override async Task OnInitializedAsync() async Task InitializeList() { - ReportCategoryDetails = await savingsAPI.GetCategoryResumeDetail(periodPattern, FilterDateFrom, FilterDateTo, category, period); + ReportCategoryDetails = await savingsAPI.GetCategoryResumeDetail(periodPattern!, FilterDateFrom, FilterDateTo, category, period!); } } diff --git a/src/Savings.SPA/Program.cs b/src/Savings.SPA/Program.cs index c1bb69a..0ac9054 100644 --- a/src/Savings.SPA/Program.cs +++ b/src/Savings.SPA/Program.cs @@ -27,13 +27,13 @@ options.ProviderOptions.Cache.CacheLocation = "localStorage"; options.ProviderOptions.LoginMode = "redirect"; builder.Configuration.Bind("AzureAd", options.ProviderOptions.Authentication); - options.ProviderOptions.DefaultAccessTokenScopes.Add(builder.Configuration["AzureAd:DefaultScope"]); + options.ProviderOptions.DefaultAccessTokenScopes.Add(builder.Configuration["AzureAd:DefaultScope"]!); }); } var httpClientBuilder = builder.Services.AddRefitClient().ConfigureHttpClient((sp, c) => { - c.BaseAddress = new Uri(builder.Configuration["SavingsApiServiceUrl"]); + c.BaseAddress = new Uri(builder.Configuration["SavingsApiServiceUrl"]!); if (configuredAuthentication == AuthenticationToUse.ApiKey) { c.DefaultRequestHeaders.Add("X-API-Key", builder.Configuration["ApiKey"]); diff --git a/src/Savings.SPA/Shared/NavMenu.razor b/src/Savings.SPA/Shared/NavMenu.razor index 580c0c2..57689e6 100644 --- a/src/Savings.SPA/Shared/NavMenu.razor +++ b/src/Savings.SPA/Shared/NavMenu.razor @@ -62,7 +62,7 @@ private bool collapseNavMenu = true; - private string NavMenuCssClass => collapseNavMenu ? "collapse" : null; + private string NavMenuCssClass => collapseNavMenu ? "collapse" : string.Empty; private void ToggleNavMenu() {