From the course: Advanced Web APIs with ASP.NET Core in .NET 6
Unlock the full course today
Join today to access over 24,900 courses taught by industry experts.
Solution: Advanced search - C# Tutorial
From the course: Advanced Web APIs with ASP.NET Core in .NET 6
Solution: Advanced search
(upbeat music) - [Instructor] There are several ways to pimp our search. One would be that we just elevate our query parameter name so that it searches both the name and the SKU field. That would be the easiest and fastest approach but then on the other hand, it might be a bit confusing that the Name parameter searches the SKU, but there's also a Sku parameter that searches, well, the SKU. So I would recommend something else. We add another query parameter, and I add this to the ProductQueryParameters class, and I call this SearchTerm. That's a generic name, isn't it? And the idea is now that if SearchTerm is set, I search both the name and the SKU, and here's how that could look. So if not string is null or empty of queryParameters and then SearchTerm, if that is set, I just search both fields. So product = products, Where, then the first where clause is that the SKU equals the search term and since this is our…
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.