Early-bird ticket price on the event page and at checkout

C# · ASP.NET Core · intermediate · modification

Adds early-bird pricing to the event page and checkout. `TicketPricing.For` (new, `Events/TicketPricing.cs`) decides which ticket price applies to an event right now and returns it with whether the early-bird offer is on and when it ends. `EventEndpoints.cs` uses it in `GET /api/events/{slug}`, which now also returns `earlyBird` and `earlyBirdEndsAt` for the page's countdown, and in `POST /api/events/{slug}/orders`, so an order's amount uses the same price rule the page shows. `EventDtos.cs` adds the two fields to `EventDto`. `TicketPricingTests.cs` (new) adds xUnit tests for `TicketPricing.For`.

Ticketing API on ASP.NET Core 10 minimal APIs, .NET 10 (C# 14, nullable reference types enabled, implicit usings), EF Core 10 with Npgsql on Postgres 16, xUnit for tests. It runs on two Linux VMs in Frankfurt whose system time zone is set to Europe/Berlin (the ops team's choice, so host logs read in office time). Existing and unchanged: `Program.cs` registers `TicketsDbContext` and JWT bearer authentication and calls `app.MapEventEndpoints()`; `User.GetUserId()` (`Tickets.Api.Auth`) reads the token's `sub` claim. `TicketsDbContext.Events` is the `Event` entity: `Id`, `Slug` (unique), `Name`, `Venue`, `StartsAt` (`timestamptz`), `Published`, `SalesOpen`, `PriceCents` (long, 100 to 1,000,000), `EarlyBirdPriceCents` (long?, 100 to 999,999 and always below `PriceCents`) and `EarlyBirdEndsAt` (`DateTime?`, a `timestamptz` column). The organizer dashboard (shipped earlier, unchanged) sets `EarlyBirdPriceCents` and `EarlyBirdEndsAt` together or clears both; organizers enter the end in the event's local time and the dashboard stores that instant. Npgsql reads `timestamptz` columns as `DateTime` values with `Kind = Utc`, and the API's JSON writes them with a trailing `Z`. `Order` has `EventId`, `UserId`, `Quantity`, `AmountCents`, `Status` and `CreatedAt`; the payment page (separate, unchanged) charges a pending order's `AmountCents`. All prices are euro cents. The code reads the clock directly, as the order endpoint's `CreatedAt = DateTime.UtcNow` does; no `TimeProvider` is registered. The event page in the web app ships separately and only reads this endpoint.

Requirements

Files touched

Review this PR

C# practice