Skip to main content

Two-way binding and CRUD editors

This example is the ticket browser from Module 3 gains Add Ticket and Edit Ticket, which open the modal TicketEditorForm. The form binds a TicketEditModel through editBindingSource; Save calls EndEdit, a validation placeholder, then TicketCommandService.SaveAsync (fresh context, load or add, map, SaveChangesAsync); Delete confirms and loads the ticket by key in a fresh context. The grid re-runs its search only on DialogResult.OK.

Run it

cd "LearnWisej-Samples/Data Binding with EF Core Course/Module 4/SupportDesk.Web"
dotnet run -f net10.0 --urls http://localhost:5404

Tests: dotnet test SupportDesk.Tests.

What to try

Browser: the Module 3 controls plus btnAdd and btnEdit. Editor: txtTitle, cboCustomer, cboCategory, dtpDueDate, chkIsUrgent, btnDelete, btnCancel, btnSave, with editBindingSource and errorProvider.

  • Add Ticket: fill Title, Customer, Category, Save: the dialog closes and the new ticket is on top of page 1.
  • Edit Ticket on a row, change the title and tick Escalate as urgent, Save: the grid shows the saved row.
  • Cancel: nothing is written and the grid is not reloaded.
  • Empty title, Save: the validation placeholder puts an errorProvider icon on txtTitle; no context is created.
  • Double-click Save: the _saving guard drops the second click.
  • Delete, answer Yes: the ticket is removed. On a Closed ticket the business rule refuses it with a message.
  • Already deleted: open the same ticket in two browser tabs, delete it in one, then Save or Delete in the other: This ticket was already deleted by someone else, and the dialog closes so the grid refreshes.