1 00:00:00,240 --> 00:00:00,900 Hey guys. 2 00:00:00,900 --> 00:00:07,960 So this suit will go about adding our enrollments to our students detail page. 3 00:00:08,140 --> 00:00:08,830 No. 4 00:00:08,910 --> 00:00:14,840 An enrollment in fewer recall in our database comprises a student's I.T.. 5 00:00:14,940 --> 00:00:16,390 And of course I.T.. 6 00:00:16,530 --> 00:00:22,740 This serves to link a student to of course which means that you have many students being linked to many 7 00:00:22,740 --> 00:00:23,680 courses. 8 00:00:23,700 --> 00:00:30,870 The objective behind this is to ensure that when we click on the details page of a student we will see 9 00:00:30,870 --> 00:00:39,780 that this student is currently actively enrolled in X Y Z courses no as a quick recap. 10 00:00:39,870 --> 00:00:46,050 We know that we did our scaffolding exercise for our students and so we can create a new one in its 11 00:00:46,410 --> 00:00:48,960 view details and delete. 12 00:00:48,960 --> 00:00:56,740 Now if I click the Details button it will trigger a call to our action in our students controller. 13 00:00:56,810 --> 00:01:02,400 I set a breakpoint and I'm currently in debug mode and we just want to take a look at the object that 14 00:01:02,400 --> 00:01:05,430 comes back when we click details. 15 00:01:05,520 --> 00:01:13,170 So we're going to feature students and the idea that was passed in was two thousand and two and we can 16 00:01:13,170 --> 00:01:18,420 see that on was fetched because we did not get back an empty object. 17 00:01:18,460 --> 00:01:24,480 Now when we look in this object we see that we have first name last name middle name and we also have 18 00:01:24,480 --> 00:01:33,250 two enrollments so this student is currently associated with two courses in our enrollments table and 19 00:01:33,250 --> 00:01:40,960 which would quickly come out of debug mode and we take a look at our database to validate that clear. 20 00:01:41,320 --> 00:01:48,190 So in my object explore I'm just going to right click force and look at data. 21 00:01:49,090 --> 00:01:56,020 And here we have three courses Introduction to the C sharpies mining calculus and enrolments we can 22 00:01:56,020 --> 00:02:04,900 see that we have students with the I.D. two thousand and two enrolled to both courses with I.D. two 23 00:02:04,900 --> 00:02:05,940 and three. 24 00:02:05,980 --> 00:02:11,880 I'm not going to commit those to memory and obviously showing this to a human really does not work. 25 00:02:12,130 --> 00:02:19,570 So now we're going to see how entity framework makes it easy for us the data bind and display data that 26 00:02:19,570 --> 00:02:23,860 is not directly in our table inside of our view. 27 00:02:24,250 --> 00:02:30,790 So here we have our details view for the students and I'm just going to add some information to it's 28 00:02:30,790 --> 00:02:35,920 on censuses student details and I'll leave everything else as is. 29 00:02:35,920 --> 00:02:44,500 And underneath this last Dynamic link tag I'm going to start populating it with some code that is going 30 00:02:44,500 --> 00:02:51,160 to generate a table showing all of the enrollments for this students. 31 00:02:51,190 --> 00:02:58,210 Now this table is going to look rather similar to the one that we're used to from our index page. 32 00:02:58,240 --> 00:03:07,450 If you recall our index page has a table it has a top row with some headers and then it has a piece 33 00:03:07,450 --> 00:03:15,880 of code that is generating rows and columns based on the data coming back inside that model. 34 00:03:15,880 --> 00:03:19,250 Now we do have a model being passed into our details. 35 00:03:19,280 --> 00:03:23,140 But unlike our index page it is not our collection. 36 00:03:23,140 --> 00:03:30,580 It does however have a collection property in it in the form of enrollments which is what we just saw 37 00:03:30,730 --> 00:03:34,120 in debug mode in our students controller. 38 00:03:34,120 --> 00:03:43,120 So we're going to go about creating a table that will furnish rows and columns based on the data coming 39 00:03:43,120 --> 00:03:46,240 back from our enrollments collection. 40 00:03:46,300 --> 00:03:54,550 The first thing we need is our table and since we're using Bootstrap we can quickly me at this table 41 00:03:54,550 --> 00:04:02,290 look attractive by just adding a few tables classes size table and then I want it to be condensed as 42 00:04:02,290 --> 00:04:07,030 well as responsive. 43 00:04:07,340 --> 00:04:12,560 Next we generate our topmost rule which will have our table headers. 44 00:04:12,980 --> 00:04:20,540 So for our table headers I want the course title and I'm just going to control these and duplicate these 45 00:04:21,170 --> 00:04:25,450 and I would like the credits. 46 00:04:25,610 --> 00:04:33,560 I'm not sure if I need to sell or remove this makes those who want to utilize our reserve view and start 47 00:04:33,830 --> 00:04:40,880 dynamically generating rows according to what comes back in our enrollments property. 48 00:04:40,940 --> 00:04:51,850 So I want to use my sign and write the word for each open that's open we want var something I can file 49 00:04:51,850 --> 00:05:01,150 it enrollment in and then we have a keyword in C sharp called model. 50 00:05:01,320 --> 00:05:09,560 No this keyword embodies whatever data comes back inside of this model and it starts with a capital 51 00:05:09,620 --> 00:05:11,110 M someone's rights. 52 00:05:11,300 --> 00:05:14,110 Capital M model dot. 53 00:05:14,600 --> 00:05:21,080 And we're going to see our enrollments which if we look at the data carefully we see it is a collection 54 00:05:21,080 --> 00:05:29,670 type so for each of these I'm going to generate a rule so t are. 55 00:05:30,640 --> 00:05:39,960 And in this rule I want to follows and I'm just going to duplicate that inside this column. 56 00:05:39,990 --> 00:05:43,590 I always say that I don't like printing text without a tag. 57 00:05:43,620 --> 00:05:47,590 So I do a splitting whatever is going to go into this column instead of a PITA. 58 00:05:48,060 --> 00:05:55,500 And then I can just directly reference the enrollment using my at sign enrollment which is no my object 59 00:05:55,560 --> 00:05:57,050 of type enrollment. 60 00:05:57,120 --> 00:06:05,640 So an enrollment object will furnish the course the course I.T. enrollment I.D. the grade the students 61 00:06:06,150 --> 00:06:07,620 and students. 62 00:06:07,950 --> 00:06:09,230 So I'm going to say. 63 00:06:09,230 --> 00:06:13,260 Course since I want the course title I have to get it from the course object. 64 00:06:13,320 --> 00:06:19,500 So I go into the course object then use my dot operator once again and then I will be able to get the 65 00:06:19,500 --> 00:06:34,660 title I'll do the same for the next one and I will add enrollment dot course Dot's critics at the end 66 00:06:34,660 --> 00:06:41,830 of this exercise what we will have is a table being generated with all of these attributes with two 67 00:06:42,130 --> 00:06:50,920 columns one for course title 1 for credits and all of the related data for human readability so we can 68 00:06:50,920 --> 00:07:00,740 go ahead and go into debug mode and see our work no one our page loads we can see quite clearly the 69 00:07:00,740 --> 00:07:10,600 fruits of our labor that our table with our headers and we have human readable data being displayed. 70 00:07:11,870 --> 00:07:17,120 So instead of displaying just the ideas and instead of me having to go and write in our joints to get 71 00:07:17,120 --> 00:07:23,780 the actual data into the framework made it quite easy for us to just call on the data on demand. 72 00:07:24,350 --> 00:07:29,240 No I left out a column because the student knows what they're enrolled in but they do not know their 73 00:07:29,240 --> 00:07:30,050 grades. 74 00:07:30,050 --> 00:07:38,960 So I'm just going to head back over to Visual Studio and modify or view and I'm going to add a column 75 00:07:38,960 --> 00:07:47,790 for grades so I duplicated predicts and I'm just going to say creates or green and then I'm going to 76 00:07:47,790 --> 00:07:59,550 add another column inside this rule which is going to have the corresponding grid data now greed is 77 00:07:59,730 --> 00:08:01,980 inside of the enrollment model. 78 00:08:01,980 --> 00:08:08,580 So once I see enrollment then I have the property grade so I don't need to go into student or go into 79 00:08:08,580 --> 00:08:17,610 course I can just get grid right there from enrollments see this refresh and we will see our changes 80 00:08:18,530 --> 00:08:19,260 and there we go. 81 00:08:19,260 --> 00:08:21,480 So this student is fresh. 82 00:08:21,570 --> 00:08:26,800 They haven't gotten any grades as yet but they see what courses they're doing. 83 00:08:26,850 --> 00:08:31,650 And anybody who stumbles upon their profile will also see what courses they are doing. 84 00:08:33,980 --> 00:08:38,740 So this is a really quick way to get additional data into your view. 85 00:08:38,750 --> 00:08:41,230 I hope you understand the concept. 86 00:08:41,240 --> 00:08:48,910 And once you have a relationship you can either call on the collection of related data or call directly 87 00:08:48,910 --> 00:08:57,110 on the related data so you can go ahead and scuffled an enrollment situation and start creating enrollments 88 00:08:57,440 --> 00:09:05,780 where you associate students with courses and you can view the details of the enrollment with the course 89 00:09:05,780 --> 00:09:08,520 details as well as the student details. 90 00:09:08,630 --> 00:09:11,210 Are watching and I hope you have a good one.