Validation, ErrorProvider and feedback
The Module 4 editor learns to
say no before the database does: DataAnnotations on TicketEditModel, TicketValidator (annotations plus
the cross-field rule Closed tickets cannot have a future due date), errorProvider icons, a
validationSummaryLabel, Save disabled while the model is invalid, and a friendly message when the database
still rejects a save (a duplicate ticket number).
Run it
cd "LearnWisej-Samples/Data Binding with EF Core Course/Module 5/SupportDesk.Web"
dotnet run -f net10.0 --urls http://localhost:5405
Tests: dotnet test SupportDesk.Tests (the negative cases are in TicketValidatorTests.cs and DuplicateNumberTests.cs).
What to try
The editor now has Title, Customer, Category, Status, Priority, Due date, Agent, Description, Escalate as
urgent, the validationSummaryLabel, Delete, Cancel and Save.
- Add Ticket: Save starts disabled with Fill in Title, Customer and Category.; fill them and Save enables.
- Empty title / no customer: an
errorProvidericon on the field and the message in the summary; Save stays disabled. - Edit a ticket, set Status to Closed with a future due date: the icon sits on the due date and the rule shows in the summary. Fix it and the messages clear.
- Open the editor twice in a row: the previous run's icons are gone.
- Duplicate ticket number: a unique-index violation becomes one plain sentence in an
AlertBox(FriendlyDatabaseErrors.TicketSaveRejected), the lookups reload, and the full exception goes to the server console. It is reproduced byDuplicateNumberTests(SaveAsync(model, forceDuplicateNumber: true)) or by two sessions saving a new ticket at the same moment.