Implementing CRUD operations
Once we have prepared modal dialogs, which will be used in CRUD operations from previous sections, we can implement CRUD operations in this section.
CRUD operations of items
To add or update an item, we can use the UpdateItemAsync()
method in Items.razor.cs
to handle both cases. To detect whether we want to create a new item or update an existing item, we define a private _isNewItem
field as follows:
bool _isNewItem = false;
Next, we’ll see how to add or edit an item.
Adding a new item
To add a new item, we can click the + button in the header of the Items
page, as shown in Figure 9.7:
Figure 9.7: Adding a new item
The Razor markup of this page header can be reviewed here:
<div class="container"><div class="row"> <div class="col-12"><h1> @if (selectedItem?.GetParentLink() != null) { ...