From the course: Advanced Web APIs with ASP.NET Core 8

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Solution: Advanced search

Solution: Advanced search

- [Instructor] There are several ways how we could pip our search. For instance, we could just go to our product view parameters where we have our name property, and we could elevate that so that it searches the SKU and the name and maybe even the description if it was set, et cetera. On the other hand, that would be a little bit confusing, wouldn't it? And therefore I would say we introduce an additional query string parameter, which then of course belongs into our product query parameter class. And I'll just call it search term and initialize it with an empty string as before. And what do we do in our products controller now? It's obvious that we have to look at the SKU and at the name and then search for the search term in it. But when do we do that? And here is what I suggest. I'll put it here before checking the SKU and the name query stringing parameters, and you'll see in a minute why. So first the implementation. So if it's not null or empty, if we have something in the search…

Contents