Create record in code and redirect to the edit page for the new record

I think it'll help if I start by explaining my scenario:

I'm creating an invoice / invoice details entry form. Right now it works fine. A new header is created, the user presses save and it redirects to the edit screen that shows the data grid for the children and they can add the children. However, if they abort at this point we have a record to worry about and an id used. Creating the header first, feels like one step the user shouldn't need to be bothered with.

So what I want to do is have a custom InvoiceId that is generated when the record is complete. The plan is to create a record with some default values without an InvoiceId. I can then filter the Invoice List page so that it doesn't show incomplete records (ie records without an InvoiceId). When a record is then edited and the save button is clicked, I can populate a new InvoiceId and thus the invoice becomes complete.

So, what I'd like to do is, when Add is clicked from the Invoice list page the following occurs:

  1. Dynamically create a new record with default values, null InvoiceId
  2. Return new invoice Id
  3. Navigate to edit that record

I can't seem to figure how to do step one.

I've thought about:

  • Invoking a data source method and pass a null object - Didn't seem to work
  • Create a custom method to create the record on the server and return the Id - I seem to run into DbContext problems with the DB.
  • Post directly to the post API method - I'm not sure this is best practice

Can anyone point me in the right direction? Maybe I have overthought this and have it wrapped around my neck.

Ideally, it would be lovely to create and new header and children all at once and save them all at once. However, I understand the constraints in place right now and am looking for a nice work around.

Thanks,

Paul.

Hi Paul,

Your scenario is similar to Orders -> OrderDetails from our Sample database. Maybe you can invoke createXXX on DataGrid Add (instead Add dialog open), get the Id of the created record and use it for Edit dialog:

Edit Order in this case will have OrderDetails grid:

Source code of the app can be found here:

When you click Cancel the record will be deleted.

Is there a Blazor not Angular sample like this?