On this part, we are going to work with the older section in this section, we are going to update
the UI, so the UI is rendered based on the user role and also in the older suppository or in the older
service.
So the user role is taken into consideration.
In Visual Studio, let us just go to this solution explorer and then in here go to data that services
and then go to the AI orders service.
And here we have get orders by user IDs.
Seeing that, I'll just change this name here to get orders by user I.D. and URL async.
See the change in here.
Now let us go to this solution explorer and then go to the order service.
You were going to get an error because we changed the method name.
So now this is going to be get orders by user ID and roll.
They sync and all this is going to take two parameters.
So we have the user I.D. The second parameter is going to be the string user role.
Then us also update the interface.
So here.
String user role, they'll see the trains in year and go back to the users service.
So new, we are currently getting all the orders filter by the user ID and then I'll just remove the
user I.D. because if the user signed in in our app is an administrator, the administrator will be able
to see all the orders across the app.
So new, we have all the orders across the app.
Now we're going to check for the roles.
If the user role.
Is different from the admin role than in you are going to add a filter, and if there is going to be
that the orders are equal to the orders appear.
But where then we are going to add a check for the user I.D. So then that to list so to list and then
we're just going to return the orders in here.
Now, let us see the genius and go to the index of you for the orders in here, we're going to add a
UI check.
So Sonia, we are going to type, if so, that if the user that identity that is authenticated and the
user that is enrolled and then the role is going to be admin, then we are going to display the user
double header.
How we are going to have the same conditions of control, see?
Down here where we currently have just a dash, so.
Now, let us just go to the survey explorer, just got the order items, so people do not.
That's first, remove all of these order items, I click, then delete.
Then there is going to lead the orders, so I'm just right click, then go to shop table data.
And then you let us delete the order, and you can see that the orders and you have the email set to
empty string with the user I.D. as well as.
To lead and then yes.
Now, let us refresh, you could see that we have already removed all the items from this table.
Now let us go back to the index view and then in here we are going to have that order that user and
we see that we only get the user I.D. So let us go to the older model.
In the models.
We have the order and only we have the user ID.
So then I'll just create a relation in here from order to the user table.
So let us create a new relation in here.
And for that, we're going to use so public.
Then application user is going to be the type and the name is going to be just the user and then we're
going to have get upset.
And then in here, we can also said that the foreign key for the user is going to be the user I.D. So
boring key that's import the namespace.
So the component model that there are patients that schema and before in key for the user is going to
be the user ID.
So another user?
Now, let us go back to the index view, and now here we have that user.
And then we're going to have the full name of the user.
Now let us see the changes and now let us go to the orders controller and then scroll down in here.
Now this will take two parameters.
The first one is going to be the user ID and the second parameter, the user role.
So string user role and you we are going to get the user ID and the user role value sign to get these
who we're going to use the user claim types.
So they're not just type in user data, find first.
And then as a barometer, I'm going to pass the claim type values that I want to get.
And in this case, I want to get the logged in user ID.
So for that, I'll just type claim types.
And let us import the namespace, there's the security that claims.
And then that the name identifier is used for the I.D. And then at the end, you can just type the value
or you can just remove the value from here and then replace the fine first with the find first value.
So now we have the user I.D. Now let us get the user role for that.
I'm just going to type in your user data, find the first value and the claim time now in your is going
to be so claim types.
Not the role.
Now let us just best submit to this method, this method got updates on get orders by user I.D. and
rolled a scene, so we have the user I.D..
Now we're going to also bears the user role.
OK, now let's see the changes that are scroll down and replace the empty strings that we have used
in the previous parts.
So scroll down in here.
You're going to see that you have an empty user I.D. and that is going to be user not.
Find first value.
The clean type is going to be claim types.
That's the name identifier, and next, we're going to also get the user email address or controversy.
And you're.
And now this is going to be the clean type email.
Let's see if we have other empty values I'm just searching for and the strengths and weaknesses we have
replaced all the values.
Now let us see all the changes.
And let us run this project.
Sinfonia, I'm just going to log in as a normal user for that, I'll use the service at Truepill dot
com and the password is the same subcortical one two three four and then question mark.
So let me just go to the orders, if I just go to the orders in here, you are going to see that I do
not have any orders and the user column is missing.
So let's go back to movies, and then I'll just add this movie to the car.
And then in here, just be with people.
Then from here, I'm going to use a test email address from my sandbox account.
So swamped, and then there's the best war.
And then log in, let me actually try this one two three four five six seven eight as the password and
I click the log in button.
Then in your scroll down and click the B Now button.
So you can see that the older was completed successfully and if you got two orders in here.
You are going to see that the order is in here.
Now let me log out and log in with another account, so I have the evidence at.
And then in here I have the new dot com.
The password is the same coding at once at three four and then a question mark.
Now if I go in here to the orders, so I have an order with another account, you are going to see that
the list is empty because I have not made any orders with this account.
So let me just go to the movies and then just add this one to the car, then be.
Now, since I logged in with the other PayPal account that's already logged in, but if you want, you
can just log out.
Then you let us provide the PayPal account credentials, so to aid.
And I click logging.
Then scroll down in here and click the B Now button.
And you can see that the order was completed successfully, and if you go to the user name and that
orders, you're going to see that the order is in here.
Now let us log out and logging as the administrator.
Now we are logged in as an administrator because we can also senior that the management option shows
up.
Now let us go to Hello admin.
And I click orders, you can see that we get an exception here, and the reason for that is because
the user is now.
So let me just stop Visual Studio and if you go to Desert Explorer, I then to the orders.
So people, you know, you can see that in the orders, we have the email and we also have the user
ID.
So let us just go to the orders service and then in here we include the order items.
We include the movie, but we do not include a user.
So for that, I just type include.
And this is going to include so and that goes through and that.
User.
Now let us save all the changes and then start this project one more time.
Now in here, let us log in as an administrator.
Now, let us go to the Helo admin user and then click orders.
And now you can see that you get all the orders that were processed in your system.
And you can see that for the first order with the idea for the user was over Stroup.
Yeah, that is the full name.
And for the second order with the ID five, the user was the bear you.
No.