1 00:00:00,860 --> 00:00:06,890 Hey guys in this video we're going to start looking at building functionality that will help us to manage 2 00:00:06,950 --> 00:00:08,370 our users. 3 00:00:08,460 --> 00:00:12,370 Now up until now we would have hardcoded one user. 4 00:00:12,380 --> 00:00:15,620 We call it admin and we hardcoded the password. 5 00:00:15,620 --> 00:00:21,050 But in reality we're not going to expect that every time we have a user or when we have multiple users 6 00:00:21,050 --> 00:00:27,650 for our application that the user is going to have to bring up the database and hardcoded and find the 7 00:00:27,650 --> 00:00:32,060 hashing version of the password like what we did and manually put those in. 8 00:00:32,060 --> 00:00:33,110 That's not the reality. 9 00:00:33,110 --> 00:00:39,500 What we want to do is create an interface where the user can click and preferably the admin user of 10 00:00:39,500 --> 00:00:45,980 course can click on users get to a similar management window like we've done for vehicle listing and 11 00:00:45,980 --> 00:00:50,210 for entire records one that lists sold off the users in the database. 12 00:00:50,240 --> 00:00:52,630 Who would want to display their passwords of course. 13 00:00:52,820 --> 00:01:01,430 And that allows them to maybe deactivate a user versus adding another user and maybe resetting a password 14 00:01:01,460 --> 00:01:02,480 or something like that. 15 00:01:02,480 --> 00:01:07,970 So those are the functionalities that we would love to put in based on what is on the screen. 16 00:01:07,970 --> 00:01:16,130 However I already modified my main window to have the button manage users and I already created the 17 00:01:16,190 --> 00:01:22,880 new form manage user so you can pause the video right here and go ahead and add this new menu option 18 00:01:22,970 --> 00:01:26,720 and the new form and write the code that would launch the window. 19 00:01:26,780 --> 00:01:28,500 You can pause the video try it yourself. 20 00:01:28,490 --> 00:01:35,960 What I'm still going to go through and show you exactly what I did so in the main window design I just 21 00:01:35,990 --> 00:01:42,020 added a new option manage users I didn't put anything underneath it because I want this option to just 22 00:01:42,020 --> 00:01:47,240 come up with the ah when clicked rather come up with the new window to manage a user. 23 00:01:47,240 --> 00:01:54,110 So I added that new menu item and that I double clicked it to give us the the Click event and then in 24 00:01:54,110 --> 00:01:58,780 the click event I did the usual thing you could even just look at previous code that we've written. 25 00:01:59,150 --> 00:02:05,300 I didn't put in the check to see if the windows open already so I can put in that check just to make 26 00:02:05,300 --> 00:02:09,210 sure that it won't launch twice. 27 00:02:09,230 --> 00:02:09,530 All right. 28 00:02:09,830 --> 00:02:15,470 So I'm checking if it is open and I'm checking if money to users is open. 29 00:02:15,620 --> 00:02:25,400 Then if it is not open sorry then you can launch so that we will only get one instance of manage users. 30 00:02:25,400 --> 00:02:30,500 I already went through and added the new form and remember to add a form you go to solution explorer 31 00:02:30,500 --> 00:02:38,330 you right click you say ad and then you select form and then you go ahead and add this new form to your 32 00:02:38,330 --> 00:02:38,890 project. 33 00:02:38,900 --> 00:02:42,250 I call it manage users if you want to change the name. 34 00:02:42,260 --> 00:02:48,710 That's fine as long as you know what name you used and that the name is relevant. 35 00:02:48,710 --> 00:02:53,260 I'm just going to make some cosmetic changes because you can see that the window title is. 36 00:02:53,690 --> 00:02:59,870 Well I didn't change it's on with the change of text to manage space users so it's more readable more 37 00:02:59,870 --> 00:03:02,480 user friendly in its appearance. 38 00:03:02,480 --> 00:03:07,930 And then on this forum we're going to have pretty much the same thing that we had on the other forums 39 00:03:07,940 --> 00:03:14,380 so I'll just go back to manage maybe manage vehicle listing that design our entire records whichever 40 00:03:14,390 --> 00:03:20,060 one because we want to have the same kind of labels we have that grid I can actually remove this refresh 41 00:03:20,060 --> 00:03:27,150 button but just for now we'll have the label the refresh button the grid and all of the buttons. 42 00:03:27,150 --> 00:03:35,980 So I'm just going to copy all of these controls and then go over to my new window manage users and paste 43 00:03:35,980 --> 00:03:44,620 them and then expand the window as much as I need to to facilitate these new controls. 44 00:03:44,680 --> 00:03:47,230 Just do that quickly. 45 00:03:47,230 --> 00:03:47,820 All right. 46 00:03:47,860 --> 00:03:56,620 Rearrange them and then let me change the text here from management records to manage users and then 47 00:03:56,620 --> 00:04:04,650 because I'm using this code of course the names what is presented on each button one that takes and 48 00:04:04,650 --> 00:04:06,370 then two the names need to be changed. 49 00:04:06,370 --> 00:04:11,600 So this one needs to say add new user instead of record. 50 00:04:11,640 --> 00:04:12,300 Right. 51 00:04:12,310 --> 00:04:18,460 And then I'm going to change the button name from beat in AD record to beat an AD user someone to go 52 00:04:18,460 --> 00:04:20,860 through and do that for each of the buttons. 53 00:04:20,860 --> 00:04:24,510 So let me just do them quickly while on screen. 54 00:04:24,820 --> 00:04:27,190 So that's at its record. 55 00:04:27,190 --> 00:04:31,990 And then that's going to be beaten at its user or you know what. 56 00:04:31,990 --> 00:04:37,750 For edit user I'm actually just going to say reset password so we're changing this functionality from 57 00:04:37,810 --> 00:04:45,740 editing the user to reset because for the purpose of this function or this application or other way 58 00:04:45,890 --> 00:04:51,190 you just want the admin user to be able to reset user's password. 59 00:04:51,190 --> 00:04:54,250 That's the only editing quote unquote that should be able to happen. 60 00:04:54,250 --> 00:04:54,520 Right. 61 00:04:55,120 --> 00:05:00,610 And then I went to change delete to the Activate user. 62 00:05:00,640 --> 00:05:07,210 So instead of delete user we're going to do deactivate and I'll show you exactly how we can facilitate 63 00:05:07,270 --> 00:05:09,620 the activation versus deletion. 64 00:05:09,620 --> 00:05:09,910 All right. 65 00:05:10,300 --> 00:05:15,400 So Beatty in the TV user All right. 66 00:05:15,820 --> 00:05:21,280 And then no that we change those old I can just do my click events just little click each button to 67 00:05:21,280 --> 00:05:25,280 get those click events and we close that window for No I don't need it. 68 00:05:25,410 --> 00:05:30,400 They will click reset password and deactivate user. 69 00:05:30,400 --> 00:05:30,630 All right. 70 00:05:30,640 --> 00:05:36,130 So now that we've done those cosmetic things at a forum I also want to make some changes to the database 71 00:05:36,130 --> 00:05:37,180 table. 72 00:05:37,180 --> 00:05:44,110 So I brought up my management studio Cisco management studio logged into my instance went into my database 73 00:05:44,110 --> 00:05:49,420 which just car rental and they interact take to my table that said and chose design. 74 00:05:49,420 --> 00:05:49,810 Sorry. 75 00:05:49,840 --> 00:05:56,590 So now I'm in the design of the user stable and I'm going to do a few modifications while one modification 76 00:05:56,590 --> 00:06:00,400 really and that is to set an active flag. 77 00:06:00,400 --> 00:06:04,870 So what I'm going to be doing here is I'll be seeing is active. 78 00:06:05,070 --> 00:06:05,410 All right. 79 00:06:05,410 --> 00:06:10,540 And then based on the naming convention I've been using up until this point any time you see is something 80 00:06:10,540 --> 00:06:16,090 that me seeing I want a boolean in school boolean will be beat. 81 00:06:16,210 --> 00:06:18,920 So the data type for boolean here is it. 82 00:06:19,570 --> 00:06:20,080 And then. 83 00:06:20,080 --> 00:06:23,440 So this is going to say is the person active yes or no. 84 00:06:23,470 --> 00:06:25,780 So if it's true then that person is active. 85 00:06:25,850 --> 00:06:31,870 If it's false as the person isn't active and I will not alone know here either but then there might 86 00:06:31,870 --> 00:06:38,410 be I'm going to get an error if I try to save while not following and also alone no and save and then 87 00:06:38,410 --> 00:06:40,380 I go back and make a modification. 88 00:06:40,390 --> 00:06:46,580 The reason for the error would be that I already have a user that does not have any data for this. 89 00:06:46,570 --> 00:06:52,000 So if I chose to not Lowenthal then it would have been a problem because then I already have a record 90 00:06:52,000 --> 00:06:52,720 that has not. 91 00:06:52,720 --> 00:06:57,430 So then it would be a data type or constraint Mismatch right. 92 00:06:57,430 --> 00:07:04,480 So moving on I have the user and I'm going to add another table so I'm directly tables go to new go 93 00:07:04,480 --> 00:07:10,900 to table and then this one I'm going to call the rules somewhat of I.D. And then this is going to be 94 00:07:10,900 --> 00:07:19,890 our primary key which is identity so it auto increments and then I'm going to have name and name is 95 00:07:19,890 --> 00:07:21,510 just going to be via char 50. 96 00:07:21,510 --> 00:07:24,840 So name here represents the name of the rules. 97 00:07:24,840 --> 00:07:30,660 So when we talk about rules I mean just save the table and see rules. 98 00:07:31,440 --> 00:07:33,240 So we talk about rules. 99 00:07:33,240 --> 00:07:34,080 It means that. 100 00:07:34,080 --> 00:07:40,740 What role does this user play in this application is this person an admin is this person maybe a data 101 00:07:40,740 --> 00:07:41,850 entry clerk. 102 00:07:41,940 --> 00:07:45,150 Is this person maybe just a supervisor you know. 103 00:07:45,180 --> 00:07:50,910 And then based on the role that they play we can determine what functionality they have access to or 104 00:07:50,910 --> 00:07:53,100 what actions they can complete. 105 00:07:53,100 --> 00:07:53,940 All right. 106 00:07:53,940 --> 00:08:00,900 So I have users I have rules and then I have to have another table that links the to someone to create 107 00:08:00,900 --> 00:08:07,520 another table and then I'm going to give this one an idea and then this is going to be the auto incrementing 108 00:08:07,580 --> 00:08:08,390 I.D.. 109 00:08:08,900 --> 00:08:13,670 And this is really going to be what we'll call a linker table because we're going to do a Many to Many. 110 00:08:13,670 --> 00:08:22,170 Meaning many users may have many rules someone of a user I.D. and then this is going to be INT. 111 00:08:22,290 --> 00:08:25,620 And then I went to have a rule I.D. which is also INS. 112 00:08:25,680 --> 00:08:26,400 All right. 113 00:08:26,400 --> 00:08:32,790 So this means that any user right now live admin and that I'd been using as an idea of one and then 114 00:08:32,790 --> 00:08:37,230 let's sandwich of two rules someone to have admin and I'm going to have user. 115 00:08:37,260 --> 00:08:43,350 So you have an odd mineral an app or a regular user rule or maybe a kind of three one four supervisors 116 00:08:43,380 --> 00:08:45,050 whatever the case may be. 117 00:08:45,090 --> 00:08:53,910 But the point is that when I user with whatever I.D. gets assigned or an record goes into this table 118 00:08:53,910 --> 00:09:00,630 or other with articulate user idea and a particular rule I.D. That is association between this particular 119 00:09:00,630 --> 00:09:02,580 user and that particular role. 120 00:09:02,580 --> 00:09:03,170 All right. 121 00:09:03,170 --> 00:09:11,360 So I want to see this table on call it user rules next I'm going to have to create a relationship between 122 00:09:11,630 --> 00:09:17,830 the user rules table and the other two tables so because of user I.D. That's a foreign key to the user's 123 00:09:17,860 --> 00:09:19,870 tables have to go click. 124 00:09:19,880 --> 00:09:21,950 Sorry I did that kind of quickly let me do it again. 125 00:09:21,960 --> 00:09:24,530 Have to right click in the design view. 126 00:09:24,710 --> 00:09:27,670 Then go to relationships and then. 127 00:09:27,680 --> 00:09:29,500 Well it would have been blank. 128 00:09:29,510 --> 00:09:36,620 So I click ad and then I'm going to choose the tables and column specifications click this ellipsis 129 00:09:36,620 --> 00:09:42,830 button over to the right hand side and then I'm going to say my primary key table is the user stable 130 00:09:43,280 --> 00:09:47,120 and I want the I'd call home from this primary table. 131 00:09:47,360 --> 00:09:49,940 And then I want to link it to the foreign key. 132 00:09:49,940 --> 00:09:51,430 Call the user I.D.. 133 00:09:51,650 --> 00:09:53,880 So that creates that constraint there. 134 00:09:54,050 --> 00:09:59,480 And then I'll do the same thing just click Add create another one using the ellipses. 135 00:09:59,480 --> 00:10:07,670 And then this one will before the rules table with the idea connected to the role i.e. the column in 136 00:10:07,670 --> 00:10:10,570 the user rules table then click Okay. 137 00:10:10,730 --> 00:10:13,340 Click close and then I can save. 138 00:10:13,400 --> 00:10:15,470 And then it will take awhile. 139 00:10:15,890 --> 00:10:20,330 Then it will make sure that I know that I'm able to modify these three tables I can click. 140 00:10:20,330 --> 00:10:21,250 Yes. 141 00:10:21,350 --> 00:10:21,740 All right. 142 00:10:21,740 --> 00:10:27,370 And once those changes are saved then we can go both to putting in some manual changes. 143 00:10:27,380 --> 00:10:34,350 So the fact is that the application is yours you can always create your own management screens for whatever 144 00:10:34,360 --> 00:10:34,740 data. 145 00:10:34,750 --> 00:10:39,740 It is like we've been doing so far we've done it for the managing of the car into our records we've 146 00:10:39,740 --> 00:10:41,670 done it for the management of the cars. 147 00:10:41,750 --> 00:10:46,820 We can do it for the users it's up to you to know how granular you want to get with that because then 148 00:10:46,850 --> 00:10:50,360 some people allow you to create your own rules in the back. 149 00:10:50,360 --> 00:10:57,590 And what in the application itself and then they allow you to assign users to the different rules for 150 00:10:57,590 --> 00:10:58,250 yourself. 151 00:10:58,250 --> 00:10:58,550 Right. 152 00:10:58,550 --> 00:11:02,080 So I will show you how to do the assignment. 153 00:11:02,210 --> 00:11:07,550 But then using the same principles if you want you can allow them to create the rules in the application 154 00:11:07,550 --> 00:11:08,290 itself. 155 00:11:08,450 --> 00:11:12,210 But for this course I'm going to just do it manually. 156 00:11:12,230 --> 00:11:16,580 So I would love for you having done it in the application. 157 00:11:16,580 --> 00:11:19,130 That's my challenge to you that you share your code with me. 158 00:11:19,130 --> 00:11:22,300 I mean I would love to see how it is that you accomplished it. 159 00:11:22,460 --> 00:11:26,500 And we can you know learn together but for now I'll just do it manually. 160 00:11:26,530 --> 00:11:33,800 So I'll right click on the rules go to edit top 200 now I know that I only want two rules in my application. 161 00:11:33,800 --> 00:11:38,150 You might be building your application for a bigger context than mine. 162 00:11:38,150 --> 00:11:46,730 But then within this context I only want an administrator role so I can have an administrator user or 163 00:11:46,730 --> 00:11:51,960 many administrator users which you want to of course you know be careful with that. 164 00:11:52,130 --> 00:11:59,160 And I'm going to have a data entry clerk right. 165 00:11:59,250 --> 00:12:05,330 As a matter of fact I'm going to extend this table a bit and I'm going to put you in another column. 166 00:12:05,340 --> 00:12:08,360 So I only have name and I.D.. 167 00:12:09,000 --> 00:12:13,320 Let me go back to the design and then when to put in sharp name. 168 00:12:13,320 --> 00:12:14,030 All right. 169 00:12:14,190 --> 00:12:24,240 So would you put in sharp name and this one will also be in via char 50 can be var char 50 various very 170 00:12:24,240 --> 00:12:25,840 similar data types. 171 00:12:25,840 --> 00:12:26,310 What. 172 00:12:26,790 --> 00:12:34,440 But it's in virtue of Arch I act very similarity so it's okay if you had either one all right. 173 00:12:34,470 --> 00:12:36,450 So for rules I mean get back to this. 174 00:12:36,450 --> 00:12:39,030 So let me just close this design view. 175 00:12:39,030 --> 00:12:46,960 Go back to rules at it top 200 and then for the sharp names I'm going to put in like a shark put name. 176 00:12:46,980 --> 00:12:54,110 So literally of the name administrator but then the short name could be I'd mean the shortening for 177 00:12:54,120 --> 00:13:01,000 data entry clerk could be just clerk and then maybe you just have you only. 178 00:13:01,020 --> 00:13:08,040 So this person wouldn't have any access to actually change data to actually take add or delete or edit 179 00:13:08,040 --> 00:13:08,630 or anything. 180 00:13:08,630 --> 00:13:15,360 That so view only will only be able to click and see the data that is in the greater it so just save 181 00:13:15,360 --> 00:13:16,550 you. 182 00:13:16,560 --> 00:13:22,020 All right so we have the roll names and we have the short names and you'll see the relevance of the 183 00:13:22,260 --> 00:13:24,390 short names in a few. 184 00:13:24,390 --> 00:13:26,360 So those are my rules. 185 00:13:26,400 --> 00:13:27,360 All right. 186 00:13:27,360 --> 00:13:33,120 And I'm going to do one more manual addition here so I'm doing these manual editions because I already 187 00:13:33,120 --> 00:13:35,760 have the data and I want to show you how it will work. 188 00:13:35,760 --> 00:13:37,450 Before we start building it's old. 189 00:13:37,470 --> 00:13:38,180 Right. 190 00:13:38,220 --> 00:13:45,360 So the user I.D. here would be the user I.D. for the existing user which let me just confirm what that 191 00:13:45,360 --> 00:13:45,520 is. 192 00:13:45,510 --> 00:13:55,100 So if I select up to sorry to top 1000 rules then I see my one admin user and I.D. Here is one I see 193 00:13:55,110 --> 00:13:56,510 is active is no. 194 00:13:56,520 --> 00:13:56,880 All right. 195 00:13:56,900 --> 00:14:04,240 So the user I.D. Here is one and then the role ie the for administrator. 196 00:14:04,420 --> 00:14:07,950 Let we just select top two on those and again would be one. 197 00:14:07,950 --> 00:14:16,160 So that means in user rules user I.D. one has rules I.D. one and I just change line to commit that. 198 00:14:16,260 --> 00:14:23,490 And so we know that our user rule our admin is in the user or administrator with the short name admin 199 00:14:24,830 --> 00:14:27,820 not oh we've made those modifications. 200 00:14:27,880 --> 00:14:31,200 Oh one more modification on my but I skipped that part. 201 00:14:31,300 --> 00:14:37,750 I need to let the administrator user know that e he is active right. 202 00:14:37,790 --> 00:14:39,670 So use going or right click. 203 00:14:39,670 --> 00:14:47,230 Users go to edit top 200 rules and then change is active to 1. 204 00:14:47,330 --> 00:14:52,630 Right so 1 or 0 in database if you say a 1 it's true if you say 0 it's false. 205 00:14:52,630 --> 00:14:52,940 Right. 206 00:14:52,960 --> 00:14:58,630 So it will always ritualistic and write the word jury can just assign the value 1 and the beat will 207 00:14:58,630 --> 00:15:00,830 automatically know what a straw falls. 208 00:15:00,840 --> 00:15:01,130 All right. 209 00:15:01,750 --> 00:15:08,860 So the user admin user is active so let's minimize all right. 210 00:15:08,860 --> 00:15:14,150 And then in our projects we need to update our data context diagram. 211 00:15:14,170 --> 00:15:16,800 So I need to go over to my e DMX there. 212 00:15:16,810 --> 00:15:22,330 GRAHAM And then we see all of the the three tables that we left here with. 213 00:15:22,340 --> 00:15:26,920 But we need to make some modifications so I didn't make any modifications of these two. 214 00:15:26,960 --> 00:15:32,900 I'm not going to delete those but the ones I made on my modification to well the one I made a modification 215 00:15:32,900 --> 00:15:35,550 to would be user so I'm just removing user. 216 00:15:35,550 --> 00:15:41,120 So I just clicked it and emperors delete on my keyboard is confirming I say yes I do want to delete 217 00:15:41,120 --> 00:15:47,780 it and then I'm went to right click and then updates model from database which is then going to problem 218 00:15:47,780 --> 00:15:48,260 to me. 219 00:15:48,260 --> 00:15:51,490 Do you want to add new tables I'm just going to click tables. 220 00:15:51,490 --> 00:15:56,350 I know I added a few tables just now and then click finish and then give it some time. 221 00:15:56,780 --> 00:16:01,760 And once that operation is done then you will see your new tables appearing. 222 00:16:01,760 --> 00:16:09,080 So I created three or two new tables and made an adjustment to the user table and you see the relationships 223 00:16:09,080 --> 00:16:09,960 that exist. 224 00:16:10,130 --> 00:16:15,170 So both user Andrew and I related to the user rule table. 225 00:16:15,260 --> 00:16:22,070 I know that to have the ability to determine what role the user is in at the time off log in. 226 00:16:22,070 --> 00:16:26,610 I need to be able to see which rule this person is inside at the time. 227 00:16:26,610 --> 00:16:34,310 When I confirmed the person so we know that we have our logging farm that handles that logic and as 228 00:16:34,310 --> 00:16:37,670 soon as I find it here's my log in form right. 229 00:16:37,670 --> 00:16:41,530 So we know that on the button click event where we said log in. 230 00:16:41,690 --> 00:16:48,410 We did that hashing we computed the hash and then we went ahead and said gets us the user is there the 231 00:16:48,410 --> 00:16:49,140 user. 232 00:16:49,280 --> 00:16:52,100 And then the user would've said yes or no. 233 00:16:52,100 --> 00:16:52,840 Right. 234 00:16:52,850 --> 00:17:00,590 So when they said yes right then we would have called the main window passing in an instance of the 235 00:17:00,590 --> 00:17:02,220 log in window etc.. 236 00:17:02,300 --> 00:17:10,110 Now we need to extend this functionality because no I need to know what role this user is in. 237 00:17:10,280 --> 00:17:10,700 All right. 238 00:17:10,990 --> 00:17:15,260 So I already have the user object right. 239 00:17:15,290 --> 00:17:21,710 I already know the user object but remember that I had said that once you get the user object or once 240 00:17:21,710 --> 00:17:27,730 you get an object from the database you can actually access the related data directly from this object. 241 00:17:27,860 --> 00:17:38,260 So I can actually declare a variable here and say var url All right roll is equal to and then I can 242 00:17:38,260 --> 00:17:41,450 say user because I just got user here. 243 00:17:41,770 --> 00:17:44,850 So and then if it's in the L's that means the user is not known. 244 00:17:44,860 --> 00:17:50,810 So that means that user presumably will have a rule recording the user rule table. 245 00:17:50,830 --> 00:18:00,970 So if I say user dot then you're going to notice that I have access to all my above say I broke my own 246 00:18:00,970 --> 00:18:01,590 rule. 247 00:18:01,690 --> 00:18:07,400 Every time you make an update to your diagram you should build the site. 248 00:18:07,480 --> 00:18:10,510 Skip that step so you can see the side effects of this. 249 00:18:10,510 --> 00:18:16,210 I'm glad this happened so when I just typed that code let me just undo and go right back. 250 00:18:16,240 --> 00:18:21,550 So when you fail to build or fail to build the diagram on or near it it's a write code you're going 251 00:18:21,550 --> 00:18:27,070 to see that the code may not reflect the changes sermon without we had added at least the one you call 252 00:18:27,070 --> 00:18:28,930 them to our user table. 253 00:18:28,930 --> 00:18:33,430 So that means our user object should have access to that new column at least. 254 00:18:33,430 --> 00:18:39,190 So we're still seeing the all the same three columns that we had before we changed the database before 255 00:18:39,190 --> 00:18:42,490 we updated our diagram all because we didn't build. 256 00:18:42,490 --> 00:18:49,660 So what I'm going to do is a comment on this line and then do control shift and B and allow the project 257 00:18:49,660 --> 00:18:51,160 to rebuild. 258 00:18:51,160 --> 00:18:53,760 All right so our build is completed. 259 00:18:53,770 --> 00:18:59,860 And let me just on this line and then control and shift after the full stop just to see. 260 00:18:59,980 --> 00:19:00,960 And there we go. 261 00:19:00,960 --> 00:19:02,270 So we're seeing here. 262 00:19:02,320 --> 00:19:11,110 I d I d active sorry is active password user name and then we're seeing user rules so that is our relationship 263 00:19:11,140 --> 00:19:11,440 right. 264 00:19:11,890 --> 00:19:19,180 So remember I said that once something is related to r a foreign T for a table is in another table then 265 00:19:19,180 --> 00:19:22,030 we can automatically access the list. 266 00:19:22,180 --> 00:19:22,490 All right. 267 00:19:22,510 --> 00:19:30,570 So far a car into the rental record is associated with one car but our car is associated with many records. 268 00:19:30,640 --> 00:19:36,690 So if you have a car object then you can see all of the records that are associated with it. 269 00:19:36,700 --> 00:19:42,550 So in this case we have the user and we can see all of the roles that this user might have. 270 00:19:42,640 --> 00:19:50,110 So it could be a situation where you have multiple rules you have multiple users one user can have many 271 00:19:50,110 --> 00:19:56,710 rules that is the situation that we facilitated in our database design a simpler way to do that could 272 00:19:56,710 --> 00:20:03,010 have been to just add rule our own name to the user but then that's kind of limiting because then if 273 00:20:03,010 --> 00:20:07,930 you modify the rule or you want a new rule then you're going to have to go through every single user 274 00:20:08,080 --> 00:20:11,070 with that rule and make a modification right. 275 00:20:11,140 --> 00:20:17,530 So if we have that Linker table then it's easier to manage the different rules the different users and 276 00:20:17,530 --> 00:20:19,430 which rule that user might have. 277 00:20:19,630 --> 00:20:23,230 But within the context we only have one rule per user. 278 00:20:23,250 --> 00:20:29,440 So even though we're facilitating that user can have multiple rules in our context in this application 279 00:20:29,440 --> 00:20:34,070 we're only facilitating one rule per user. 280 00:20:34,090 --> 00:20:34,420 All right. 281 00:20:34,750 --> 00:20:41,110 So I can say user dot and then I'm getting user rules but I only want the one rule that this person 282 00:20:41,110 --> 00:20:51,480 has so I can tell safe dot and then use the link to get the first R default rule that is associated 283 00:20:51,720 --> 00:20:53,670 with this user. 284 00:20:53,660 --> 00:20:55,510 So first are defaults. 285 00:20:55,560 --> 00:21:00,480 No I don't need a lambda expressions up here I use a lambda expression because I had a condition upon 286 00:21:00,480 --> 00:21:05,880 which I wanted the first or I wanted the first record that met this condition. 287 00:21:05,880 --> 00:21:09,470 In this situation I don't have any condition I just want the first one. 288 00:21:09,510 --> 00:21:16,260 So I'm saying get me the user and the list quote unquote list off rules and get me the first one because 289 00:21:16,260 --> 00:21:21,930 we know that we only have one rule anyway when we get the first one then we're getting the one roll. 290 00:21:21,930 --> 00:21:22,530 All right. 291 00:21:22,650 --> 00:21:23,600 So that is a nice. 292 00:21:23,590 --> 00:21:30,890 Quickly it does get the one rule that this user has and this is embodied in the object called roll. 293 00:21:31,050 --> 00:21:31,780 All right. 294 00:21:31,860 --> 00:21:32,400 No. 295 00:21:32,430 --> 00:21:36,510 When we look at rule it is going to be of type user rules. 296 00:21:36,510 --> 00:21:44,940 So then I can use rule and say Dot and I can get the details on the rule are the details on the user 297 00:21:45,130 --> 00:21:53,640 that this record is associated with second C rule DOT rule and then I can get the name or the Sharpe 298 00:21:53,670 --> 00:21:58,440 name and the reason that created a short name is that it would be much easier to check the Sharpe name 299 00:21:58,470 --> 00:21:59,160 than the name. 300 00:21:59,160 --> 00:22:04,890 So name is the nice official title improving readability but the short name is what we the programmers 301 00:22:04,890 --> 00:22:07,200 would be using in the background. 302 00:22:07,230 --> 00:22:07,910 All right. 303 00:22:08,070 --> 00:22:14,910 So now that I have gotten the role that this user who is able to log in or who was just logged in. 304 00:22:15,030 --> 00:22:17,950 Now that's I know the rule that they have. 305 00:22:18,090 --> 00:22:18,450 All right. 306 00:22:18,780 --> 00:22:22,140 What I'll be doing is passing the. 307 00:22:22,170 --> 00:22:28,010 Well let me say that I only want the shark name so I don't want the whole rule object I want to short 308 00:22:28,010 --> 00:22:28,230 name. 309 00:22:28,230 --> 00:22:38,310 So I'm just going to say var rule name is equal to rule dot and then get the table rule and then say 310 00:22:38,320 --> 00:22:42,260 dot again and then get then shark name. 311 00:22:42,270 --> 00:22:42,920 All right. 312 00:22:43,620 --> 00:22:46,110 And then I'm passing this shark name 313 00:22:48,790 --> 00:22:52,830 in two so a shirt name. 314 00:22:53,490 --> 00:22:54,330 Oh sorry. 315 00:22:54,840 --> 00:22:58,070 I'm passing Roland in my bed. 316 00:22:58,080 --> 00:23:00,990 Not sure anymore need some passing so I'm all right. 317 00:23:00,990 --> 00:23:03,840 Let me in or just because I just confused myself. 318 00:23:03,840 --> 00:23:12,900 So let me just be clear role shark name all right is equal to rule our are object which is users rule 319 00:23:12,930 --> 00:23:16,300 that rule which is our table not the shark. 320 00:23:16,320 --> 00:23:24,630 Name column and then this variable is going to be passed into the main window construct us and I need 321 00:23:24,630 --> 00:23:29,850 to modify this construct to someone you don't control and then I click it jump so what's that constructor 322 00:23:30,120 --> 00:23:32,410 we know it's this one that we need to modify. 323 00:23:32,460 --> 00:23:37,910 So I'm saying that you can also accept a string called Rule shark name. 324 00:23:37,920 --> 00:23:38,300 All right. 325 00:23:38,790 --> 00:23:44,160 So when we log in and we're launching our main window we're passing in the log in object. 326 00:23:44,180 --> 00:23:51,030 We're also passing in the rule shaft name so because I'll be using this rule all over the place on when 327 00:23:51,030 --> 00:23:55,260 to do it similar to how I did the log in but this time I want to make it public. 328 00:23:55,260 --> 00:24:04,590 Someone to say public and string and then I'm going to give it the underscore rule name. 329 00:24:04,820 --> 00:24:05,620 All right. 330 00:24:05,680 --> 00:24:12,840 So my main window is going to have a publicly accessible property called a rule name which would allow 331 00:24:13,120 --> 00:24:18,250 any window that needs to know what rule is the current a loving person in right. 332 00:24:18,250 --> 00:24:23,110 So I can just get that and then I'm going to initialize it. 333 00:24:23,230 --> 00:24:33,850 So I'm going to call this rule on the squirrel name is going to have the value of the rule shark name. 334 00:24:33,850 --> 00:24:35,060 All right. 335 00:24:35,380 --> 00:24:35,880 So. 336 00:24:35,950 --> 00:24:41,470 And then I mean this principle can be used anywhere so it could be that you're going to be passing in 337 00:24:41,470 --> 00:24:49,420 maybe user data because you wanted a welcome screen or you know you want some little taskbar at the 338 00:24:49,420 --> 00:24:51,490 bottom to see who is logged in. 339 00:24:51,550 --> 00:24:56,310 You know you would have passed that information just the same way as I could have actually just possibly 340 00:24:56,320 --> 00:25:00,780 the entire user object into the main window and then use that data. 341 00:25:00,790 --> 00:25:02,240 How I need it to. 342 00:25:02,300 --> 00:25:04,100 There are so many ways you could have done it. 343 00:25:04,380 --> 00:25:07,680 But right now I'm just interested in knowing the role of the person. 344 00:25:08,380 --> 00:25:09,160 All right. 345 00:25:09,160 --> 00:25:13,720 And then we can move along with that so the person's rule 346 00:25:16,660 --> 00:25:19,490 now let's do a simple operation. 347 00:25:19,510 --> 00:25:26,900 So let me just show you exactly why we need the rule name and what we can restrict what if anybody who 348 00:25:26,900 --> 00:25:31,860 is not admin should not be able to click manage users and you can just think about it. 349 00:25:31,860 --> 00:25:34,470 We have three users we have a three year old Sara. 350 00:25:34,490 --> 00:25:35,540 We have admin. 351 00:25:35,840 --> 00:25:43,610 We have our administrator we have data entry clerk and we have you only nobody who is not in the administrator 352 00:25:43,610 --> 00:25:46,170 role should be able to come and click. 353 00:25:46,190 --> 00:25:51,660 Monday's users it should either not be visible or visible and inactive. 354 00:25:51,670 --> 00:25:52,010 Right. 355 00:25:52,430 --> 00:25:59,060 So the best way to make sure that when the main window lords we know one what rule this person is in 356 00:25:59,270 --> 00:26:04,530 and then to we determine what they can and cannot do would be to see unload. 357 00:26:04,550 --> 00:26:06,320 We want to make these decisions. 358 00:26:06,330 --> 00:26:06,920 All right. 359 00:26:06,980 --> 00:26:14,780 So I'm going to just create a form loading event on the main windows so I just go to properties go over 360 00:26:14,780 --> 00:26:16,180 and here it is load. 361 00:26:16,220 --> 00:26:17,930 So I'm just going to double click in there. 362 00:26:18,050 --> 00:26:22,660 However the main window Load event in the main window Load event. 363 00:26:22,670 --> 00:26:27,850 I'm going to see if roll sharp name is equivalent. 364 00:26:27,860 --> 00:26:34,490 And this is why I said we can use the sharp name and sorry actually have underscore all the names so 365 00:26:34,790 --> 00:26:41,540 roll Rosado name is unique to just the constructor but then the rest of the application knows underscore 366 00:26:41,540 --> 00:26:42,170 rule and name. 367 00:26:42,170 --> 00:26:42,780 Right. 368 00:26:42,790 --> 00:26:50,900 So I want to say if underscore or the name has the R is not equal to admin they miss it not equal to 369 00:26:50,960 --> 00:26:56,870 admin so it is not equal to the sharp name admin. 370 00:26:56,870 --> 00:27:02,480 All right so obviously this wouldn't be so keen if somebody went on updated the short name that would 371 00:27:02,480 --> 00:27:04,000 break it all together. 372 00:27:04,000 --> 00:27:04,280 Right. 373 00:27:04,310 --> 00:27:06,340 But lets us work with it for a.. 374 00:27:06,350 --> 00:27:11,820 So if the roll name is not equal to admin then we want to make a decision. 375 00:27:11,960 --> 00:27:15,880 The decision we want to make is that the manager uses button. 376 00:27:15,890 --> 00:27:18,360 Let me just find its correct name. 377 00:27:18,440 --> 00:27:26,150 So just go over to the properties for that button and I see that the name for this button is manage 378 00:27:26,150 --> 00:27:31,410 users to strip menu items I can copy it at just copy the name. 379 00:27:31,410 --> 00:27:43,650 So if the rule is not equal to admin then I want to see this control by its name docs enable is equal 380 00:27:43,650 --> 00:27:45,000 to falls. 381 00:27:45,000 --> 00:27:45,500 All right. 382 00:27:46,110 --> 00:27:48,210 So you have properties that allow it to be a bit. 383 00:27:48,210 --> 00:27:50,310 So remember we have dot visible also. 384 00:27:50,310 --> 00:27:55,650 So if you wanted to hide it you could see a visible is fours or you could see a dot enabled as far as 385 00:27:55,650 --> 00:28:00,120 meaning they would see the button but it's not enable that kind of clicking the content directed it. 386 00:28:00,510 --> 00:28:04,950 But let me use the visible because I think that's cleaner instead of shoot and then something that doesn't 387 00:28:04,950 --> 00:28:07,010 work let's just hide it altogether. 388 00:28:07,020 --> 00:28:13,260 So they would never guess that they could have or that that functionality existed right. 389 00:28:13,320 --> 00:28:19,980 So I'm saying that if the role is not equal to admin then this is false side. 390 00:28:20,010 --> 00:28:23,580 So let me click Start I listed that's out. 391 00:28:23,850 --> 00:28:24,300 All right. 392 00:28:24,300 --> 00:28:31,120 So we see that we still see or manage users and that's because all the user we have is the admin user. 393 00:28:31,200 --> 00:28:38,340 So when it got to this statement when it was loading it would have said is the rule admin if it is or 394 00:28:38,340 --> 00:28:41,220 if it is not admin sorry then don't show it. 395 00:28:41,250 --> 00:28:49,470 So I'm going to create another user that is not an admin user so this one I'm just going to say user 396 00:28:50,070 --> 00:28:56,400 so and then I'm went to use the same password and then this is going to give me an error so I make a 397 00:28:56,520 --> 00:29:07,090 copy of the password first then see user password and is active is true all right. 398 00:29:07,280 --> 00:29:10,760 And then I'm going to try that again. 399 00:29:10,760 --> 00:29:14,170 So let me try to log in with this new user. 400 00:29:14,180 --> 00:29:14,530 All right. 401 00:29:14,540 --> 00:29:23,210 So I'm logging in with user password to log in and then it said something went wrong so let us see exactly 402 00:29:23,540 --> 00:29:31,580 what our error is Selimi go over to my log in code and see if it's something so it's something on the 403 00:29:31,580 --> 00:29:32,540 click event. 404 00:29:32,570 --> 00:29:34,820 Let me put a breakpoint here. 405 00:29:34,820 --> 00:29:40,570 Let's try that again and then it gets a lot of the hashing of the password. 406 00:29:40,580 --> 00:29:41,960 That's fine. 407 00:29:41,960 --> 00:29:49,170 Let me step through using a few Levin and then it runs the query where it's sitting where if the user 408 00:29:49,170 --> 00:29:54,320 name is equal to user and the password is equal to the hashed password. 409 00:29:54,440 --> 00:30:02,200 Good and then we step through again and then it says if the user is equivalent to no else. 410 00:30:02,230 --> 00:30:02,740 OK. 411 00:30:02,740 --> 00:30:04,950 So it moved along. 412 00:30:04,950 --> 00:30:06,350 Now we're getting the rules. 413 00:30:06,370 --> 00:30:09,540 I suspect that my arrow might be here. 414 00:30:09,580 --> 00:30:12,080 So rule came back as No. 415 00:30:12,070 --> 00:30:12,460 All right. 416 00:30:12,490 --> 00:30:13,480 That's what's so wrong. 417 00:30:13,480 --> 00:30:19,030 So I added the user and I did not set the record instead of the user rules. 418 00:30:19,040 --> 00:30:21,970 All right I ends even if you hover over it in debug mode. 419 00:30:22,030 --> 00:30:23,310 That account is zero. 420 00:30:23,320 --> 00:30:24,370 So that was a problem. 421 00:30:24,400 --> 00:30:27,930 So let me just click continue and it will. 422 00:30:27,950 --> 00:30:30,490 So exception handling is why it didn't break right. 423 00:30:30,490 --> 00:30:31,830 He just said something went wrong. 424 00:30:31,830 --> 00:30:40,240 Please try again and then I'm going to go back to my database and I need to add the new user so my new 425 00:30:40,240 --> 00:30:42,340 users I.D. three. 426 00:30:42,730 --> 00:30:50,100 Let me go to user rules table it Top Two hundred and I want to say that user with the I.D. three has 427 00:30:50,110 --> 00:30:55,270 the rule I.D. of two because we know that real I.D. one is admin. 428 00:30:55,290 --> 00:30:58,010 So we want it to be anything but admin. 429 00:30:58,030 --> 00:31:03,610 So I just added that to the database and I'm going to try and run the application again frankly log 430 00:31:03,610 --> 00:31:08,870 in and I want to remove the breakpoint and press F5 for it to continue. 431 00:31:08,990 --> 00:31:10,390 That's something soon wrong. 432 00:31:10,390 --> 00:31:14,640 So clearly we still have an arrow that we need to fix. 433 00:31:14,680 --> 00:31:16,520 So let's try that again. 434 00:31:16,570 --> 00:31:21,220 So I'm moving the breakpoint though into the if statement check. 435 00:31:21,280 --> 00:31:21,640 All right. 436 00:31:21,640 --> 00:31:23,020 So let us try. 437 00:31:23,040 --> 00:31:24,490 The log in operation again. 438 00:31:24,520 --> 00:31:28,480 So it's good that we're going through this experience together because I think I may have missed a step 439 00:31:28,510 --> 00:31:30,370 but I don't want to just tell you the answer. 440 00:31:30,370 --> 00:31:31,480 Let's see it together. 441 00:31:31,480 --> 00:31:36,250 So if you live in and then we get the roll out. 442 00:31:36,280 --> 00:31:38,800 So the rule is still no. 443 00:31:38,830 --> 00:31:40,990 So it still to me that the user rules. 444 00:31:41,020 --> 00:31:43,240 So let me just make sure it's getting the right user. 445 00:31:43,240 --> 00:31:50,440 So when I hover over the user object I see that the I.T. is three and everything else is good but then 446 00:31:50,470 --> 00:31:55,910 it's still seeing 0 4 the user rules. 447 00:31:55,930 --> 00:31:56,310 All right. 448 00:31:56,320 --> 00:32:05,260 So let me stop out of debug mode and let's just recalibrate and see and make sure everything is OK. 449 00:32:05,290 --> 00:32:11,820 So I have user rules I added the user I.D. 3. 450 00:32:11,840 --> 00:32:22,710 So just make sure that it was the right user so user I.D. 3 and then sorry of some tabs open. 451 00:32:22,710 --> 00:32:26,020 All right so a user I.D. 3 and 2. 452 00:32:26,020 --> 00:32:26,260 All right. 453 00:32:26,260 --> 00:32:29,200 So let me just do some debugging and let you know what's up. 454 00:32:30,190 --> 00:32:30,460 All right. 455 00:32:30,460 --> 00:32:34,980 So I all I did was stop it and start it and try it again and try and debug. 456 00:32:34,990 --> 00:32:36,850 And there was literally no error. 457 00:32:36,880 --> 00:32:39,250 So I'll explain what happened then. 458 00:32:39,280 --> 00:32:44,170 So user password we clicked plug in we're going to hit the break. 459 00:32:44,170 --> 00:32:49,700 I didn't move the breakpoint but as you can see user rules is no counting to 1 if I hover over it it 460 00:32:49,720 --> 00:32:53,020 is not seeing one I literally made no changes. 461 00:32:53,140 --> 00:33:00,460 I think what happened is that when it's during a runtime it did not go back to the data base every single 462 00:33:00,460 --> 00:33:08,200 time it kind of like took a staged like a snapshot of the data at the time of the query or at the time 463 00:33:08,200 --> 00:33:14,560 of debugging and it was using that set of data saved when we made the changes it didn't reflect in the 464 00:33:14,560 --> 00:33:16,330 application at runtime. 465 00:33:16,330 --> 00:33:23,710 So what we've done so far should work if it doesn't you can always let me know but I'm just going to 466 00:33:23,770 --> 00:33:28,260 remove this breakpoint and I'm just going to continue because everything should work. 467 00:33:28,290 --> 00:33:30,190 So we envisioned it. 468 00:33:30,190 --> 00:33:35,260 And then when I press if I have to continue I noticed that the menu is not showing manage users. 469 00:33:35,260 --> 00:33:42,580 So that's because the role that the person who was loved in the role associated with them is not admin. 470 00:33:42,580 --> 00:33:44,790 So their role is clerk. 471 00:33:44,860 --> 00:33:45,250 All right. 472 00:33:45,250 --> 00:33:51,580 If I had left the debug the breakpoint then you'd see that a rule a short name is still seeing Clark. 473 00:33:51,580 --> 00:33:52,390 All right. 474 00:33:52,450 --> 00:33:53,800 So then that is hollow. 475 00:33:53,800 --> 00:33:58,000 So what we did was we got the rule for the person logging in. 476 00:33:58,000 --> 00:34:02,140 We transferred that rule data over to the main window. 477 00:34:02,620 --> 00:34:07,070 And then in the main window what during load we use. 478 00:34:07,090 --> 00:34:14,140 Well we set up a load time event and we said when you load take if it is in add minerals so whatever 479 00:34:14,140 --> 00:34:19,510 it is you don't want the non admin persons to be able to do if you had 10 menu options and they should 480 00:34:19,510 --> 00:34:21,100 only be able to access to. 481 00:34:21,220 --> 00:34:28,210 You can follow the same pattern and just make it not visible just you know with a deactivated they make 482 00:34:28,210 --> 00:34:29,170 it not visible. 483 00:34:29,170 --> 00:34:30,790 The point is that they can't do it.