The appointment booking is the Kladde’s most important public page. Whoever wants an appointment with the office shouldn’t have to call:
choose a day, choose a free time, enter your name and address, done. So far, the prototype appointment.html has a form for that, and the
form doesn’t know anything. In this lesson, the Kladde gets the rule for which times are free, and a Blazor page that offers and books them.
The rule is the harder part, and it belongs in the core. You build it test-first, as in K1: first a test that’s red, then the code that makes it green. The page on top of it is then almost only forms from the last lesson.
Where the Kladde stands
For this lesson, you need three parts from earlier modules. In the solutions, they’re called this:
BookingOptionsfrom lesson 2.3.4: the booking’s settings fromappsettings.json, checked at startup. So far, they have one opening time for all days (Opens,Closes), the length of an appointment (AppointmentMinutes), the lead time (LeadTimeHours) and, since lesson 2.3.9, the office’s time zone (TimeZoneId,FindTimeZone()).TimeProvider, registered since lesson 2.3.3. The page asks it for the time, neverDateTimeOffset.Now.The booking from lesson 2.4.10. In the solutions, that’s a record
BookinginKladde.Coreand a method onKladdeBook:// excerpt from Kladde.Core after lesson 2.4.10 public sealed record Booking // in Booking.cs { public const int MaxNameLength = 100; public Guid Id { get; } public string Name { get; } public EmailAddress Email { get; } public TimeRange Time { get; } … } public IReadOnlyList<Booking> Bookings { get; } // in KladdeBook public Task<Result<Booking>> BookAsync(string? name, string? email, TimeRange time) // in KladdeBookBookAsyncrefuses withbooking.time.takenif the time overlaps with an appointment or another booking, and the unique constraint from lesson 2.4.10 keeps even two simultaneous bookings apart.
If yours are called something else, keep your names and transfer the steps.