In the previous part of this article series you were introduced to the sample application we are building. You also created the EF Core model consisting of Team, TeamMember, and AppDbContext classes. In this part we will add TeamsController to the web application perform CRUD operations on the Teams table.
The DataDisplayModes enum is intended to indicate the display mode of the data entry UI such as read-only, Insert, and Update. Based on this value we will render the appropriate UI. The DataEntryTargets enum indicates whether we are editing Teams table or TeamMembers table.
The Teams property points to the list of Teams entities that are to be displayed in the master grid. The SelectedTeam property is a reference to the Team that is being selected by clicking the Manage Team button. The SelectedTeamMember is a TeamMember selected from the detail grid for editing. The DataEntryTarget tells us whether master table is being modified or details table is being edited. The DataDisplayMode indicates the mode for the data entry operation - Read, Insert, or Update.
The InsertEntry() action gets invoked when you click on the Insert Team button at the top of the master grid. Inside, we set the DataEntryTarget to Teams because we are adding a new Team. We also set the DataDisplayMode to Insert because we want to render UI like this:
When you enter Team details such as Name and Description, and hit Save, the InsertUpdate() action gets called. Inside, we use Add() and SaveChanges() method to add a new Team. We then set the newly added Team as the selected item in the master grid. This is done by setting the SelectedTeam property of MasterDetailViewModel object. The DataDisplayMode is changed to Read so that the newly added Team is shown like this:
The UpdateEntry() action is invoked when you click the Edit button. We pass teamId route parameter to this action. Inside, we fetch that particular Team and set the SelectedTeam property of MasterDetailViewModel. We also set the DataDisplayMode to Update since we want to render UI for update:
When you edit a Team record and click on the Save button, UpdateSave() action is called. Inside, we use Update() and SaveChanges() methods to update that Team record. We then toggle the DataDisplayMode to Read because edit operation is now over.
Inside the Delete() action, we find the Team to be deleted and then use Remove() and SaveChanges() methods to delete that record. Since the record is now deleted, we also set the SelectedTeam property of MasterDetailViewModel to null.
Finally, we need an action that cancels the Team selection. For example, when we click on Insert Team button we need to remove the current selection because a new record is being added. This is accomplished by CancelSelection() action as shown below:
This completes the TeamsController. Note that for the sake of brevity we haven't paid much attention to model validation and error handling. You can add those capabilities using data validation attributes as you normally do in any ASP.NET Core application.
Master-detail pages are quite common in many web applications. There are various approaches to building master-detail pages including server side, client side, and hybrid. There are also many third-party controls and plugins that can be used to accomplish this task. It would be interesting for beginners to learn and understand how master-detail pages work and how they can be developed in ASP.NET Core. To that end this multipart article explains how master-detail pages can be developed using purely server side code without relying on any third-party component or library.
We will be using two SQL Server tables namely Teams and TeamMembers. Teams is the master table and contains information about a team such as TeamID, Name, and Description. A Team can have one or more members. The members are stored in TeamMembers table. Thus TeamMembers is a detail table and contains TeamMemberID, Name, and Email.
As you can see, we display Teams records in a table. You can add a new team by clicking Insert Team button. You can modify existing team information using Manager Teams button. And you can manage team members using Manage Members button.
When you select a Team for editing purpose, that record is highlighted in the master grid and the Team is displayed for editing below the master grid. You can click on Edit to modify the Team details. You can click on Delete to delete that team. And you can hit Cancel to cancel the editing and selection of the team.
Now that you have some idea about the application, let's see the structure of Teams and TeamMembers tables. I have added these tables to the Northwind database using Visual Studio Server Explorer but you can create a new database if you so wish.
The TeamMembers table contains four columns - TeamMemberID, TeamID, Name, and Email. The TeamMemberID is an identity column and acts as the primary key for the table. TeamID column is a foreign key column that references to the TeamID from the Teams table.
Notice the Members navigation property that will hold the TeamMember entities for a Team under consideration. We will load the Members property explicitly through code as discussed in the next part of this article series.
This is an AI generated summary. There may be inaccuracies. The green links below are Amazon affiliate links where summarize.tech may earn a commission.
Summarize another video Purchase summarize.tech Premium
In this YouTube video titled "Advance Master Detail CRUD in MVC ASP.NET CORE 6 using EFCORE - Purchase Order form," Anis demonstrates how to create, edit, and delete records in a purchase order module using ASP.NET Core 6 and EFCore without third-party components. He showcases the functionality of required fields and auto-generated numbers, such as the P1 number. The grid allows for dynamic scrolling and summary totals. The user can change currencies, and the price in the grid converts accordingly.Anis also explains the steps to create and manage a currency module, which enables users to create, edit, and delete currencies. The speaker demonstrates how to install EFCORE tools and perform migrations to update the model changes, encountering errors due to compatibility issues with EF Core and its dependent libraries that are not upgraded to .NET 6. After resolving this issue, the speaker adds the 'exchange currency id' foreign key property to the model and establishes a relationship with the 'currencies' table. Finally, he guides viewers through how to pass error information from the repository to the controller and adjusts CRUD methods in the currency module
In this YouTube video titled "Advance Master Detail CRUD in MVC ASP.NET CORE 6 using EFCORE - Purchase Order form," the speaker explores creating and updating models for a Purchase Order form using Entity Framework Core (EFCORE) in ASP.NET Core 6. Topics include creating new currency records, resolving exchange rate issues, improving appearance and functionality of screens, and fixing referencing issues between foreign keys. The speaker modifies various methods like create, delete, and get items, and implements the CRUD operations by updating return types, input parameter types, and coding for supporting methods. Additionally, they create a new PurchaseOrderController and make necessary modifications
In the YouTube video titled "Advance Master Detail CRUD in MVC ASP.NET CORE 6 using EFCORE - Purchase Order form," the speaker discusses implementing a master-detail relationship for a purchase order form using ASP.NET Core 6 and Entity Framework Core 6. The process includes modifying the controller and creating views, scaffolding, setting up master and detail columns, and adding validation rules. The speaker demonstrates how to add an empty item and create select lists for the product code column. The speaker also explains the importance of handling delete actions properly to avoid deleting rows with only one detail present. The video covers the creation of the header section, including input controls, labels, and validation spans. The speaker plans to add code for the Add button's click event to add new rows dynamically in a later session, and the tutorial also touches on the importance of setting the correct id for the table and header row
I'm using Radzen community edition and trying to create Master/Detail Hierarchy based on two MS SQL Views. I created empty page and added datagrids but I'm unable to set filters to get child rows on master row expand event.
The current master record is available as $event. In the case from the screenshot (considering the Category - Product relationship) the event handler invokes the getProducts method and filters by CategoryID by setting the $filter parameter to CategoryID eq $event.CategoryID.
Thank you for your answer!
I'll be more precised... I have datagrid (master) created with SQL View "viewParametri_naloga". This SQL View is created using data from couple tables but ID field is "Primary key" in this View.
I have another datagrid (child) created using SQL View "viewProduktivnost_ploce". This SQL View is created using data from another table with column "ID_parametra_naloga" that is "Foreign key" in this View and contains values from master view "viewParametri_naloga.ID". This way I can relate all records from viewProduktivnost_ploce with record in viewParametri_naloga. I can load all rows from viewParametri_naloga in main datagrid and my goal is to load all child rows from viewProduktivnost_ploce where viewParametri_naloga.ID = viewProduktivnos_ploce.ID_parametra_naloga.
This code looks correct. The Data property of the child DataGrid should be set to $data.viewProductkivnostPloces (if it is defined in the Template of the Master DataGrid). You can check in your browser's developer tools to see if the getViewProductivnostPloces method is invoked - it should appear as a HTTP GET request in the Network tab.
Query in SQL view "viewProduktivnostPloce" is simple select query without WHERE condition. My goal is to filter this query on RowExpand event (please correct me if I'm wrong). Bellow you can find JSON response:
7fc3f7cf58