Outline

Demo: Get Article by Slug

Let's continue with the next method in the Articles Controller which happens to be GetArticlebySlugAsync. In this method we return a single Article based on the Slug.

Let's Right-Click on the GetArticleBySlugAsync method and select Go To Implementation.

Once again we'll be working with some very familiar code where we get an Editorial from Context, Editorials. We need to Include Favorites, Person and Tags. This time we'll grab the first one that matches the slug. If we don't find it'll give us a null value.

If we do get a null value from the Context we'll Throw an ArticleNotFoundException. Using string interpolation we'll send a message saying, "The slug [slug go here] was not found."

Otherwise, we'll reuse our single Article Mapper method to create an Article and return it.

Let's give a run for the money and see if it works!

Since we don't have any articles we'll get a 422 with our message.

In the next demo (as promised) we'll begin creating Articles. I'll see you there!

 

I finished! On to the next chapter