We have been finding and displaying an employee record already, so this should be trivial to us by now. However, we have always used the id field as the key. This time, we are going to use the name of the employee as the key.
Click on the Find employee menu item to test it. For now, try to find an employee by the first name and last name.
But when you click on submit, you get this error:
It is looking for the postFindEmployee() method, so let’s create it.
Edit source\empcontrol.d and append this code:
We are converting the names to uppercase because we are not sure how the names were inputted in the forms and saved in the database.
Edit source\empmodel.d and define this method at the end.
In the SQL statement, we are also converting the names to uppercase before comparing. Instead of looking for the row ID, this time the method is looking for the first name and last name converted to uppercase.
Create views\employee.dt.
Then compile, run and refresh the browser. Look for an employee and click Find. If the employee was not found, it simply shows the home page.
But if the employee was found, the record should be displayed.
So here is the full source\empcontrol.d so far.
And here is the full source\empmodel.d so far.
Now we have gone through all the CRUD (create, read, update and delete) operations.
void postFindEmployee(string fname, string lname)
{
import std.uni; //so we can use toUpper() function
string first = toUpper(fname);
string last = toUpper(lname);
Employee e = empModel.findEmployee(first, last);
if(e != Employee.init) render!("employee.dt", e);
else redirect("all_employees");
}