diff --git a/BudgetApp/Components/Pages/Accounts.razor.cs b/BudgetApp/Components/Pages/Accounts.razor.cs index 749179a..a6c5686 100644 --- a/BudgetApp/Components/Pages/Accounts.razor.cs +++ b/BudgetApp/Components/Pages/Accounts.razor.cs @@ -1,4 +1,3 @@ - using BudgetApp.Data.Entities; namespace BudgetApp.Components.Pages; @@ -133,4 +132,5 @@ public partial class Accounts [System.ComponentModel.DataAnnotations.MaxLength(3)] public string CurrencyCode { get; set; } = "GBP"; } + } \ No newline at end of file diff --git a/BudgetApp/Services/DashboardService.cs b/BudgetApp/Services/DashboardService.cs index 8ade703..5bb0382 100644 --- a/BudgetApp/Services/DashboardService.cs +++ b/BudgetApp/Services/DashboardService.cs @@ -76,22 +76,16 @@ public class DashboardService(ITransactionRepository transactionRepository, IAcc if (startDate.Date <= today) { - foreach (var t in accountTransactions - .Where(t => t.Date.Date >= startDate.Date && t.Date.Date <= today) - .OrderByDescending(t => t.Date)) - { - runningBalance -= t.Type == TransactionType.Income ? t.Amount : -t.Amount; - } + runningBalance = accountTransactions.Where(t => t.Date.Date >= startDate.Date && t.Date.Date <= today) + .OrderByDescending(t => t.Date) + .Aggregate(runningBalance, (current, t) => current - (t.Type == TransactionType.Income ? t.Amount : -t.Amount)); } else { // Future-only window: project forward from CurrentBalance using only unpaid transactions - foreach (var t in accountTransactions - .Where(t => t.Date.Date > today && t.Date.Date < startDate.Date && !t.IsPaid) - .OrderBy(t => t.Date)) - { - runningBalance += t.Type == TransactionType.Income ? t.Amount : -t.Amount; - } + runningBalance += accountTransactions.Where(t => t.Date.Date > today && t.Date.Date < startDate.Date && !t.IsPaid) + .OrderBy(t => t.Date) + .Sum(t => t.Type == TransactionType.Income ? t.Amount : -t.Amount); } for (var d = startDate; d <= endDate; d = d.AddDays(1)) diff --git a/BudgetApp/budgetapp.db-shm b/BudgetApp/budgetapp.db-shm index 8b03f4d..3d42b32 100644 Binary files a/BudgetApp/budgetapp.db-shm and b/BudgetApp/budgetapp.db-shm differ diff --git a/BudgetApp/budgetapp.db-wal b/BudgetApp/budgetapp.db-wal index 18074c8..2330d1f 100644 Binary files a/BudgetApp/budgetapp.db-wal and b/BudgetApp/budgetapp.db-wal differ diff --git a/Dockerfile b/Dockerfile index 5237ce2..279bdaa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,9 +5,16 @@ EXPOSE 8080 FROM mcr.microsoft.com/dotnet/sdk:10.0-preview AS build WORKDIR /src + +# Copy project files first so the restore layer is cached independently of source changes +COPY BudgetApp.Data/BudgetApp.Data.csproj BudgetApp.Data/ COPY BudgetApp/BudgetApp.csproj BudgetApp/ RUN dotnet restore BudgetApp/BudgetApp.csproj + +# Copy all source (BudgetApp.Data must be present before building BudgetApp) +COPY BudgetApp.Data/ BudgetApp.Data/ COPY BudgetApp/ BudgetApp/ + WORKDIR /src/BudgetApp RUN dotnet publish -c Release -o /app/publish