Outline

Demo: Add Comments To Article

I'm sure by now you know the routineā€¦

Open the Conduit.Api Project, expand Controllers, open the Articles Controller and expand the Delete Article method.

Once you expand the method we'll Right-Click on the AddCommentToArticleAsync method of the Article Repository and Go To Implementation.

Again, we need the Editorial from the database to begin. Using the First or Default Async Method I'll have the Context get the me the Editorial with the matching Slug.

We'll fix the error by making the method async.

If the Commentary object is not found we'll throw the famous Article Not Found Exception with the message indicating so.

Otherwise, let's get the Logged In User so we can create a new Commentary object. We'll initialize the Body, PersonId and the EditorialId.

We'll have the Context add it as a Commentary and have it saved to the database.

We'll need to create a Comment object but because we already have a comment parameter we'll need to come up with a new name. We can use retComment to avoid the name collision.

We'll also need to map the Author information with the Person from the Account object.

Return retComment and call it complete!

Let's run the app so we can test the featureā€¦

I'll login as someone other than the author of the Article so I can comment using a different identity.

Let's get a list of available Article Slugs so we can pick one to comment on.

We'll put some cheesy comment and execute it.

Aw! We get a 500 Error. Once again I created the error on purpose so I can give you an exercise. What fun would it be if I created perfect code every time without having anything for you to fix?

I happen to know what the problem is just by looking at the error.

As an exercise I'll let you fix the problem. Remember to use the debugger if you have to.

In the next video I'll show you how I fixed it. See you there!

 

I finished! On to the next chapter