From the course: Building and Securing RESTful APIs in ASP.NET Core
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Add a default sort term - ASP.NET Core Tutorial
From the course: Building and Securing RESTful APIs in ASP.NET Core
Add a default sort term
- [Instructor] Right now, the default sort order is the order that items are added to the database. You can see this if I make a request to the rooms route. If I don't pass any sore parameters the Oxford Suite is listed first and the Driscoll Suite is listed second. But if I open up the seed data class and then change the order those are added to the database. And send that request again, the order will be reversed. Instead of relying on the order things were added to the database, it would be better to declare a default sort term that's applied if the client or user doesn't specify a sort. We can extend the sortable attribute to do this. In the sortable attribute class, I'll add a new property which is a Boolean called Default. And I'll update the sort term model to include this as well. Boolean default. Now we need to make some updates to the sort options processor. In the GetTermsFromModel method, let me expand this syntax a little bit here. Instead of just outputting the name I…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.