diff --git a/src/GoodWood.Application/Games/FoxHunt/FoxHuntGameSetup.cs b/src/GoodWood.Application/Games/FoxHunt/FoxHuntGameSetup.cs index b8ba2a0..c7aeba0 100644 --- a/src/GoodWood.Application/Games/FoxHunt/FoxHuntGameSetup.cs +++ b/src/GoodWood.Application/Games/FoxHunt/FoxHuntGameSetup.cs @@ -35,7 +35,8 @@ namespace GoodWood.Application.Games.FoxHunt ThrowMode = throwMode, ThrowsPerRound = throwsPerRound, ParticipantsMode = participantsMode, - LeadingThrows = leadingThrows + LeadingThrows = leadingThrows, + PinCountGoal = pinCountGoal }; } } diff --git a/src/GoodWood.Application/Services/DayService.cs b/src/GoodWood.Application/Services/DayService.cs index 767c004..a721dbc 100644 --- a/src/GoodWood.Application/Services/DayService.cs +++ b/src/GoodWood.Application/Services/DayService.cs @@ -377,21 +377,22 @@ public class DayService : IDayService if (club.ExpenseCalculation == ExpenseCalculation.None) return; - // 3. Get all PersonExpense prices for this day - var dayExpensePrices = await context.PersonExpenses + // 3. Get total expenses per participant for this day + var personExpenseTotals = await context.PersonExpenses .Where(pe => pe.DayId == dayId && !pe.IsDeleted) - .Select(pe => pe.Price) + .GroupBy(pe => pe.PersonId) + .Select(g => g.Sum(pe => pe.Price)) .ToListAsync(ct); // 4. Edge case: No expenses - skip - if (dayExpensePrices.Count == 0) + if (personExpenseTotals.Count == 0) return; - // 5. Calculate price + // 5. Calculate price based on per-person totals decimal calculatedPrice = club.ExpenseCalculation switch { - ExpenseCalculation.Average => Math.Round(dayExpensePrices.Average(), 2), - ExpenseCalculation.Maximum => dayExpensePrices.Max(), + ExpenseCalculation.Average => Math.Round(personExpenseTotals.Average(), 2), + ExpenseCalculation.Maximum => personExpenseTotals.Max(), _ => 0m }; diff --git a/src/GoodWood.Web/Components/Game/FoxHunt/FoxSetup.razor b/src/GoodWood.Web/Components/Game/FoxHunt/FoxSetup.razor index 00b15f3..ecc4a7e 100644 --- a/src/GoodWood.Web/Components/Game/FoxHunt/FoxSetup.razor +++ b/src/GoodWood.Web/Components/Game/FoxHunt/FoxSetup.razor @@ -109,6 +109,7 @@ var setup = new FoxHuntGameSetup { LeadingThrows = _options.LeadingThrows, + PinCountGoal = _options.PinCountGoal, ParticipantsMode = _options.ParticipantsMode }; await OnOptionsChanged.InvokeAsync(setup); diff --git a/src/GoodWood.Web/Components/Game/Pin.razor b/src/GoodWood.Web/Components/Game/Pin.razor index 0fae342..037270e 100644 --- a/src/GoodWood.Web/Components/Game/Pin.razor +++ b/src/GoodWood.Web/Components/Game/Pin.razor @@ -1,7 +1,7 @@ @using GoodWood.Domain.Enums