Deleting a record from the database
When a user clicks on the trash bin icon, it should not immediately delete the corresponding record. The user should be given the chance to recover if the user made a mistake. We can simply display a page showing the employee details first, then ask the user for confirmation.
Edit source\empcontrol.d and add this code:
We retrieve the employee record and display that record in views\empdelete.dt.
So let's create views\empdelete.dt.
Here we are displaying a page showing the employee details and asking the user for confirmation.
Compile, run and refresh the browser. Show the list of employees again and click on a trash bin icon. The confirmation page should show.
Click Cancel for now just to test if the Cancel button works. Then click the trash bin icon of another record.
This time click the Delete button.
And you get this error:
So let’s implement postDeleteEmployee() in EmployeeController class.
Edit source\empcontrol.d and append this code.
We are calling empModel.deleteEmployee() here, so let’s implement that too.
Edit source\empmodel.d and append this code.
Here we finally delete the record from the database table.
Compile, run and refresh the browser to the list of employees. Click on a trash bin icon, click Delete on the next screen, and you will be redirected to the list of employees again.
This time you should see that the record you selected is no longer listed.
Now, let’s implement that Find employee link on the menu.
Last updated