Why separate Add/Edit?

Is there a reazon to maintain two separate pages?
Why not just use one page for both actions? It would be so much easier to maintain.

Although the form is almost identical there are still enough differences and we prefer to keep them separate instead having conditions on various places.

I wonder if some of the differences would be lessened & generation simplified if you were to allow/require us to explicitly create page parameters at design time. As opposed to interfering them from events such as Open Dialog and Navigate events on other pages. I know I still often get hung up on compile when a page parameter is missing because I messed with one of these events.

For what it's worth, if there are going to be two pages per entity, I'd prefer to see View Page and Add\Edit Form. This maps better to Read\Write permission in most scenarios.

Thanks for listening.
Josh

I'd tend to agree with Carlos and while I haven't tried it, it seems like it would be easy to achieve manually. (I think there's been a post or two about this here before). Just pass a page type parameter to the receiving page, and handle the load and submit items based on that. However, wiring up at least one type of component, the multiple select dropdown, is rather different for each type and would probably negate any benefits.

I came up with this solution:

In the Designer.cs page renamed the Default Task FormSubmit wich creates a new record to FormAddSubmit and added a new task named FormUpdateSubmit with the code from the FormSubmit from the EditEntity page.
Then in the Edit-Entity form wich will be the only necessary page (Add-Entity will no longer be necessary) replaced the following:

<RadzenTemplateForm TItem="MyErp.Models.DefaultDb.Customer" Data="@customer" Visible="@(customer != null)" Submit="@Form0Submit">

To

<RadzenTemplateForm TItem="MyErp.Models.DefaultDb.Customer" Data="@customer" Visible="@(customer != null)" Submit="@(Id!=null ? FormUpdateSubmit : FormNewSubmit)">

What this does is to check if the 'Id' parameter has value. If it has a value it means it is editing the record, if it doesn't then it is a new record.

PS: The 'Add' button in the grid form has to be changed to call the Edit-Entity (without any parameter) instead of "UriHelper.NavigateTo("customer-add");".

    protected async System.Threading.Tasks.Task ButtonAddClick(MouseEventArgs args)
    {
        var dialogResult = await DialogService.OpenAsync<CustomerEdit>("CustomerEdit");
        await InvokeAsync(() => { StateHasChanged(); });
    }

It is really quite simple. And it avoids having to maintain two differente pages wich in reality are just about the same.

2 Likes