Dotnet
Articles Part 2

Implement Articles Repository Part 2

PRO
Outline

Implement Get Articles Async (cont.)

The next thing we need to handle is if the Author is not null. Remember that the API only requires you to handle one case at a time.

We'll do that by using an else…if statement to check if the Author is not null. Just like the Tags, we'll call another method named GetEditorialsByAuthorAsync. Pass in the Author, the limit and the offset as parameters.

I'm sure you know the routine by now… Let's create the method, move the private method above the public methods.

We can copy the method where we fetch the Tags and simply change the where clause. We'll change the Where Clause to reflect that we want to filter by Author. Let's fix the error by making the method async.

That's it! The rest of the heavy lifting is already done! Let's do the last one.

Again, using an else…if statement, we'll check to see if the favorited parameter is not null. We'll call GetEditorialsByFavoritedAsync and pass in favorited, limit, and offset. Let's generate the method and move it up above the public methods.

Once again, we'll copy from our previous example and change the where clause and fix the error by making the method async.

Final criteria

At this point we've covered in the case the user wants to filter by tags, author or favorited. But what if there is no filter?

Let's go thru the exercise to see how that would look.

We'll do an Else block and call a method called GetEditorialsAsync. Since we don't any filter in this case we'll just pass in the limit and the offset parameters. We'll let Visual Studio create the method and in an effort to keep our class in an organized fashion we'll move it to the top where the other private methods are located.

Exercise

At this point I'd like to propose an exercise by letting you complete the implementation of this method. Use the other 3 methods we created as reference to help you accomplish this one.

In the next video I'll show you my solution. See you there!

 

I finished! On to the next chapter