1
00:00:00,590 --> 00:00:01,630
Hey guys.

2
00:00:01,640 --> 00:00:09,540
Last time we left off we were creating the control for our courses and using scaffolding to generate

3
00:00:09,570 --> 00:00:11,370
all of the views.

4
00:00:11,370 --> 00:00:18,590
I left you with the challenge to go ahead and create the scene control or end views for our students

5
00:00:18,590 --> 00:00:19,260
table.

6
00:00:19,380 --> 00:00:20,600
Someone to do that quickly.

7
00:00:20,610 --> 00:00:26,360
Just in case you probably didn't know what to do and I'll show you how simple it really is.

8
00:00:26,370 --> 00:00:36,870
So rightly or until the stable he go to and controller select MVC 5 controller with use using entity

9
00:00:36,870 --> 00:00:41,970
framework at then we select our model class.

10
00:00:41,990 --> 00:00:50,610
In this case it would be students then we see that most of the information is already populated because

11
00:00:50,610 --> 00:00:52,140
that's what we did last time.

12
00:00:52,140 --> 00:00:58,210
So Visual Studio is keeping track of our activities thus far making it easier for us to just move along.

13
00:00:59,040 --> 00:01:06,440
This time I will use song control our actions just to show you the slight difference in the core everything

14
00:01:06,440 --> 00:01:07,310
else checks out.

15
00:01:07,340 --> 00:01:17,990
So this week at at the end of the scaffolding exercise our new control is generated for students and

16
00:01:17,990 --> 00:01:25,190
we see that it looks very similarity to what we're used to from our courses on controller.

17
00:01:25,760 --> 00:01:32,600
Additionally if we look at our use table we will see that we have a new folder for students with the

18
00:01:32,600 --> 00:01:37,280
same set of views that were present in courses.

19
00:01:37,280 --> 00:01:43,550
Now if you take a closer look at your controller you see that you have a few new syntax words namely

20
00:01:43,640 --> 00:01:45,700
async and A.

21
00:01:45,740 --> 00:01:53,390
These are parts of the code that generated from when we said use async functions and pretty much async

22
00:01:53,390 --> 00:01:55,650
handle with our code but the end that's a low.

23
00:01:55,640 --> 00:02:03,720
Our methods still run asynchronously so this is in keeping with C sharps need for efficiency and loading

24
00:02:03,740 --> 00:02:07,700
multiple threads to run in one application.

25
00:02:07,820 --> 00:02:12,170
Outside of that we see that most of the code looks pretty much the same.

26
00:02:12,230 --> 00:02:22,350
If we compare it with our courses controller or no in this video we want to focus particularly on making

27
00:02:22,350 --> 00:02:25,590
modifications to our database as we go along.

28
00:02:26,070 --> 00:02:31,620
We're using a database base first coding Hutter and which means that our database would have existed.

29
00:02:31,620 --> 00:02:39,000
And then we build application on our own or our database is constantly evolving as we finish old and

30
00:02:39,060 --> 00:02:42,460
muffles the functions needed for our application.

31
00:02:42,510 --> 00:02:48,780
Now the challenge with this approach is that as we change our database we have to update our models

32
00:02:48,960 --> 00:02:51,460
and also update our code.

33
00:02:51,480 --> 00:02:53,920
Now I just generated this code.

34
00:02:54,030 --> 00:03:00,930
All of our views and this control are based on the fields that were present in our database tables.

35
00:03:00,930 --> 00:03:03,810
So if I look into the database

36
00:03:10,470 --> 00:03:19,020
I'll see that I have three fields student I.T. last name first name and enrollment dates which means

37
00:03:19,020 --> 00:03:24,560
that everything that would have been generated would have been generated around those particular fields.

38
00:03:24,600 --> 00:03:33,330
So if I take a look at my control view I'll see that I have a form generated for last name first name

39
00:03:33,720 --> 00:03:35,760
and enrollment dates.

40
00:03:35,860 --> 00:03:39,660
Now what if I needed to put in the student's middle name.

41
00:03:39,990 --> 00:03:42,270
I love that those the database initially.

42
00:03:42,450 --> 00:03:46,040
And though I need to include it in what I have going on.

43
00:03:46,130 --> 00:03:51,000
Someone to go into some views into my school's server object explore

44
00:03:54,670 --> 00:04:00,260
and drill down into my database instance and find my database school management.

45
00:04:00,270 --> 00:04:10,560
Evey table and make a modification to my student table so I right click and then click view designer

46
00:04:15,440 --> 00:04:20,230
I will then proceed to add the middle name column to this table.

47
00:04:20,360 --> 00:04:24,240
So I just come here in the middle name.

48
00:04:24,990 --> 00:04:28,910
I wanted to be a far Shah 50.

49
00:04:29,150 --> 00:04:30,240
Just like the other names.

50
00:04:30,240 --> 00:04:33,220
And then I think of dates to commit that change.

51
00:04:38,120 --> 00:04:39,900
Ones that obvious is done.

52
00:04:40,010 --> 00:04:47,030
I no need to update my database model to be cognizant of the fact that there is a new column in this

53
00:04:47,270 --> 00:04:56,060
table or in that particular class so if I bring up my DMX I'll see that the current students does not

54
00:04:56,060 --> 00:04:57,700
have a middle name column.

55
00:04:57,920 --> 00:05:05,210
So I right click in the empty space and I click Update model from database.

56
00:05:05,240 --> 00:05:13,920
This will then give me a little wizard I can go to refresh tables and then finish at the end of that

57
00:05:13,920 --> 00:05:18,900
process we see that we have middle name added here as a column.

58
00:05:18,900 --> 00:05:26,550
Now that leaves me to have two of these all of ordinary to use to know that there is a middle name that

59
00:05:26,550 --> 00:05:30,680
needs to be edited or handed in our creed.

60
00:05:30,890 --> 00:05:37,970
So this control shift and V and make sure that everything builds successfully after unsuccessful builds.

61
00:05:38,070 --> 00:05:42,750
Then I will go ahead and find my views that need to be edited.

62
00:05:42,780 --> 00:05:49,410
So go Don't say my views folder for students and then first edits are create view.

63
00:05:49,530 --> 00:05:55,770
So I need to pretty much replicates the structure that I have here for last name and first name and

64
00:05:55,850 --> 00:06:03,480
since the form is uncertain that they're all very similar data types and these are constructs I can

65
00:06:03,480 --> 00:06:11,430
just copy and paste this block of code and modify it so that we know you want middle.

66
00:06:11,490 --> 00:06:15,390
So this is generating a label for the first name.

67
00:06:16,510 --> 00:06:22,180
I just change this to middle name and you can see that the intelligence is picking up that there is

68
00:06:22,450 --> 00:06:26,470
indeed an impact column in the model cause name.

69
00:06:27,270 --> 00:06:37,210
So I just enter and then I will do this or edit for and also the validation message

70
00:06:41,590 --> 00:06:44,370
I will also need to do this for my edit page.

71
00:06:44,400 --> 00:06:51,620
I can just copy this considering that edit page looks very similarity to create page and I will just

72
00:06:51,620 --> 00:07:01,710
create some space here and paste the scene code and once again our model on our edit page of his students.

73
00:07:02,150 --> 00:07:10,010
And so it knows of the new property cause to make an additional step so that we can browse to this newly

74
00:07:10,010 --> 00:07:18,080
created index pitch is to modify our layouts and added in our virus so just click on courses on through

75
00:07:18,110 --> 00:07:22,250
the duplicate line and then I'll see students

76
00:07:25,860 --> 00:07:34,200
and also we will change the controller name to students we can see this and then go ahead and e-book

77
00:07:38,620 --> 00:07:44,200
once our window launches we will see that we have the link to our students space so we can click that

78
00:07:44,260 --> 00:07:50,280
and be navigated to our list of students we know that we didn't add anything to the database.

79
00:07:50,290 --> 00:07:56,410
And also you'll see that even though we added middle names to the model there is no middle name column

80
00:07:56,530 --> 00:07:58,060
being set up here.

81
00:07:58,060 --> 00:08:03,730
We did however modify the create it so we do have a middle name here on the page.

82
00:08:03,850 --> 00:08:12,280
And if I go ahead and create and then not do n that enrollment it allows us to type in our free text.

83
00:08:13,030 --> 00:08:19,660
So if you recall I was saying that there are certain situations where you may want to add custom controls

84
00:08:19,690 --> 00:08:27,850
or text box and edit for has some limitation Salud wanted probably changed data type associated with

85
00:08:27,850 --> 00:08:34,850
this input from text and set it to be time so we can at least get that big time picture or find a g

86
00:08:34,870 --> 00:08:38,950
query or JavaScript caught in the control to put there.

87
00:08:38,950 --> 00:08:44,680
We can do that at the later leads but for now I would just put generic dates

88
00:08:47,410 --> 00:08:55,340
and then click Create Now if we take a look at this we see that our newly created record is here once

89
00:08:55,340 --> 00:08:58,040
again on index we're not displaying the middle name.

90
00:08:58,040 --> 00:09:04,140
However if we click edits we will see that we have a slight anomaly with our program.

91
00:09:04,220 --> 00:09:10,560
We did not do enough to make sure that middle name was going to be populated upon trees.

92
00:09:10,610 --> 00:09:14,600
As a result though we added the text box to the edit form.

93
00:09:14,600 --> 00:09:20,360
There is no middle name displayed because there was no middle name committed to the death of these when

94
00:09:20,360 --> 00:09:21,830
we clicked create.

95
00:09:21,890 --> 00:09:25,470
So we still have a bit of work to do now going back to our code.

96
00:09:25,490 --> 00:09:31,730
We can come out of the book mode for a second and see what additional work needs to be done to ensure

97
00:09:31,730 --> 00:09:34,790
that our create function works.

98
00:09:34,790 --> 00:09:42,410
If we take a look at the data we will also see the writing our table and if they view data and we see

99
00:09:42,500 --> 00:09:47,160
that middle name was indeed and in fact sends across as a note.

100
00:09:47,390 --> 00:09:53,360
That is because at the time of creation even though we put the text and the controls there or the middle

101
00:09:53,360 --> 00:10:01,250
name we did not tell the control that each should indeed in fact look for a middle name when it is receiving

102
00:10:01,400 --> 00:10:03,310
data from our view.

103
00:10:03,710 --> 00:10:14,120
So if we take a look at our controller really quickly and we go to the create post function we see that

104
00:10:14,120 --> 00:10:19,940
we have something here that is fine include and we have some parameters

105
00:10:22,330 --> 00:10:31,720
do n students i.e. the last name first name enrollment date and no middle name know what is happening

106
00:10:31,720 --> 00:10:39,010
in this include equals was followed by this string of fields coming from our student model is we are

107
00:10:39,100 --> 00:10:49,110
looking for specific properties from this class that should be included when we compile or objects and

108
00:10:49,150 --> 00:10:50,170
see if changes.

109
00:10:50,590 --> 00:10:55,900
So if I made the modification here that we should take students any last name first name enrollment

110
00:10:55,930 --> 00:10:58,960
it and tack on middle

111
00:11:01,540 --> 00:11:09,010
name and this part is case sensitive so please be sure to write in the same way that the property appears

112
00:11:09,010 --> 00:11:19,330
in the class and for the edits we can also go ahead and include the middle name and go into debug mode

113
00:11:19,360 --> 00:11:23,760
and that tend to add another students then you should no longer have this problem.

114
00:11:23,980 --> 00:11:32,410
So let us try knowing debug modem with attempts to add another then I click creates and then we have

115
00:11:32,500 --> 00:11:34,960
a second student's record.

116
00:11:35,920 --> 00:11:45,120
Now if I look at the edits then you will see our value coming back unlike our first one where there

117
00:11:45,120 --> 00:11:47,450
was no value committed to the data.

118
00:11:47,460 --> 00:11:54,000
Now if we look at the details page to see all of what we need to see about the students details really

119
00:11:54,000 --> 00:11:58,210
and truly should list every single thing above the students here.

120
00:11:58,320 --> 00:12:03,920
Note there is no middle name so we still have a bit of work to do to get literally into up in our D

121
00:12:03,980 --> 00:12:05,220
fields page.

122
00:12:05,280 --> 00:12:13,410
So I just quickly go over the details and we're still in debug mode find the details view and we can

123
00:12:13,410 --> 00:12:20,010
see here that details page looks a bit differently from the other pages it is predominantly using the

124
00:12:20,010 --> 00:12:25,950
issue demo helper function for Display display name for and display for.

125
00:12:26,070 --> 00:12:32,970
So we can just take this and replicate this kind of logic and insert middle layer.

126
00:12:33,630 --> 00:12:44,430
So I just put middle name and middle name C and then refresh or page and there we go.

127
00:12:44,520 --> 00:12:50,110
Last name first name and our new additions to the family middle name.

128
00:12:50,160 --> 00:12:55,710
Also we have enrollment dates there are things you can do is that the goal is to make our dates more

129
00:12:55,710 --> 00:13:03,960
attractive possibly easier way to have accommodated all of these changes to our database and our subsequent

130
00:13:03,960 --> 00:13:11,700
control and view code would have been to regenerates our controller and views based on the changes in

131
00:13:11,700 --> 00:13:12,630
our model.

132
00:13:12,630 --> 00:13:18,630
The danger to this however is that any changes you would have made would have been discarded and replaced

133
00:13:18,660 --> 00:13:20,320
with the generic code.

134
00:13:20,370 --> 00:13:26,100
So be very careful when you are going to make changes to your database and be cognizant of the fact

135
00:13:26,100 --> 00:13:33,200
that you probably want to do it manually so maintain whatever code has preceded this gene.

136
00:13:33,210 --> 00:13:33,840
Anyhow.

137
00:13:33,840 --> 00:13:38,400
Thank you for tuning in and I do hope you found value this lesson.

138
00:13:38,400 --> 00:13:39,280
See you next time.
