Transcripts
1. Introduction: Hey guys, welcome to this course entitled complete dotnet Core 3.1 and Entity Framework Development. I am your instructor, trapdoor Williams. This is a very detailed course to get you up and running and programming in the dotnet Core environment in no time. And some of the objectives that we hope to meet for this course are to build a fully data-driven web application. Understand how the dotnet Core applications flow. Build fully functional program using the repository pattern and dependency injection. And some of these expressions may seem scarier, but throughout this course, I will simplify. Everything is very beginner friendly, it's very detailed. And at the end of it, you should be a full-blown dotnet developer. We will also see first on-hold, the MVC pattern works. We'll get to a better understanding of C Sharp and certainly tips and tricks. And we will get a taste of using front end frameworks to style the overall layout and look and feel of our web application. Now, doing this course is very, very beneficial to you. Dotnet is one of the most popular. Knowledge is used to build enterprise of the applications. Developers are in very high demand. It is a very predominant technology and it is an extremely important skill set to have in this day and age. For the duration of this course, we'll be using Visual Studio 2019 Community Edition, which is a very, very powerful development environment into the tool of choice when you're doing dotnet development. And it's allows us to quickly integrate with other front-end frameworks such as bootstrap, jQuery, Font Awesome, and many others. It also comes with Git integration, which makes it easy for us to integrate with GitHub for our source control purposes. And it comes with many Management Studio for our database management activities. Ultimately, I want it to be prepared to open up yourself to the world of dotnet programming, you wouldn't need some knowledge of HTML, CSS, and object oriented programming if you have some knowledge of databases filament, that's also good. But ultimately, once again, this is very detailed. So even if you're not that adapt to these technologies, I make it very easy for you to get up to speed and feel proficient in no time. This is just a sneak preview of the application that we will be building together where we'll be allowing employees to be able to apply for leave and setting up some administrative features for admin users to be able to manage those leave requests. So whether they are approving them or rejecting them and showed the history. So all of this once again, will be dynamic. We are going to be styling it using Bootstrap and admin LTE. And we're going to have fun. So just get ready to roll.
2. Create a GitHub Account: Hey, guys in this video will be creating or get up accounts on. This is a really simple step. Get up. Makes it very easy for us to sign up. You just need to go to get hopped up palm. That's G I T H u b dot c o m. Get hub dot com on. You'll land on this pitch. No, from here, if you already have an account and you can sign in and you can pretty much stop watching the video here if you don't, however, then the Senate form is right here. You can do a little reading. Just get an appreciation of what ghetto B is for. And it's all a boat. They do have pricing, so they do offer enterprise plans and education plans and different plans for different situations. But for the solar developer for very small, you know, teams that may not be enterprise ever than they do give you ah lot for free. So to sign up, you need only put in a user name on an email address and a password on Once you have provided all those things and provided that your user name is unique enough off course then you click. Sign up for ghetto on. You should be in. So I already have an account, Some real adjustments Assigning you saw my brothers are going crazy trying to provide information, so I'm just going to sign in with my existing account. So that's my what he can use. You're using him or e militarists to sign in. And the password on here I am. This is my landing pit. So they actually give you, like, a sense off community. It's almost like a Facebook for developers. To some extent, you can follow people on once they're following people, you see their activities on the flu landing page. You can jump to your repository. So obviously, if you're new to get up, then you wouldn't have anything listed to the side here. What? I'm not news. I've been quite busy. Um, putting up content on get off almost any little pet project that I start. I have a get over positive, actually need to go through and clean this up on Also, I've had students add me to their repose in the past. Eso that you know, we could collaborate. Maybe they're having a problem and I could just verify their cord through the re posits. Very all of those things are, you know, possible through this fair, powerful tool. But once you have created your cones and you're signed in Ondo well, you obviously wouldn't see what I'm seeing once again. But then that would complete the sign of active
3. Install Visual Studio 2019 Community Edition: Hey, guys, in this video will be installing Visual Studio 2019 Community Edition Now to get to the visual studio website, we type in visual studio dot Microsoft dot com Photo Don't look bizarre studio, and we want to get the community edition. So we do have professional and we do have enterprise. But in the community edition is free for individuals on academic users on ditz. Also open, sir. So once again, um, if you are in an inter press sitting, you should get enterprise and you have to pay a license for that. But then for our pet project, an individual project or academic projects open source purposes, communities there it's free and it's fully powered and waiting to be used. So we just get community on then that triggers are don't lord for an installer. So we just click on that Insulted that was just downloaded Run. It will initialize Onda. We can go ahead with our installations so we could continue on that just fishes a few files for us. All right, so after it's finished with those initial workloads, then what it will do is ask us. What packages do we wish to install to support whatever it is that we're going to be developing. So, like I said, we're developing a web application, So we needed SP dotnet and Web development package or workload on. Then we take that, um, we take that box here on then to the right and said, You see that they're giving us a little list off what will be included. So the latest dot net framework is four point it. So you know, it is that we're getting 4.4 to 4.6. So I understand to go ahead on the teak. All of these all of these dot net framework 4.6 point 1.2 point seven point it on. But that's not all, though. We need that Met core, but then this course is based on dot net core 3.1, which is the latest. But if you go with visual studio and they're getting full 0.1 so we can leave that alone after this, then I'll show you how to get 3.1. Also, since we'll be doing a little as your stuff way, I'm just going to take the A zero box on. We don't have to modify much more there. I'm just ticking that box. Make sure that we have any libraries that would require you can do a drill down on. Just see what else is available to you. Safe. He quit the dot net core cross platform development. If you click that workload, then you get some more dot net core things. But I think a lot of those are already included in the Web development workload as you notice that the total space will increase with each workload that you choose. So I'm just going toe on Tick the 01 on. I'm just going to make sure I have the dot net core cross platform workload on the SB dot net and Web development workloads. We're not doing much development with as your so you can take it if you want. If you If you know you have the space, that's fine. And off course, the more you tick is longer will take the download. But I'm not going to take it for this particle, Of course, so once again we just have the sp dot net and Web development, and we have the darknet core cross platform development on the numbers one to click, Install on, then that will start the installation, which is really a don't load. So based on the Internet speed, this is going to vary in length. Some just quinto resume when everything is finished here. All right, so this process is finished. Burba took just unlearn our on their seeing that they require that I restart my computer in order to complete this set up. So I'm going to say not. No, not that you don't need to restart, but there's something else that I want to show you before I let you rebuild. So I'm going to say, not know which is basically just not going to complete the installation just yet. But I'm just going to minimize this and I'm going to show you that we need to download the dot net core 3.1 tools on, so I already have that open and you can get to this website through dot net dot Microsoft dot com on. Then I'm at slash Don't Lord, where it is showing me that I can don't know the dot net core 3.1 tools or the run time for that specifically as well as dot net framework four point it. So we actually just installed visual studio with the dot net framework. Four point. It's tools, so we don't need to pay attention to that. But we do need the core 3.1 on. I did say earlier that the dot net core is built for multiple platforms. It's cross platform. So you see that that the windows don't know that the Lennox Stone Lord, that the McCoys don't and they have a doctor don't Lord. All right, so we'll go with the windows. I'm using a Windows machine on I'm teaching you based on Windows. But that being said, whichever one year on you don't know the one that's appropriate for you on DWI Run the up so I'm Winton. Just don't load the dot net core runtime on. I'm also going to don't know the dot net core sdk, so I'm just going to don't know the X 64 cause I was 64 bits on. We can don't know that on install it. So when the installer comes off, it's pretty straightforward, a slick in star on. Then it will do what it needs to do on. Then you will see that it was successful. So I really didn't take that long to install on. I'm just going to go back and also get the sdk. So what I got was a run time. I went to download the SDK no sdk short for software development kit. So that's where the real development tools will be, um, made available for visual studio to interact with on notice. They're saying that this release is only compatible with visual Studio 2019. So if you have 2017 or an earlier version, then you may want to upgrade. So that's don't know. Did let's just install that so and then start A comes up with a stick install, let it do its thing. And then it says that everything was successfully installed and they use all their own times and all of the other pointing us. The different documents that we can use for your resource is so we can close that. I know that we've done all of this. Then I can restart the computers. I didn't want to restart and then forget the steps. So I just made sure to install everything and then we just do one big restart Onda low the computer to do its thing. All right, so know that Ari Start is complete. Letters. Go ahead and fire off Visual Studio 2019 on. You can find it by going to the start menu, and you can probably just type in Visual Studio will pop up already pinned my visual studio 2019 to my Start menu, as well as to my task bar. So just by clicking this purple icon that looks like that infinity sign, we will launch our visual studio the once it's launched. It encourages you to sign in or create an account, and you can up to do that later. No, with the community addition, it will actually give you a little, like a 30 day trial kind of feeling if you don't sign in. So if you choose, not know, maybe later and then later down the line, you you see like they're saying, or it has expired or something like that. It's really just saying that they expect that you signed in wants to sign in. Then there is no expiration experience that you have part, so I'm just going to sign in windows account, and this is the windows are cones. Are the Microsoft a corn that I hard long before? Andi. This is the one that abusing for any as your related activities that our house understand to go ahead and log in Once again, you can create a Microsoft cones or, if you already have one, just use it on log in. So whether you opted to sign in or you said not know, maybe later you'll be led to the speech where they ask you what style you like. So dark, dark theme is all the region. I t all right. No, but you can choose the theme that is appropriate for you on the development settings. I'm going to put that toe web development. So, General, Yeah, that's fine. But then what development? That kind of put certain things at certain places to make it more obvious for you to see. All right, So once you do all that, you can start results studio No, just no matter. I'm toe signing feel because I'm on a server and they're certain restrictions, our own certain activities. And so I'm just highlighting that to show that if you said not know, maybe later, then this is a screen you'll get. Once visual studio Florentines, you'll be prompted to sign in and to the right. You see that you have a 30 day trial. So once again, your evaluation period as and that please sign in tow a lot of products. All you really need to do is sign in on that evaluation message goes away. Someone's a sign in once again. All right, I know that I was signed in. You see that? I have the personalized cone they had at my content. And then that evaluation message really has gone away. And so I can pick clothes. And then this is the launch screen for visual Studio 2019. So from here, I can check out something from a source Control. I can open an existing project, open a local folder for creating new projects. So we're going to pause right here. If you got this far, then that's perfect. You've installed results Studio 2019 Community edition on. Then you're ready for the next activity.
4. UPDATE: Install Visual Studio 2022 Community Edition and .NET 6: Hey guys. In this lesson we'll be installing Visual Studio 2022, which ships with dotnet six, which is the fastest dotnet yet. So to get started, we just need to go over to Visual Studio dot Microsoft.com slash downloads. And then we will go ahead and hit the free download on the community edition, which will then give us an installer. So once we run that installer, we will be able to select the workloads that we want. Workloads really refer to the libraries or to supporting libraries for the type of up that you're interested in creating. So in this case, we definitely want to get that web development ASP.net on web development workload. But then if you are interested in other technologies, you can go ahead and select them. So you can see I have several workloads selected with Azure development, NodeJS and desktop development. So you can go ahead and split those also. I think that they will come in handy with other projects that you might end up building all in all, once you have done that, you can go ahead and hit Install, which would be done by the bottom right-hand corner. Of course, the more workloads you select is the bigger the download size. So once you've completed that, then you can continue. Now when that download is finished, you may get certain options that I am not going to get because I already have it installed. So this will walk you through what do I expect? You may get an option where you get to choose your theme. As you can see, I'm using the dark theme, but then you do have the option of a light theme, a blue theme. And the thing is that Visual Studio 22 has many more themes than its predecessors. So even if you don't want light the initial themes, you can get all the themes if you need them. Also, you may be prompted to sign in. So if you already have 2019 installed on your machine and you are just installed in 2022, you already signed into 2019, then it probably won't prompt you to sign in again. However, if this is your first installation of Visual Studio, you may be prompted to sign in or creates a live account, which point you would want to just use your Microsoft issued at live at all loci are taught me a lot com cones, or you can just go ahead and create one. And if I if my memory serves me correct, you can use an another non-Microsoft email address, secretes saliva, cold.
5. Create .Net Core Web Application Project: you guys in this video, we will starts creating our dot net core Web application. You can start this by firing a visual studio. If you don't already have it open on, then when you get to this point over here was probably blank for you because you did a fresh installation. I did a fresh installation. Just demonstrate. But I have other projects that I have been working on, so I'll have them to the side here where it kind of shows your recent projects. But for this exercise, we're going to be creating and you want to click, create new project and then using the search bar at the top, we will just type in the word core. So when we type in court, it will kind of filter out all of the dominant core related project templates on because we're specifically doing a Web application, I can be more specific and CSB dot net core on. Then it will once again filter and then give us the sp dot net core Web application template so we can go ahead and click this one, and we want to make sure that it's the one with C sharp. You may see other ones with F Sharp and maybe vb dot net. But we want the one with C sharp and then we click next and then we give it a name. Someone should be calling this one. Leave. Hi, friend Management's since we're creating a leave management system, so it's leave hyphen management on. We don't have to modify anything else unless you have a specific location that you wish to put your project in. Then everything else can stay as it is, and they will just go ahead and click create after clicking creates there. No asking us what kind off scaffolding or preset. Um, you know what? What do they we want to create a project with so we can create a completely empty project. We can create one with an e p I, you know, template. We can do with a Web application templates we can do with an NBC template angular act GS, etcetera. So for this exercise were selecting the Web application M. V c template. Want to make sure that this is that mitt core and not dotnet framework. Right? So I did explain that dotnet framework and don't Niko are kind off different. So we want to make sure that we're on darknet core. And we also want to make sure that the version off dot net core is 3.1. So I have quite a few listed here. You may not have as many, but you should have core 3.1 if you don't have core 3.1, then go back to the installation video on Try and configure it once again. So I'm selecting core 3.1 on to the right and said they're asking, Do we want to configure for https? They want to enable doctor support. I want to leave those as no. So I'm selecting Web application with NBC dot net core 3.1 on then for the authentication. I'm going to change this from no authentication toe individual user accounts. So what this will do is actually give us the framework for authentication in our application where we can create and Andi use user A cones natively are out of the box. All right, so I'm just going to select individual user cones. Click OK on, then we can go ahead and click create once again on Then it will start the process off creating the project. Once that project is successfully created than you see, an interface that looks something like this, I can have customize my interferes because you can actually move around the docking buyers . He can introduce others that you may not see. So, for instance, I think by default, the solution Explorer is usually under right hand side. So that's probably what you're seeing. Um, I actually have a preference for it on my left hand side, mainly because, you know, as Western readers or read left to right. So starting from the left, going to the right, it's easier for me. But I mean, at the end of the day, you can dock on undock these two bars. As you wish. If I have a toolbar here that you are not seeing on yours and you can just go to view on, then you'd be able to click and you see Team Explorer survey experience. E All of those. All of these or most of these are tool bars that will appear on our doctoral If you don't want maybe a toolbar to be, you know, always displayed like, for instance, the solution explorer, maybe want more real estate for your court than you can use this little pin here. That's his auto hide, and you can click that and it auto hides. Andi. It only comes up when you go over it and click it on there. When you lose on while there is focus, you can do what you need to do. And when you're finished, you can just click it and it will, you know, just hide again. So it's It's a quiet, versatile interferes. You can kind of customize it, move things around to your preference. So once again, I have social expert to my left. Andi, I like when it's there for easy access, have a big you know, screens have enough real estate. This landing page they give you some resource is they can, you know, get started quickly with building code. But for this, scores were going to be building a specific application on doing many more things than any of thes articles probably probably would ever mention to you so you can stick our own in the next video. We're going to go through the solution explorer, and we're going to have you know, we're going to go through and understand exactly what we're looking at and how all of these components play a part in helping us with our application development.
6. Tour of ASP.NET Core Application: Hey, guys. In this video, we will be looking at the folder structure off our newly created SP dot net core 3.1 Web application. No, our tool of choice is visual studio Community Edition 2019 on In the Solution Explorer that the afford us. We can see all of the files that are in our project. So are, well, let's let's start with what's at the top So you can see that this kind of like a tree view are higher Arctic. Higher are give you off all of the files. Everything is a so file or something else. So I stand at the very top. So this is a solution file. So if you're not so familiar with visual studio on projects in Visual Studio, what they do is they create We call a solution file, which is like an overall director for all projects that might be inside off a solution. So you can have one solution and it has a Web project. It has ah, see sharp class library. You can have a desktop project. You can have multiple projects within one solutions. In this situation who have one solution, it's gonna leave management and we have one project. So the solution is at the top. Most on the project would be second in that list. On that is our Web projects. And if you click, it kind of shows you that is really just an XML file that is highlighting, you know, certain properties that the project or solution will have to keep track off what is being done. So the solution is at the top and usually has that square with that infinity logo that visual studio has. And then we have the Web project after that, and we're project, you know, the icons kind of clue you in as to what kind of project it is. So this is our Web project, Andi. It is another like director for all Off the files that will be used are created inside off the Web project. So this what project represents our entire Web sites that were about to develop? No, just walking through F connected services. And if you wreck that, you skins, you can at connected services. Connected services include, like Microsoft, as your services maybe develop services. Anything that may be can be connected to the project and use like a Web service or an additional service. You can use that as a hope for this video. I won't get into that. I just wanted to understand what you're looking at. And then we have dependence is so if you expanded dependencies than you're seeing analyzers . So Dominic Cork comes with a few analyzers that help us with our debugging and or performance analysis. As we go along, we have framework. So we know where do using the dot net core up from work on the the store dot net core framework references on, then packages where we actually know what what kind of packages were using and a package can be, You know, like 1/3 party library that is a utility. So, for instance, bootstrap will release in previous versions you could download. Bootstrap. Not that you can't know Sorry, but it's not implemented that way primarily. But the point is, if you have 1/3 party library that you want to include in your project, then you don't know what we call a package using a tool called new get. So if you're actually dependence is and you see something called managed, you get packages up. Another screen that shows you what is installed. So we have all of these packages and remember that we had done individual user cones and we created a project. So when you look at it, you see the dot net core that identity that you I right. So that's a package that we don't loaded on certain libraries, the handle connection store data bees. And then, if the library want isn't already installed, you can always go to Bro's. On. They will least owed all the libraries available to you on the new get platform. So here's geek where you can don't know Jake wear references right here without manually going and getting the files. Um, you have autumn upper. You have quite a few of them that some may mean something to your I know some me not, and that's fine. Just notes that it's important that you include pre release when you're searching because we're using that night 3.1, which is brand new on DSO. Some people may not have published um, very publicly the darknet three point the dark net core 3.1 version off their package just yet. So by including pre release than we're making that release available to us for Donald and inclusion. Next, we have properties. And if we go into properties, you see launch the lawn settings that Jason, which opens up this file, We don't have to touch anything here. But this is Miss Guy. Just a fire with some directives that when we're launching, this is what we're expected to do. So you can modify it if you know exactly what you're doing. If not, then you can leave it as is and change it on a case by case basis. Our next we have or www route No. Www Root folder has our static files. And when I say static files, I mean in the CSS file, any Java script file or any lib has the bootstrap on JIA query. So it comes with those things already built in. It comes with the bootstrap, um, file references by default. So if you were planning to use bootstrap, then you don't have to go very far because it's already apart off the project temporary that we would have created if we want any JavaScript files that were going to be developing . We put it here site not CSS. is basically just there ceases file that they give us that we can modify if you want to add things that bootstrap me, not necessarily give to us. So all in all, anything that is a client side static file. They give us the framework as to where to put them in the sea. Assists, and they're usually CS and GS files wouldn't be making each dima files necessarily in a project like this. So it's really CSS and JavaScript files that would be created and placed in these folders on all of those are in the www Root folder. Next, we have areas on Daz. We go into the identity stuff. We'll explore what goes in here. But areas is basically like a segmentation off your applications. You have, like an admin area versus and employees era versus I use their management era. So by default, because we included the user authentication, we got identity as an area on its It's empty. No, but when we get to that point, you see it Philip a bit more. Next we have controllers. No, I mean not have spent much time explaining what the MTV and the sea really mean in NBC, but they stand for models, views and controllers. On DSO, we have a folder four controllers, and you notice that we have a full of four models. Are were a folder for views. No, the controller. Since it appears person, that is, I'll explain it first pretty much dictates what the Web application should do. So when somebody clicks on a page when they click on a link, rather they're requesting content. They're requesting a pitch. So when the click on that link, that is our request, which is sent to the controller. So Controller receives a request on. Then when it gets the request, it says, Okay, this person requested this link or this content based on the information that I'm getting on. Then he will return the content as best as it can. If he can't, then you get like that four or four errors, so the controller is literally pulling the strings based on what the user is requesting versus what the application has to offer, said User. So let me put it in a little simpler term or well within the context of what is in the actual file. So in the controllers sold Aranda we have won control and it's called home controller. So that's a naming pattern home controller. So whatever the name off the controller is, we have that name and then the word controller, and it should always be in community. It's just like that on then our file. This one was generated for us so we can just go through it and look at it. We see that we have public class home controller. So the same name of the file is the same name of the class that is there. And it is inheriting from us a base class called controller and that one insisting, provided Onda start with index. So indexes usually the very first page that lords on any website. So when you goto upset amazon dot com bulled up come youtube dot com. The first page that comes up is usually called index, regardless off the extension of this that PHP dot html Whatever it is, it's It's almost always called index. And so if we were toe bro store, leave management and just go to the home. So he said, leave management under said slash home, then the first thing it would do is try to find index. All right, so home slash index is the contents that we the users would be requesting on DSO. The controller is going to check if it has a function hauled index. If it does, then it says, What does index I should do? Then it says return view. So the view is what the user sees arts removal Have em wear V nufc model view controller. So the controller is seeing I got a request from a user on dso I'm goingto do what I am commanded to door. This is the content that that user should see, which is the view whatever the user seizes the view. So if I look in my views folder, then I'm going to see ah folder with the corresponding name for my controller. So I have home controller. That's the name of my controller Have Abuse folder called home on DSO Forever function that is defined inside off my controller. So at least index and privacy. If I look inside off this views folder for the whole controller, then I should see some file with the same name. So I have an index file. Sorry. Let me just get back there quickly have an index function right function called index and returning view. The expectation is that when he says Return View is going to look inside off that folder with the corresponding name for some file with the same name as the function. So for privacy, you see a file called Privacy Arrow. Candido Something different Did those returns of you with some content in it as soon get get into that? Why it's a little different, but at the end of the day were a turning view on work to returning view here. The court is identical, but then contextually knows that it's returning the view that corresponds with the name privacy. So it looks in the folder and finds a file with a corresponding name. So since we started off with Index, let's look at the index view. So if I don't like the index, do you see that? It's really just loading and it's seeing Okay, um, each one tug Welcome. So this is an html five, but notice the extension, say, C s that html on This is a This is a special extension because then it allows us the kind off inject C sharp chord into our page as we me want. All right, so here you can see that this does not look like HTML. This is not html a tall. It's actually a little bit off like a C sharp kind of hybrid C sharp html kind of hybrid. PH All right, so if you're familiar with PHP, then that kind off according is applicable in a CS HTML file. Now the default error page is here, and it is returning of you. But it's a view somewhere, and it's returning some error view model. So notice that regardless of the name, let's not look at the name off this. But if you're familiar with C Sharp and this is really a class, this is so declare class. I were returning a view with some class that is going to have some data. You notice it, seeing request i d. And it is stating what the contents off that variable should be. Essentially, this is content, so once you're going to be producing content, that's not static. So static content is like this. I typed it and I left it. However, based on this, based on what I declare this class to be on past into the view, then that can be context. So I can see if it's this type of ferro on this kind off message, etcetera, etcetera. Or maybe I want data to be displayed. And once data are dynamic, content is to be displayed than what we're using is the model. So we had the Vienna See, we have the views. We have the controllers. Now we're looking at the M, which is models on. We have a models for then, in this model swallow, we have one model called error view model on you. Notice that that is the same one that is being declared or initialized here with some content on being passed into some view that should correspond with the word error or named Eric. If we looked in the views and looking shared on, then look in the well in the share for they will see that we have that error, not CSS html view file there. All right, so when we when this serves off the era, Pidge, it is really going toe, Serve up This view with some text error and error occurred while doing your request on. Then it gives you that same request idea notice it's quoting from the model doctor request ideas. So notes in the controller where a review model request I d. So once this view is rendered, it has whatever contents were put into a review model, it can access it on. Then we can dynamically print that's toe our users using, well, the C sharp syntax. So see, we have a statement, and that's what I meant by the CS issue. Malala's was the kind of inject some C sharp with over html. All right, so moving along hopefully have a better grasp off NBC. I know that I was like a crash course, but don't worry, we have a whole course ahead of us and we will get to understand everything as we go along . So we have the app settings that Jason this is where connection string large strings are set up on whole. We want logging to be handled on dso this default connection pretty much. You can change the name if you want, but it's there on the this is going to create a database on a server called local TV. So I did say that we're using SQL Express. We're actually using a smaller version off SQL Express. And that's called local DB, which kind of comes built into visual studio. Granted, we can access it in visual studio or we can use this management studio. But that's up to us. So they're certain settings outside of the bait of bees there certain settings that we can put here on access and it's in a settings file. So if we need to change something, we just come here, change it on, move along or programmed out CS file. This is a standard file that comes with core applications, and it's really just like an initial Isar. So it's just creating the environment for the doctor core application toe. Start up and exist in on then or startup dot CS has more configurations for us, so Doctor core is very model in nature. We can put in connectors state the moat, um, you know, reference things here door France, them there. At the end of the day, this file this conflict started that ceasefire. Sorry comes with a configuration initialization on. We can figure we set up different services that are needed. So, for instance, we need toe connect to the database that is defined by the Default Connection String, which we just looked at in the up sitting so we can change the connection string here. But then we have to make sure that we change the connection string. We can change it in the conflict file. Sorry, but we have to make sure if we change it in the conflict file, that we change it in the startup that CS file reference. Also, we can configure certain defaults about our identity. Identity, once again, is what we're using. Toe handle, authentication and authorization. We set up services for controllers with views and reads. A page is so once again, dot Net Core is versatile can be used for desktop web or even console application mobile applications. So you may not necessarily need all of these depending on the context. So when you set up the project, your startup, that ceasefire is going to look very different based on what kindof project it is that you are creating. So they stop application, wouldn't need controllers and wouldn't need Razor PGE's. Our Web application does so. We do that. We also have a configure function for the environment. So is do certain things based on the type of environment, and we're using certain rotating on authentication functions on we're sitting up what the default pattern for you're browsing should look like. So there are number of things that we can set up. We're not going to make any changes, are be too intrusive in the changes in this video and throw the course We made the changes on a case by case basis. So know that we have seen how the full of structure looks and we have a better understanding off. What were you can't And I think I skipped over the data folder. So the data folder I did skip over it the data folder hoses, our DB context on our migration. So our DB context is a file where when we're sitting up the database, we won't be going into SQL Server and creating the database the traditional we were going to be using a technique called Code First, where we're actually just went to build classes that will model what are tables will look like. You have to add them to this file on. Then we have to run what we call migrations, which will actually generate the database for us based on those models that we would have created are those data classes are. So I'm not going to get into that in this. I just want you to understand what's in the data folder, but right know what I want to do is actually run this application as it is, so that we can see what our Web application looks like out off the box with no modifications done. So we clicked ice expressed that green arrow on. Then it starts what you call a debugging process where it checks. If you have any syntax errors or any, anything in your court is going to prevent it from running, so it does all of those checks on. Then, at the end off those checks, it will launch a browser with your application. So this is visual studio in debug mode. All right, so they actually low you toe click through your files Onda, but it's taken diagnostics and showing any activity based on your use off the application. While it's in this morning on here, we see our application is loaded so I can click our own. If I can click home so embarrassing that the index directory or the index view in the home controller is always going to be the default. You can change that, but it's always going to be the default on DSO. Remember, we saw that h one tag on some all other P tug. All right. And then, if you click privacy than it grows, is the home slash privacy. See that? If I change that on my right index, then it's going to go right back to our index speech on then in visual studio. While we want to see whole or application is running, What we can do is at what we call break points. So let's say I'm experiencing some form of era and I'm not exactly sure why. Are were that arrow is, um, I can set a break point. Let's see here. So this brake point, you just click along this panel between the docking bar on the cord lines, so the most well, most will turn inverted when it's in this section. But then he will return to normal here. When you click, you see that red dot and that line is highlighted in red, right? So I'm going to broz the index once again on, then what is going to do is hit this function and then proceed to do what's in the function . But then it will pause on the break point, because that's where I want application to pause or rather let me do it on the privacy pitch. So I'm going to pause on returning the view for privacy. So I'm going to go back on. Then I'm going to see privacy and then not it loses focus on the bro's, and then it highlights the line where it is. So it's in that you're about to do this process. At this point, I can choose to skip meaning I can go line by line, which are lows. Me to view all the variables and all the values being set, or I can just continue or press f five to continue on. Then the application will proceed as it should. All right, so that is essentially hole we global running or application. If I go to log in that, I think I'm going to get an error because they're certain steps that or I didn't get an error. Okay, there are certain steps we need to company before we can actually do this. So fact leak register. Then I believe I'll get that error and there we go. So it seemed that there was a database operation failure on. We need to do some migrations before we can proceed. So that's that's on activity for a later don't. But for no, I just wanted you to understand how visual studio works and how our project is settled so I can actually disclose out off this browser window. Andi, once you close the browser window, visual studio will exit, debunk more than go back to the mode where it allows you to write code freely. So that's it for the tour off the full of structural for dotnet core 3.1 application. On in the next video, we will start setting up the Leo. So you saw the Leo just know it had that kind of bootstrap feeling to it already. But we're going to just go ahead and make some modifications, at least to get started
7. Migrate Project to .NET 5: Hey guys, in this video we're going to discuss how to upgrade 2.In at five or even install it if you've never installed any.net framework at all. So dominant five is all encompassing and it is actually backwards compatible with a lot of things that you would have in your ASP.net or your dominate core 3.1 application. However, if you do desire to my agreed to.net five, then this video is for you. So our journey starts off with a simple Google search for.net five, we can follow the first link and then that will lead us to an era where we would either download the SDK or the runtime or bullet. There's really no limitation on which one you should. So you would install the SDK so that Visual Studio gives you all the tools you need to be able to create a dominant five application, whereas the runtime is more sets off libraries so that you can host the application on like on iOS. So you can check on my other video on hosting dominate core applications. And the steps you need to go through to install the runtime, prepare as, and publish your application. So for the SDK, we want to download the appropriate version on, say, if you're on Mac, Linux, Windows, they have an installation package for you. So you can go ahead and click the appropriate one. I'll go with the x 64. And once this download is completed, you will get this installer, which allows you to just go ahead and click Install. You go through any security checkpoints F2. And it's a fairly quick and straight forward process, so it will let you know and it was successful. If it wasn't successful, you probably want to double-check that you got the correct version. I'm nor Rachel, to Microsoft support. Either way, if you have the silk screen, then you're one step closer. So again, go ahead and click Close. And then if you're going to be creating our brand new project, then you can go ahead and launch Visual Studio. Click Create Project 2-0 templates. And let's go with a core web application. Click next and give it a name. So this is just a sample, so I won't be too formal with anything wet and click Create. And then on this screen you would be able to select Dot NYC core 5 from the list. And then you choose the appropriate template that you wish to work with. Change anything else, and then go ahead and click Create. So that's how you can create your first.net. So in the event that you already have core, maybe 3.1 application, then what we would do top graded is still bring up the project. Click on your what's the project file, and then this will just show the XML, XML configuration behind it. And then you are going to make a few changes. So where you see detonate core up 3.1, You don't want to change that to.net core or.net, sorry, 5. So just like that.net five-point or let me just make it done into bigger so it's more obvious. So you'll want to just replace dot. I keep on seeing dot.NET Core up 3.1 with net 5. That's step number one. The next few steps would have you updating your package or references. So Randall, all of my packages that would see 3.1, I would actually want to change them to maybe five, right? Or I could do a build. Well, my build is actually feeling because it, seeing that my dependencies are not matching up to what these expected, which is what we're about to fix. So let me take that different approach instead of building or doing anything else, we can right-click our project, go over to manage new get packages, and then look at installed. And then you'll see all of the available updates from maybe 3.1 to five or from whatever version it was at because I have some other ones that are not Microsoft dependencies directly and they are offering the upgrade options. So I'm going to go ahead and go ahead and do all of these objects. So I'm going to click updates, select all packages, and load the update. And then after that's exercise, if I do another build, then I see that everything has been successfully updated. So in a nutshell, maybe your project is different from mine in terms of the dependencies and the libraries that you're using. But the steps are me and you install the SDK, you come and change your target framework, update all of your new get packages. And then you should be good to go with.net five. If you go back to your project file, then you would see that all of them have been changed to 5. Alright, so those are the steps you can take to update your series of pages. Mvc application to.net five.
8. UPDATE - Migrate Project to .NET 6: Hey guys, welcome back. So in this lesson, I'm just going to walk you through upgrading your project from dotnet 52, dotnet six. Now, this is completely optional, and I'm only suggesting is if you took the plunge and already updated your project from dotnet, three-point one, dotnet Core 3.12 dot net five, as the previous lesson would have suggested. If you didn't take that pledge, you may continue beyond this lecture and just continue with the rest of the course using dotnet Core 3 point 1, 0.net Core 5 is backwards compatible with everything from dotnet Core 3.1. So I would suggest that you made the upgrade nonetheless. However, for this particular lesson, dotnet Sikhs are dotnet Core six is only shipped with Visual Studio 2022. So if you are using Visual Studio 2020 to and you already created the project using dotnet Core 3.1 or dotnet Core 5. Then this lesson is to guide you on how to upgrade that project to dotnet 6. So once again, you already have Visual Studio 2022 and you have the project in dotnet five or dotnet Core 3.1, then this lesson is to help you to upgrade to dotnet six. Otherwise you may proceed with the rest of this course. Everything that we're doing in this course is compatible with forward versions. Though, as you go along, you see that Visual Studio 2022 does provide some functionality that you will not see present in 2019. So in terms of the experience, you may have different things popping up on your screen. Then you will see on my screen, however, the general concepts remain the same. So enough of my monologue, let's get started. So the first step is to go over to our CSS file. Now, I am aware that you're probably not very familiar with dotnet core and that's fine. I'll go very slowly. Now, you'd see that I'm already in dotnet, in net or up 3.1, that's where I'm starting off. So that means if you are still in not core 3.1, what I'm about to do also works. So we're going to firstly date or upgrade this to see net 6. Then we're going to take two new packages and place them right here under the item group for package references. So be careful as you type these package reference include Microsoft dot, ASP NET Core, JSON Patch, and the version is 6. Same thing applies for Microsoft dots extensions dot caching abstractions version on 6. So you can hit pause and type those off. One more change that we're going to make is to the app settings.js ON file. So we're going to replace these two lines, lines 89, or at least for me there, 89, but Microsoft colon warning and Microsoft dot hosting dot lifetime information. And we're going to replace that with Microsoft dot ASP NET Core colon warning. Be sure to put in the correct quotation marks and the courts be seeing, as you see it here, hit pause and replicate accordingly. Now after you've made those changes, you can build the solution so you can hold on Control Shift and press B. Or you can just go to Build and go ahead and hit that option. And that will suggest to you is that you have certain assets that are out of sync. The reason for this is nowhere using dotnet six and our versions are not yet done. So if you're already on dotnet five, then you're going to see versions with five. You would have already updated them to five. You'd be seeing the same kind of error. So what we need to do is right-click our project and then we go down to Manage NuGet packages. And you might not be familiar with this, but as we go along in this course, you will be interacting with the package manager more. So this is a tool that allows you to make sure that you're using the correct version of libraries for the version of dotnet that you are currently using. So if you look under updates, you'll see that it came pre-packaged with certain libraries, certain packages. And a lot of the versions are off. Your versions might be different from mine, but at this point they all need to be seeing six. So what you can do is select all packages and then hit Update. And then you can go ahead and agree and click Okay to any prompts that you get. And once that updates pain is cleared, you can hit build again and then do a rebuild this time. So this will clean the solution, restore all the packages, and make sure that it sees everything according to what it expects. And once that is done unsuccessful, then you can proceed. So that is how you upgrade to dotnet 6. So you see even if you didn't upgrade dotnet five, you can still take the plunge and upgrades dotnet 6 from dotnet Core 3.1. So these do enjoy the course. Like I said, Visual Studio 2022 is different from 2019 in, in terms of some of the features. So you will be experiencing certain things like enhanced IntelliSense, more AI suggestions. And you may not see that on my screen because I'm using 2019, which is an older version. However, everything that is taught is fairly the same and backwards compatible. So you should have absolutely no problem. I readjusting accordingly. So continue and have fun.
9. Setup Website Layout: Hey, guys in this video will start modifying some of the aesthetics around our application. So I have it in people more than this is our application on. You can see it's very plain, but nobody is simply is more or less is more so. Don't mind the white spaces, but some modifications that we're going to be making include changing the name that is displayed here. CC leave on the score management. That's the actual name off our project. But that might not be the name off the application itself. So we learn how to change this. We'll get to understand that we can meet the changes one time. Are certain changes one time ideal. Rep. Ricky throw the application because or dot net core application gives or something like a lay low pH where we change things once and it is changed globally. So you notice that the knave bar on the footer are static, regardless off the page or on if I go to privacy is the same nerve bar Onda footer. If I go to register, it's the same nerve bar on footer. All right, so you know what is that? There certain things that are consistent. And that's because there is a base file that can be modified toe. You know me, these things kind of static on global in our application. So back in visual studio, and I'll just close this getting out off debug mode, and then we go back to visual studio on. We're going to be going into the views. Fuller. We're going to expand, shared on. We're going toe layout dot CSS html. So that opens up one big HTML pizza. If you've done any work with HTML and by extension bootstrap, then you should be. You know, you should be able to navigate your where on this speech. There are a few things here that are kind of different from the standard issue of peace. But as we go along, I'll explain them. No problem. So we have the standard Isham of formats, or what I call the skeleton, where we have or not type or declare their declarations at the top or head tug and or body tug all of that inside of where html tub tyrant on the inside off head. We have certain meta tags that are required for us to be both globally acceptable in our chances on also tohave are responsive. Website on these This is required by Bootstrap for spends responsive website design. Then we have our title, so the first thing I want to change is the title. So you see here it has leave on the score management, which is the OG liteks that we said we want toe get rid off on. Then you'll also notice that it's It has this at sign and something that is kind of highlighted, angry and doesn't quite look like HTML or static text. So once you see the outside on that great highlight over text, that means it's razor syntax or C sharp in html. Pretty much so. View data is a kind of variable that is available to us inside off our dot net core applications, and we can kind of sit the view data to be what we wanted to be from the controller on. Then that is what will get printed in this section off the title on then the hyphen and leave management ecstatic. So I'm actually just going to change this on. I went to call our application core, leave management so for more context, pretty much when you go on amazon dot com and click on the credit speech. If you look in your Tubb, you do realize that you see products hyphen, amazon dot com. Or maybe see amazon dot com hyphen. Some indicate off What pager on this is pretty much all they do. Amazon dot com would be static. That never changes. But then they dynamically tell you what pager on based on when you grows. So if I go back to controllers are rather if I go back to the views off home on I Click Index than you see here that we're actually setting the View data title Toby Homepage on, then in the layout it is going to be printing whatever I put in that title and then hyphen , whatever static fixed I put there. So for every piece that we will create, we can if you want to. If you want to be that meticulous, no problem. You just make sure that you are very particular about what you put there. So homepage hyphen core leave application is what will get loaded when we Breaux's so our homepage on for privacy, it will be privacy policy, hyphen core leave management all right, so that so that view data section works on. Then you see that we're referencing our bootstraps bootstraps style sheet, as well as the site that CSS and links the CSS slash site. That CSS and that's going from our www roots uses Fuller. That site on this one is going from the lib bootstrap folder Beast CSS on in that we have the bootstraps files. All right, so that's how those links work and by extension that it's similar for the script file. So the scripts are usually referenced at the bottom off the page so that the P surrenders before the script files render because, you know, we don't want him keep our people waiting on DSO Modern technique would have us put the script files at the bottom of the pizza that a content can lord until the strip fire loads . So we have that on. We also have a section I get to the section Enough, you know, let's start by modifying over enough bar. So are enough. Bar is a bootstrap enough bar on def. You're not so familiar with bootstrap Party wants more reinforcement with what you can do with Bootstrap, then you can go to their website, get bootstrap dot com, where you will have access to all off their documentation, examples and so on. So Bush, up 4.4, is the latest. That's and that's what Well, I'm not sure if it's four point for that the project comes with, but it's definitely four. So your if you're not the latest and you're pretty close to the latest on once again covers building, so we don't have to pay attention, much attention to the installation directions. But if you want to understand, hold enough by works and hold the classes work. Then we can go toe. I believe it's documentation on. Then we can look for you to tease if start utilities than its components. Andi, As you can see, it's quite a big document, but in components and we have nuff buyer. So when we click enough bar, then it brings us to the section where we can actually look at the core that is required for enough buyer. And that's the example off what the court below will render for you so you can be guy that you can use this, um, guide to understand the court better, but I'm going to be walking through some of the changes that we'll be making for our application. So firstly, I don't want a light enough bars. We have an option off light on. Dark on. Let me just go back. Onda show you the different options. You have Siberia. You have dark hair blue, We have light blue. I wanted to be enough bar dark on BG Dash dark. So I'm going to go back to my court and I see here I have not bar dash light. That's almost the default. So I'm going to see dash dark on going to change this to B G dash dark. But then if I erase that I do cultural space, then you see the visual studio court kindof gives me, um you know, some what we call intelligence. So it helps you as you go along with your court. Even with bootstrap classes, I did so RBG dark. So I'm selecting BG dark on. That is one change that I'm making that I'm going to make some changes to my navigation properties. So for each link that appears in enough bar, you need an ally with the class now item on. Then you have an uncle tug with Charles. Will the classes for the ANC attack already want them to look So I want it takes to be text dash on. I wanted to be white. I believe I can see a wife's right. So I need the text to be white because the nuff buyer is going to be dark. All right, so I'm kind off inverting it here. All right, so my novel ing on, then the text dash white is going to make it white text on spe area is be controller, eyes equal to home. And the action is index. So that means that when I click this home Ling all right, like we did when we went into the book. More decide come upon where home and privacy links. So this is the home link on. This is the privacy link. When you click, the homelink is going to look for the controller called home. Right. And we did establish that we have a controller called home right on. Then it's going to look for the action. Is an action is pretty much that function that I showed the inside off the controller so you see that it's called action result. So the action is that function on did. It must have the name index. So it's looking for an action called Index. And so when I click home, that is my user request to see the index action or view in the home controller. So when I click home is going to look for firstly that controls of that controller doesn't exist and you get an error. All right, then, if it does find it, then it's going to look for the action inside it. And if it doesn't exist, you also get an early. If it does exist, then it's going to do whatever is inside that space for. The function in this case is just returning the view, So it's no one to look in the Views folder for the corresponding home views collection on. Then it's going toe. Render our index content. No, the index content is over each one talk that says Welcome and our Peter that has some link and some narrative about that night court. So what happens is that when we click that this is the Leo pitch, whatever view is returned by over action gets rendered inside off Orender body. All right, so this is our hitter. Six on with enough bar and then we go on to the content section. So once again, I'm doing all of this, assuming that you have some exposure to HTML on. So you know that Mishima PGE After you do your hit and body tubs which are required absolutely required for proper structure. The new structure your page of the hitter section which usually has enough by on your banners and whatever else. And then you have the contents that's on the page on all of that, most of the footer. So if you look at it closely, you see that are male Peach has the header section with our enough bar right which has all our links on. It also has, ah what we call a partial for the lugging functions. All right, but then we also have a give that has a class called container on this is the main sections that is the content section off all upset on. Every view gets rendered inside off this section which is why or view can be so lightweight because we don't have to go through and be clear All off the html syntax and everything. Every time we have of you, we just need to focus on the HTML that is required for that. Particulate bit off contents to be rendered toe the pH. All right, on. So it's rendered as in this section, inside of the container on Contin Aires, a bootstrap class that gives us, like a nice 80% fill on any screen that is being viewed on. All right, so I'm just walking through this will come back and modify our enough bar a bit in a bit because they're something sonny to our butts going on, we add, we have our container, which renders our view content each time. And then we have our footer. So our footer section I'm not going to modify the aesthetics off it, but I do want to modify the content. So we have the copy, um, percent copy, chemical. And this gives us that copyright sign right on. Then I want to change this, and I'm going to show you some bits off. Um, razor syntax. So remember that razor close us toe put c sharp instead of four html syntax. Pretty much so. I'm going to modify this year, Toby more dynamic because right now it's 2019 and I'm actually recording this video on New Year's Eve so literally tomorrow is going to be 2020. So I'm just making that known so that going forward when you see 2020 in my Footer, even though we started out 2019 year when to sit 2020 this is why. So it system to 19 and it's static as 2019. So I'm what's going toe. Use some c sharp to make it more dynamics. I'm going to say at sign date time, all right, and then I can see No. So if I ever wanted to know the time No, As I'm talking, I would use the timed up. No, But then I want only the year so I can see dot on. Then only get the year. So what is going to do is have the copyright sign on, then get the year as acts the time the Web application is loading, or the year according to the time on the server it is looting from, So my computer is accurate, fairly accurate. So tomorrow any changes 2020 then my daytime will be 2020 if the server time is wrong. Lord applicator are the computer time is wrong, then Obviously this this value will be wrong. But the fact is, it's dynamic. It's not going to be 2019 even when it's 2020 and 2021. So I'm just making that a bit more than and become just demonstrating. Whole c sharp can be inserted into our HTML quite easily through the razor engine art on. Then I'm changing this text on DSO. They should also say core leave management. And I'm going to copy this so that I don't have stepped again on I leave that privacy link and then we have or script, um, files being loaded. So FRG query script fire being loaded the bootstrap JavaScript fire being loaded on our custom site that Js file, which is also coming from our doublet of your route. Gs Fuller. No, please notes that with scripts and with CSS, the order matters. So that means sometimes you try to install some, you know, like a J quarry. We guitar something, and then you put the script references above the Jake Worry reference. That's a no no, because then you just get a rosy won't work and then you see Oh, my God, what am I doing wrong? I can't do this. So the order matters. So I just recommend that any additional script files that you're going to be adding that are not Jake or, er, bootstrap. You just put them underneath. They just keep on adding, adding, I think I think I never put above All right, that's a good rule of thumb off course, case by case. If you understand what you're doing, then that's fine. But just to stay out of trouble, if you're not so sure, just always add them below on. Then we have our intersection here. So remember, let Orender body, which is rendering off our views. In that section, we have render section well, which is caused scripts, which I lose us the insert scripts in the view on a case by case basis, because we may not need every script five for every single view. All right, so you want to reduce our fires, The Lord on what pages. So as we go along, we'll see the purpose off this, but I'm just letting you know what it's for. you don't have to remove. You can if you want to. You don't have to. I would say don't aren't so Then what? We'll do? No, it just make final touches. Store enough bar. I just want to change at the top here, where we have the first section on debt saying leave management and want to put in the application in which is score leave management. So this is the text that will be printed in the nav bar itself. We don't have to trouble much more, but I'm just going to add some other links here. So we have home. We have privacy. I have a few other links. That's our key toe, our pending activities. So I wrote 1/4 and I'm just going to replace the existing chord with the new court and just give you a quick run through of what I'm doing. Some replacing the privacy link with my additional cord on DSO. Once again, we're building a leave management system. So the first thing that I put in police privacy is one that's is apply for leave on. I'm just going to make sure that my text is also white. All right, so apply for leave. That's what the employer will be doing. And then I have another one, and this one is in the form of a drop down. So this is how you do drop Don's on. Actually, I just took the example cord from bootstrap dot com because they did have a drop down example. And in their drop down example, they said that to get a drop down link, right, that's a drop down link that we need to goto l I We need toe have core that looks like this . So I just copied this and then modify the parts that I wanted a key. The drop. Don't link text on the actual action or anchor tugs. Rather. So I might me that modification on. So I have the drop down items and I have all of them. But as we go along, we'll be filling them in as we put in the functions. Then we'll meet the links work. So right now, that's not my objective. I just want my nut bar to look slightly like what I expect to look. Andi, I'm just going toe, uh, teak this text dash white and make sure that it is inside off each drop down item to make sure that takes these white. But I'm. Then I'm going to just go and debug and see what it looks like. All right, so this is what it looks like, right? No. On dso you see that the number has changed too dark on did so many things are still not takes dash white. So you see that they're hidden over here. But then the others are So those are little things that you know as you go along you test and then your allies Oh, I didn't currently let me change it on another thing. You do realize that I changed my drop buildings to text That's white while the drop down is white So everything here is white, So I'm just going to go about me. Those modifications on the good thing is that you can actually change the court while in debug mode. So let me start off with the partial. So I'm going to find my solution explorer, which may have changed opposite position on I'm going to go to the logging pyre show. So this log in partial hoses, the links for the logging and register some changing this toe white. And I'm going to change this one to white also on, then save on. Then I can just meet the change and see even go back to my debug mode Refresh on down Once the changes are reflected, then you know that you've done something right? So I just went ahead and made all the changes to me. These text dash dark on dso know you're seeing everything. All right, so we have our application name. It could be a logo. You know, I'm just doing it us application name right now. Andi. So whatever changes we make, they would ripple across every view that is going to be rendered inside this section, which is between our nav bar on our footer on. So that's a quick introduction toe making aesthetic changes to your application as you see fit. If you gotta feel maybe you have the admin, lt. Whatever it is, whatever theme it is you got or whatever Look and feel you're going for you can just me the changes one time in the layout stocks CSH in a file on day will be global. Toe your application if you want more than one loads and you can actually create another layered file on on a case by case basis. You reference that Leo file inside the view. We haven't created any views just yet. So when we reached that point, then you see what I mean by referencing. It's in the view so you can go ahead and me those changes and any other that you see fit. Andi. In the next video, we will start creating our database.
10. Setup Database, Models and Migrations: Hey, guys, Welcome back in this video, we'll start modeling over database, and on my screen is an actual data model off what we will be creating using our entity framework called first Technique. Now, this is a data model diagram on. Let me see if I can get a bit bigger for you. All right, So I got it'll be bigger on the screen. Andi eat rectangular, or each box represents Ah, table. So you see here that some have the named are the words ISS be net at the start. So have s peanut user claims is peanut users etcetera? These are all kind off auto generated by our identity. Um, built in identity functionality given to us by s p dot net Core know we have some other tables that we will be creating manually on there. Here below. Leave histories. Leave type Steve allocations. We may want more one. We me want less as we go along with refined the design on. That's what court first I lows us to do by keeping all off for database design on court. Kind off in one kind of structure so that we can I just as we go along, So I'm just giving you an overview of what we're about to create and notice that relationships will be created on will be walking through how each of these things will be facilitated in our actual the adults. Now let's so head over to visual studio and start designing or classes. So, firstly, we have a folder here called Data on. Whatever goes in data is, you know, it's recommended that it has to do with the database. So using court first, what we'll be doing is creating some court classes that will be converted into the beat of the stables that we just saw. But to start off, we want to generate our database are set up by beat obese on, so we can continue working with that data base. So the first thing that we want to do is go to our up settings that Jason on we have the default connection with the connection String toe. Our database of this entire string represents a connection. String the different database engines. The string may look differently. Um, we're using ah, built in database engine called local BB. It Zaveri Avery Light version off SQL. And it's kind off native. Well, it comes with visual studio. So by installing results to you, you would have gotten that database engine on DSO. That's the one that we're using. So to connect to that engine, we need to say server equals on. Then it's should already be there. Local db slash slash m. S s que a local db so we won't have to change that part. But then for database welcomes in this section should be the name off the database that we wanted to create. So he gave us Ah, well on our degenerated name with a good, But that's not necessarily what I want. That's quite a mouthful. So I'm just going to simplify this a bit on. I'm going to call it leave management. So I'm going to take it all off that on databases equal to leave management. So when we execute well, we need to execute to generate the database in our database should be leave on the score management. That's what we're looking for on. Then we can leave everything else toe the defaults for no. At least you don't have to trouble those on then if you remember when we tried toe register . It told us that we needed to set up the database and we needed to do a migration and all sorts of fancy words. So that's all we're going to do? No. So, off the backs, what's going to happen is it has migrations. So if we're going to the data folder and the migrations for their and we see that we have here a file with a bunch of zeros and it is create identity schema So if we take a quick look in this migration file will see that we have an open my third on. If I collapse that we see that we also have ah dull method. So the don't method based callouses. Okay, let me remove these on then. The up methods is let me create these and these are the constraints for the creations. So it's going to create a SP net Rolls s peanut users. All of these things are default. And if you look in SP users, you see all off the columns and the constraints that they will have all of these wonderful things. I'm not telling you to study this file and become an expert in this fire necessarily this was once again also generated because we selected individual user consular creating our project on As we go along, we will see that this kind of file will get generated with the different changes that we make right, So toe effect a migration. What we want to do is look for the package manager console, so it should be at the bottom off the visual studio window. If it's not there, then you can disco to view Onda. I'm sorry. Not view but fools actually tools. Then you get package manager on the package manager consoles. When you click that, then this window that I have highlighted here should be made available to you on. Then what we'll see is update cash databases. So there are actually two steps to this. But then the first step is already kind of taking care of because we have the migration file already. I'm not going to get much into that When we start building out our database, you see the relevance of that. But we have the migration first. What we need to do is update the database, so play database basically says if there is a database that I'm going to meet the changes as I like to me. Based on the migration file that is most recent on diff, there is no database than this. Command is actually going to go ahead and create the database based on the migration files that are available. So when I say up the database and press enter is going to go into our own off processing, it's going to build a project on. Then once that successful, then we will get a message seeing done. So if you got no error messages, you didn't get any red writing or every yellow writing, and it's something looks at this that means something went very right. So once you've done that, then we can verify that a database was created based on the name that you put your. So I put leave on the score management. So I'm expecting to see a database called Leave on the Score Management. So to get to the databases, what we'll do is go to view on. Then we will look for the SQL server object explore. So this is like a built in SQL server management um, dashboard, that visa student makes available to us on by default is looking at the local DB instance that's built into visual studio. So I already have it here. I can expand this expand SQL server on then inside of SQL Server, you would see to local db incenses. So we're going with the m s s que a local db as outlined in our clinician string and I'll expand that on then in the list off databases I see leave management. So if I expand, leave punishment and expand the tables then we'll see that some tables were created based on that last migration on we gets like a migration history which is just a trucking table on all off those is being net tables that we saw in our previous Montel diagram. So that's how easy was to roll out all of those tables required for our authentication andare user on rules management, it stands if I try to register again, I shouldn't get an error about, you know, missing database Operation block right. It should work. No. However, our work is not done because we still have some other tables that are required that are not necessarily just about the users and so to create our tables the first thing I'm going to do and understand to collapse what is not absolutely necessary to the task at hand. Someone to close the migration, find clothes or g son file on. The first thing that we want to do is create on like an employee profile table. So I'm going to write Clickbait er goto ad class on. Then I'm going to create a new file on Ball a new class and I'm calling it employees. It's a class on the name off. The cast is employee. Someone to click, add and then this gives me on employee class No on employees usually has first name, last name tax I D. Date off birthday joint. You can add other things. You know, whatever makes up on employee in the organization you work with what These are the properties that I am working with on Soto at our property you can while you can go the long way and right public string the name off the property which in this case will be first name on. Then we can just have imaginary get on set. Ah shorter. We are quicker way to do this is to write the word prop That's P R O P. Pressed up twice on. Then. Visual studio kind of generates that line for you, so the data type would be string again. He pressed up to move from data type toe property name and the name is last name on. Then you disperse, enter and then move along to the next line. So whichever way you find easier to do it, you can do it that way. But once again, we're doing first name, last name Tax I d. On date of birth. And so that is what our class is expected to look like. First name, last name Tax I D date off birth. The joint off course two days are off type beat time are on. Then we can have one more so I can just duplicate this land by holding on control and pressing b notice. I didn't have to highlight the lions off course. You can copy and paste, but just by clicking in the line on holding on control and President de it will duplicate as many times as you do That key combination on I'm going to put this as did created meaning bit. The employee record was added to our database so you can add as many as you want. So that was just an example. I won't be going forward with the it created. So this is what my employee profile will look like. You know? Another thing to note is that the employee pretty much is the user, so I don't want to have a user table andan employee table separate. I would like the user table, which has using in the password on Do you know other little details about the user that help with authentication can also have the details off what an employee should have so in orderto extend that table. So remember that the user table is actually generated for us, and I can just go back to escalate object Explorer on expand that user stable on Look at the columns on Then the columns would have, you know, an I D, which is a primary key. The user name a normalized using him the email address. So all of those things are already included in the SB net User stable, but then I want these properties first Name, last name tax I D data birthdate joint toe Also be ah part off that user table. So what I'm going to do is extend this table toe also have these properties on to do that. What I'm going to do is use inheritance. So use our colon on that. I'm going to specify a class name, which, in this case, is identity User. So identity user is, ah, class that represents the stable. This is spin it user stable is represented by the table identity user. You noticed that red line. We can just click there on then if we over over, we get that little white ball that is suggesting how we might fix it on the fix for it is to include some missing library, which is SB net core identity. So just by including that library in our library listing at the top, we saw the problem. And then we have no more errors for our employees, Gus. Now we can roll these changes directly to the database, seem at the same time by one creating a migration and then to update in the database. So I'm going to first go back to our package manager console. So this is the first class that I've added on Well, before I get there, there's actually one more step that I need to complete, which is the ad it. So our DB Context files. So I need to click on application db. Context are so we see here that's the class and it's it's called Application Devi context. But their true power comes from its inheritance off the other class identity db context Right on Then we have ah constructor here. So underneath the constructor, I need to tell it that in constructing the database in doing whatever it is you do by default, you also need this are these stables so than most recently created Table is employees, which is inheriting from identity user. So I need to see public on then say db set open under bracket. I noticed intelligence is guiding me as I go along, So I need employees on then. So this is a class that I expect to become a table, but that I need to give it an actual names. I'm going to call it employees on then I have my generic get Andi sit. So no, I just created property inside off the application db context and told you that it should be a part off the DB set. So whenever it's generating the database of data into database, whatever it needs to do, it needs to make sure that the employee class is accounted for. On it is rollout into a table or by by the way we defined it. It extends the identity user class, are SP user. It's being that user also includes what employees has to offer. So when we do that, then we can run a migration. So then we go back to our package manager console and then we say, add hyphen migration on, then we give it a name. So of course you want to keep Indian scanned off unique so that we can track changes me to the database. It's easy to say, Oh, that's what I did at that point. So I'll see added employees eat up points because that's what we did. We added employees data points that identity user class on. Then once we add migration and we press enter is going toe to build on, then generate that migration file on this generated migration. Fat is actually going toe have the same up and don't functions that we just saw in the other one. So in the up function you see here, it's actually doing some at columns, and it's seeing ad ah column off types, string TSP users. Here's one off the time be joined. It's adding it to the SP Net users date of birth, all the data points that I said I wanted to be a part of the S peanut users. It's going to add them to its heart. So that's what this migration five does know. After doing all of that. The next thing I want to do is up the it the database press enter, and then we get to notice that this has been done. So if we go back to our object explorer on while, I already have the table open, So if I just click it and click refresh, which I think is just going to refresh the entire view anyway, all right, and then we drill back, don't into our table. Then you see that the new columns air there we have did joined with a bit of birth were first name, last name tax I D. So that's actually how easy to still be it. This database And if we don't want a column. We can go back, remove the column from it. But then off course, we have to do a migration and then update the database once again. So essentially, if you were to share this cold with somebody, or I know this project on you told them, Okay, here is a project. You need a database. We can just run the update database. And what the engine is actually going to do is go from the first file to the most recent file, and it's actually going to roll out all of those changes using the opened on methods to know exactly what changes he needs to make to create the most recent version off the database based on where the project was, as at that time. All right. So that's why the court first technique is kind of easy to track. What changes are being made to your database. Overtime Onda help people to know exactly what's going on when all right, so we added one table or we extended one table. But we have three tables that we need to act. So I'm just going to go ahead and create another class. I'm right clicking, data clicking, add picking class on. Then the next table that we are going to add is leave history. So we add Leave history on. I'm just going to go ahead and at all the classes before I start putting any properties in them. So we have leave history. We have leave type because, well, she leave. History's going to believe record. The leaf type is a type off leave that the person took with its maternal paternal or, you know, vacation on. Then we're going tohave the leave allocation table, which is also storing what? How many days each employee has for each type off leave right so you can have 10 vacation these but five sixties etcetera, etcetera. So those are the three tables that were setting up to begin with Onda as we go along the first Andi easiest one really to do will believe types because the other tables have dependence is on leave type, so I'm going to create or go back to our leave type class on. Then what I'm going to do is put in three properties. So remember I can say prop on our part instead. So that's public. I d I I didn't I d sorry. So the idea would be the primary key off the table. So it's always good. Database descent always have a primary key. Another property would be the name name being the type off. Leave your name off the type off leave. So string name on down. One more, Which would be did time on this would be deed created. All right, I'm kind of mixing my lines here. So once again, you can t this kind of shorter way off writing in the properties. Or you can write them in the long way. Either way works. But then we need what we call attributes. Still kind of specified to the database that when you're generating this table, this is what is required for these, right? So, for instance, I am going to put a key attributes over the I. D property. All right, So that is specifying that this is the key property and it has a red line. I'll get back to it afterwards on then for the name. I'm going to specify that this one is required so in databases and you can alot are not alone knows so without the required t bird t word. Then this would have Bean generated as a column that alos knows what then It doesn't make sense to create a leaf type with no name. If there's no name, then there can't be a leaf type, right? I'm not going to be so hard and fast on the date created because I can force that value later on. But at least I want to show you that we have that tributes to have the square bracket, the word or the name off the attribute and close square bracket. So the red lines once again indicate that something is missing so we can hover over it, click our light bulb and get there the solution. Or we can. If we're just typing out, we can't bother with the most. You just meet the currents are going right in the middle of the world and then hold on control and press dot on. Then it will give us a suggestion on the less so that's another short keyboard shark card that you can use. So I'm just going to go ahead with the suggestion toe include the component model data on notations in leave type. So we have key. So the database, you know that this is the primary key for the stable and it gets generated on the required meaning that this should be generated as not snow. And then I can see if this file next file to be modified is leave allocations to leave a location. It will have the property i d which is also going to have that key attributes. So I'm just going to control that, get the suggestion and let it be done. We're also going toe have properties for the number off these which will be in the form of integer on for the dates that the record is created. So we have public into number off these on we have the daytime be created on. Then we're going tohave reference toe the employees for whom these allegations are being made as well as the type off leave that the allegations are being made again. So let's just think about it. I am an employee. I have an I d on. I'm being allocated five, which is number off these sick days, right? So I'm getting 56 days, so you need to know who I am or who the employee is as well as the type off. Leave that this number off this is being a pick you apply toe applied to. Sorry. So what we need to do know is see public So we'll start off with the employee reference. So we say public employees. All right on then we can just give the property the same name employees get set. So this is saying toward database engine that we need to somehow make sure that we're referencing employees or that the employee toe whom this leave allocation record is going to be related toe the details off that employees are available for selection. If I'm looking at that allocation right on, then I'm going to see employee I d. Because I still need that property for the employee i d. Which is what will actually often so employees. So actually, the employee i d is going to be a string And why do I know it's a string? Because if I go into my object explorer and look at this property four I'd iate is on environ Shar It's not onion. So traditionally in I always teach later basins they use in their using Ah Geo I d. All right, a unique identify which is usually ever a long string. And that's fine. So I'm just going to say, Public string on, then see employees I d. On the get and sit. All right, So no, it seemed that for whatever employee I D is referenced here. I can get all the details and store instead off employees, objects that is apart off believe allocation class or record right on. Then we'll do similar things for our leaf type because we still need to know what leave tax is there. We may want the details, so I'm just going to put the leave type on the leaf type i D. No to other attributes or well, another attribute that needs to be added is one for the foreign key, where we actually can dictate the name that the foreign key should have in the table on while it's not much different here, so I'm just going to say, foreign key on the foreign key for the employees. Foreign key is employee I d. On. We'll see it again for the leave type on its leave type I D. So it looks kind of redundant. No, because those are the actual names off the foreign key, but, um, properties. But then in the next table, you see where it actually comes in handy. But then you see that I have read lines, and that's because I need to include something else. So I just use my light bulb. Get rid of that reference on this time. It's data anarchy annotations dot schema. So know I can save this file and then move along to the next one on this next one is leave history and leave histories quite beaks. I'm just going to hurry up on, write them in, and then I'll just let you know what was done are so leave. History is going to have a lot more data than the other two tables, and we're just going to walk through them first. Then we start out with the key, which, as I said before, is traditionally an integer. Then we move on to our first foreign key reference. Now, remember that I said earlier that the foreign key, um attribute cannot tells us what we want to be called. So I mean, I try to keep it kind of the same texting text, but it might be different in your case, but the fact is, a foreign key is requesting employee I d on. Then that would be the employee who is requesting the leaves. So that's another foreign key referenced over user table or employee table. No, you're probably wondering, OK, but the employee table didn't have an I D. So if you go back to our employees class, remember that we put five properties. Here are six Properties five, But then we are extending identity user. So whatever identity User has as its own properties, which I can actually will, it's kind of hard to see what identity user has the offer as its own properties. But then, if we go to the database, you can see the columns that are there than employees actually embodies this identity user class. So whatever it is from the identity user class or from the ESPN it user stable that we want , we can actually access it just by referencing or employee table, because our employees class is inheriting the properties from the identity user. So you want the employees idea. We also have our public started public ended, so from when to when should leave be applicable. We have the leaf type. So I'm requesting I am requesting a leave from this dates to that date on. I want this type off. Leave, right. Seek vacation, etcetera. On. Then the request was made the day it it was action and action here presents whether it was approved or not. So you see here that have public bull approved and this bull boonies yes or no? But it also has a question mark. So that kind of gives me a little cheat. Where can have third state off? No. All right, so this means it's notable so it can be put in with a no approved state or ah, yes. Value are no value. No, obviously would mean that it's pending. It doesn't mean action does yet so did action would be blank. While this is no. Once the state off this changes, then the expectation is that we make sure that the date action also changes on. Then we have another foreign key linking toe our employees table on this time it's approved by I D. So I mean, you're an employee, your making the request. Whoever is approving it is probably also on employees off the company. So we want to know who approved. Um, your leave are forever. Action, You're leave. What? They approved it are denied it. Andi. So we can track who requested it, Who approved it on Some did sometimes and details around what was being requested. So that is what the leave history table has in store for us. Know, once we've created these three data classes, we need to make sure that we wrap them up in the application db context. So we did that with the employee table on. So we have to make sure that we do that with the other three tables. So in this following the same pattern that it's a public DB set the name off the class that was created on then the name off the table, so you'll notice that I have This is my naming convention where I call the class by its singular states. But then I call the till by it's plural state because the tape is usually a collection off the properties that make up a singular states. Right. So this is one instance off, and this is many instances, right? So I mean, you can put in your own name and convention. There is nothing hard and possible that, but this is mine. So I have leave history, leave histories, leave type leave types leave allocation to leave. Allocations are so know that I've done all of those things with the tables are set of my data classes. Andi, I have settled the DB context. The next thing I'm going to do is start or at another migration, some which is a add dash migration. And then I want to say I did leave detail tables on in, press, enter and then this will generate over new migration file on def. You just dropped on migrations and you see each file. So were the 1st 1 The one that I did. Employees I know are most recent one on his can see that it's time stumped. Underscore Whatever name we gave it in the command Right on. You can take your time and analyze what is being done. If you wish. I'm not going to spend time on that. I'm just going to go ahead on and execute the migration by doing up the database. So using the up command opened on keyboard arrows. You can actually cycle through all of commands that you've ever in this console. So the database and press enter on, I'm going to wait until that's finished. All right, So I got a don't message with no errors. And if I go back to my SQL server Object Explorer and refresh on, then go back into my database on tables, then I should be seeing all off the existing S bean it tables as well as my leave allocations, my leave histories on leave types. And if I look at the columns than the columns and the date it as the names and the data types should all kind of correspond with what I designed and you see where the foreign keys are on, everything looks quite in order. So that is my database creation. So once again, any table you want to create the preferred are recommended, Please, for you to put the template class. I call it a template class or the data class I say is in the data folder. Remember, to add it to the application BB context as a DB set class or property on, then you need to create a migration using the package manager console. So you see, add hyphen migration the name off the migration on. Then once that is done, then you see upbeat database. If you have no errors, then you should end up as far ahead as I am. If you have some errors, feel free to contact me and I can help you to work through with them.
11. Setup Repository and Dependency Injection: Hey, guys, welcome back. In this video we will start implementing or repository pattern on setting off our project with dependency injection. Now, before we get into what those fancy words mean Repository Independence injection. Let's look at an application at the most basic level. We just set up the data classes or database objects which are load us to generate a database. No any application that is owed their with its A website or it's at this stop application, even a mobile up most of these applications, especially if they interact with a database or some form of beat a store. They're allowing us as users to do four things with that data. It's either allowing us to create the data, read the data or, you know seats review it. Update data meaning make changes. The existing data or remove data are delete for shorts. The acronym for those four operations is crowd crud. See for creates R for read you for updates on before delete. So once again, no matter how fancy the application looks, no matter hoe flashy. It is when you hit the delete to see an animation and all those things, no matter whole flashy looks at the end of the day. The most basic operation is that it is removing data from the database or creating beat and a database, either presenting it to you. See click on your profile on maybe Facebook and you're seeing all the information that you previously entered. Then you're viewing. The data are reading the data. If you make a change to your data, your profile on Facebook, then you're updating the data. That's it at the end off the B. So our repository pattern pretty much is a very popular pattern. It's a way off writing and structuring your court. That's what we mean when we say patterns on DIT is very, very popular at the enterprise level application development. It helps us toe restrict hole. We interact with the data and create layers are owned the database operations, the business logic on the U. S. So we spend some time. We can't do you. I, which would be more defend the look and feel on. That's the presentation to the user. And then the business logic will probably come more in the controllers when we start building ought our controls for different models. But right now we're focusing on the database operations, and that's really where that repository pattern is going to come into play. So I'm going to create a new folder in this project structure. So understand, toe collapse, everything that is not absolutely necessary right now on I'm going to create two new Fuller's the 1st 1 And just by clicking the project, I'm going to right click on that. I'm going to see Add on, then folder and then the 1st 1 I'm going to call it contracts on. Then the second folder Son was going to repeat those steps. I'm going to call Repository. I know if you were taking note, but while I had this selected, this court actually got modified as I added more, um, folders. So you see, created to interest for the contacts under Repository Folder. So we don't need to see this file. Really. We can close that. So the first thing I want to do is add uh, contract on the contracts are pretty much the interferes is so they're positive they're repository pattern would have us create interfaces, onda classes that implement the interface. So our interferes is like a template for what are class should have, and I'm going to explain that. So the first contract I'm going to create, I just right click goto ad on. Then I went to see class, but I'm not really creating a class. I'm creating an interfere. So using this same Poppel box on was going to select interferes instead on Then I'm going to call this one I repository beasts. All right, So, like I said before, therefore, major operations that every database, most databases or applications rather allow us to do against the database that's create data, view data or manipulated the data whether we're deleting it, are making a change. So the first thing I'm going to do with this interferes is I'm going to make it very generic because every type off database table or in our situation, data class or domain class employees live up. I look, your son leave history. They're all going toe a loss or a four disabilities to perform crowd against the records that are in these tables. So I'm going to create this base, interferes on going to make it public on this based interface is going toe, have some generic identify air called T on that I'm just going to see a were t colon class . So what this is saying is that I'm making this interface generic enough that I can pass any class in here on that class should be able to perform whatever operations I'm going toe online. All right, So this is making this base repository generic enough on the generic or global operations that each class are each table should be able to perform would be to create, update, delete on view part. So, having done that, I'm going to actually just right off the operations that should be implemented once we are implementing database operations around any class that is being passed in. So the 1st 1 that I'm going to do is find also I'm using I collection. So this is legendary comic collection class. So if you're familiar with C sharp, you know that See Sherpas A number of collections you have list you have innumerable, like wearable. I collection is generic enough that you can almost be any off those. But then if if you're not familiar with C sharp than just think of it as an ar e. All right, so this is just saying that I am accepting any type off ari off objects that might be passed in. So any type off area that's a collection off type T T would be your class. But then, because I'm making tea and making generics or tea, here is just a generic identify Rare to say that any class where they will believe type leave history can go there on the operation would be to find all which means I'm returning all from the database. And if you're familiar with databases and SQL, that'll be like a select star from whatever the table name is hard. So that's the find all on. Then the next one to view would be toe if I wanted to see only one record, and I would probably want to find that one record by I D. So I'm creating another function. The creation was like a function hitter to see some class on. I want to find that record by I D. And I'm accepting some integer parameter called idee, but we do know that we may not have integer parameters. We may have another one, but that's fine. We can leave it as integer for no another set off commands would be to create update and delete. So I'm going to put those in on I'm seeing bull because I want indicate, as the whole successful this operation was, Sobule will return yes or no on based on DS Arnott, I can use my business logic toe handle Hold the u I presents the era our success to the user, right? So I don't want to get too much into that. I just want to say I appreciate what's happening as we're building on this class. So this based repository classes going toe have ah function to get all records off. Whatever class type I'm looking for table I'm looking for I want to find a specific record based on the i d. That is provided Andi want to create some entity off type T So the variable name is entity that's generic enough on the type Eesti, which is also generic and the same for update and delete on our final operation, would be to save now once again, this is all generic and this is a base. This is a base interface, so that means every other interferes for any other specific table should inherit from this base because these four operations are here defined for everybody on then in that particular interface, if there are other operations that I needed for that particular table, then we can implement them there. So as a first act, I'm going to implement a repository for our leave type. Since that one has no dependencies, that should be the easiest want. Implement someone to right click or contracts folder Goto ad add on C class. But once again we're adding an inter fees on notice that the naming convention for the interfaces would be I on whatever it is. So in this case, I'm calling it. I leave type repository, right? That's that. That's my naming convention. So I just click Add on, Then when that creates its one, I want to make it public to avoid any errors going forward on. Then I can know alot my I leave repository toe leave type repository Sorry Teoh inherit from my base repository. So I just did repository base Right on then. Remember that repository based should have some type some variable type being declared with it some class type brother being declared with it and decision Eric So since I'm dealing with the leaf type repository. Then I'm going to pass in the leave type as on my auto. Complete is it's completing informal, but that's not what I want. I want leave type and I went to press escape this time instead of enter. So leaf type is a class that I expected to interrupt with. All right on then off course is going to give me an error because they're in different folders, different name spaces. I just need to include that. So I just over their control on full stop and then press enter, and then it will add that reference to the folder where Leaf type is on. Then we have. It's no added. So that's how you go about making this interface inherit from or leave type from, or a repository Bees. So know that I have template ID what should happen. And once again, I'm trying to keep it simple because we're at the start eso this I leave. Repository is no one to define the database operations that are actually implemented in our repository. So I'm going to go on create class and this time is going to be a class in a repository folder Someone directly that click Add go to class on the Leavitt US class on. Then I'm calling this one leave type repository. Alright on. Then I click at. So no, I have a new class that's called leaf type repository. It's blank on. The expectation is that whatever was defined inside off this repository should be defined inside of discuss notice. Nothing was defined in this repository in This interferes rather, but it is inheriting from I repository base, which has five functions defined, which means that we expect toe for five functions declared rather on. So we expect to define the behavior off those five functions inside off leaf type repository. So the quickest way to get them in is inherit from our I leave type repository on. I'll explain why we don't just inherit from I repository beast over here. I'll explain that, but for no, let's just work with this. So I leave type repository on. I'm just copying that on that I'm going to make it inherit from that and then once I do that, you're going to separate line. No. Firstly, I need to include the name space where the contracts are on, Then use notice that the red line is still there. If I hover this time, it's a different arrow. It's no saying that it does not implement the Interferes member and notice it seems all off those functions coming from the repository base. All right, so it is expecting that if I'm inheriting from this interferes that whatever functions are being declared on once again known is being declared here. But they're all being declared here and her poster base is being inherited by I leave type repository on DSO By inheriting I leave type repository. It is basically inheriting the fact that these functions need to be defined on so I can just use my light bulb once again NC implement interface and it will just steamroll through and implement all off our functions. Associate id with our repository obese? No. Now let's say that there are certain functions and this is no explaining why we're not just inheriting from the repository bees? No, these are just the basic Croat. Once again, those are the base. Those are the four million functions that you always do on any function on any table. Right? But then maybe there's Ah function that only I leave type Repository needs to know. So the base doesn't get annoyed because if the base knows that everybody else who inherits from bees will also know it. So I can go ahead and define another function right here on DSO Inside I leave type repository on DSO When leave type depositor inherits from it, it will know everything that the base knows as well as anything that its corresponding repository interferes knows. So let's say I wanted one that returned some I collection on because this one is specific. No, it has to be off leave type. All right, so this time it's not t There is no t within this context. So I want a collection off leaf type on. Then this function is supposed to get get employees by leave type. All right, let's say I wanted to get all the employees who have taken a particulate type off leave on then this is going to take into ICTY indictee being the i d for the particulate er leave type. Now that I've defined this inside off, I leave type repository. If I go back to the inheriting class, then you see the red line is there on the arrow know is that I have not implemented all off the functions on that is because it's no seeing that a function is a part off. I leave type repository so I can go ahead and implement interface on it will just add that function to the list off functions to be defined. So with that, I'm going to pause on dime will allow you to go ahead and create the other repositories, the other interfaces and correspondent repository classes for leave a location on leave history. I'm going to leave you to do that. I'm going to do it. I'm going to complete it so you can reference it. But I want you to go ahead and try and get feel off doing it yourself. All right. So I hope you pause the video and tried it yourself. What? I'm about to go through what I expected you to have completed. And if you didn't, that's find. Then we'll go through together and you will find the resource is for these created files in the resource is for this video. Anyhow, what we were to do was to create the I leave a location repository. I leave history repository Onda. Same for the actual repository classes. So if we completed its successful than leave allocation should look like this. Remember to put on your public if it doesn't already get generated with it. Public interface. I leave allocation repository on. We're inheriting from repository beast with the appropriate class which is leave a location on the same for the history. We have the same format seem butter and just the different name on we're sure to inherit for the right class type part on then for the respective actual classes. Then we're inheriting. I leave allocation repository which we just rolled oats The implementation for the inter fees functions inside of the class file on. We did the same for the leave history repository. No, there is one more thing. And this would be like the start off our dependency injection. Our look at what independence injection really is. But we need toe actually let these repository classes know about the database, so yes, they know about the classes and all those things, but they don't embody the actual connection to the database. Andi, if you recall that application, DB context really embodies that connection. So this is like our gateway and our bridge to the database itself. So it actually hoses all off or entity framework functions right here on the actual connection to the database. So we need an object off type application BB context on then that will alot us to actually interact with the database. So in on going back to the 1st 1 we did, which is leave type repository in the class before our creator and the implementation off all the other functions, I'm going to declare private, read on Lee or property on. I'm going to make it off type application BB context on. Then I'm going to call it well, underscore db All right, So the pattern for private properties you'll use an underscore when your name e threats so that that's like a nice tell that if anybody comes by, Caesar called. They know all underscored. That means it's a private variable are whatever in your class side. So that's step one. Step two is to create a constructor for our repository. So we have public Andi, or will the shortcut for constructors their a C T O. R. And first up twice on it actually generates that constructor block off court for you. So you should be familiar with or PR Constructor is any function that has the same name as the class and it does some initialization is when that class is called Orenstein. She hated So in this situation, what we expect this to do is tow initialize. Ah, fresh copy off our application db context variable. So you noticed that it saying that it's defined, but it's never use. It's just there. So the first thing I want to do is actually give this a parameter on the test of a perimeter off the same type that I'm about initialized understand? To copy that on call it application db context, but not underscore db. So this one is private and this one is coming in through the constructor on. Then we're just going to initialize the private one to be whatever value comes in through the instruct the constructor. Sorry. So then our constructor is no initialized toe have this. So that's how what dependency injection looks like on this is step one. This is not all. There is the dependency injection. It's quite out a few steps, but this is the 1st 1 So this block off court needs to be present in every repository class file. So we're just going to copy this? We wrote it once in I leave repository, so I'm just went to copy it, and I'm going to go to leave a location, and I'm going to put it there on what I'm going to change is just the name off the constructor cause obvious to the construct. The name can't believe type repository. So I'm just in to make sure that's does the car its name on. Then I'm going to do a similar thing in leave history. Andi, just change the name on then our data classes or are positive classes are nearly ready for action. So we've done quite a bit off work setting up this framework on once again the repository Potter and its military that it's a pattern. It's a structure. So if you do it with these three and you find out you five more tables in Utah ad, then I expect you toe follow the pattern and do this five more times. For each of those tables, it may seem tedious, but at the end of the dates back structure that allows you to maintain your court even better, because it cuts out a lot off repetition, helps you centralize your court and makes maintenance easier over time. All right, so right now or functions are defined, but they really don't have any functionality. They're just going to throw exceptions, and we'll leave them like that onto the next video where we actually go through and defined the database operations in this video, we're just putting in the ground we're putting in the foundation on The last thing that I want to do is tow odd the knowledge off these repository files and their purpose is to our start up that CS fire. So we went into this file briefly, and we saw that we had a CONFICKER services function that, you know, it initialize is some stuff. So I'm going to add some more initialization is here, and I'll do that after the database initialization on these initialization czar toe, add our repository or contract on repository class relationship toe the dot net core application. Right. So what I'm going to do is say services not on. Then I went to see ad school on then we have our first class, and I'm going to see I leave type repository on, then put a comma on. Then I'm mopping that I leave type repository to its much air posture class, which is leave type repository on. Then I'm going to close the braces and semi colon. No off course there in lines because we need to include the name spaces. So I just use my control docked. Andi, include that name space for the I leave type repository, which is the contracts on. Then I'll do the same here on include the next name space for our repository. All right, all right. So once we add schooled on, we put in our repository or interferes on over repository class, Then if you get any red lines and you probably just want to check your references up top on , make sure that you have the correct name species for the respective files on. Then we're going to do that for each off our pierce. So we have I leave type repository. We also have I leave he story repository er and we also have I leave a location repository . And so you see, the red lines are appearing? No, because it's realizing that there's some mismatch between the interferes being referenced on the repository class. So to clean that up, we can just make sure that we're just hearing them properly. So I'm just going to copy the name off the interferes and move it over and then remove the I. And so everything is, you know, our start of that CS file fuse watch. Terrible that. So I'm just going toe ad some commons here to see. So this section deals with adding references for repository on contracts to start up file. All right, so that's the comment that I added for that section. So once again, for as many other data tables that we may have want to create a contract for that table, want to the creator positive class of that table? So and then you just add them in that section inside off the start about CS class. So those are a few steps towards implementing or repository pattern. Please notes that once again, all off the functions that would have been implemented are pretty much empty. They're just going to throw exceptions. So in our next video will actually start putting in the data operations per class or per function rather so that we can have some database operation beat into our application.
12. Implement Database and Entity Framework Functionality: Hey, guys, welcome back in this video we will be setting up our database functionality. No. In our previous video, we went through and we started implementing over repository, pattern or interferes is on the repository classes to inherit from the interfaces. However, when we implemented the functions that would have been or lined in the interfaces, we did not go through setting off actual functionality in these functions. So we have the bull create function here, but it's only throws and not implemented exception. And that's basically the case for every single one off them. So we're going to go through setting up one off the repositories and we start with the leaf type repository. This is the 1st 1 that we set up on den. I'm going to pause and allow you to set up the others. And then we can go through it together. No. Ah relief type repository class. It's inheriting from I leave type repository which, if we take a look at that, it is also inheriting from the repository base on. It has its own function in that implementation in that interferes. So then we have about six functions from their poster bees and then we have an additional function from the I leave type repository on DSO over inheriting class or repository class would have a total of seven functions that need to be implemented. Now I'm going to start writing in functions in the same order that they would appear in the interferes class. That's for no particular reason. It's just, you know, in building up. If you're not so familiar with entity framework, I'm going to bring you through step by step on, show you how you can use entity framework to interrogate the database. So we're going to start off with the I collection find. Also, the idea behind this function is that once this function is called relative to whichever repository and which of her class it's dealing with, whichever table stealing with it should get back all the records in that table. All right, so for context, if you wanted to shore grid off all the leaf types that are eaten the system, then you need to get all the leaf type records from the database. And so you need to find all right. So when implementing that formation, we goto find all on its right here all right on the expectations that were returning some form off collection off the beat, a type leaf type which once again is just a class on. I can just hold on control and click on it will go to the actual implementation off the class. Our definition of the class rather on it will show us what it is. It's a database class or a data class, Deby said. Class over, You want to put it. But the fact is, it's a table in the database and it's represented in our project as a class called leaf type. So I want every single I want a collection off records that looked like this class pretty much so in this function, which is find all I went to erase this throne, you not implemented exception and then I'm going toe invoked my connection to the database . So for more previous video, we had set a bad connection through this variable called DB, someone to use on the score DB and then I'm going to say it dot and then you would realize that you have quite a few form shuns available to you, but then, more importantly, you start seeing that you actually have the tables need available to CLC employees, you see, leave type Whatever it is that we set up in our DB context as a data class that can be accessed, a noticed leaf types is there. Then we can actually access them through DD. So to get about that list after the dot I just hold on on control and press space, and that brings back up that intelligence on. Then I can start typing leave types on. Then I need toe make it into a collection. So just by saying, db the leaf types that's literally running a select star from Leaf Types statement. If you're familiar with SQL, if they're not, then pretty much this is just saying, Give me back all the leaf types. That's literally it. Fine. But then, because I need it in some form of collection, I'm going to see that to list fire it. So ah, list in C Sharp is a very, very flexible way off getting a collection that can be used in multiple applications. You don't have to do much typecasting after that. You can just say to list her, but then you notice that it's it has a red line because it's they does not return a value because it's expecting that we're returning a collection off type leave type. So all I need to do really is just a return, he believe types that to list on some people. I mean, everybody has a different quoting patter, and some people would have probably puts dinner variable onda virus a nice, quick way off declaring of variables they can save our leave types. Onda, that is equal toe this, that the results of this statement. So whatever gets returned from this statement gets stored inside off, leave types on. Then we can return leave types so everybody does it differently. You can develop your own style. Whichever one is quicker or easier for you, that's fine. Um, but at the end of the day, as long as you understand what's happening, then that's fine. So we're getting all on their we save. I relieve types. DB leave types to list. So we're turning all of the leaf steps, and they were casting its toe a c sharp neat that I called at least, which is like a glorified Ari. All right, sorry. You have to have a sit number off. Objects are values are realistic and flexi can grow. It can contract. It can be any number at any time. So it's a very flexible collection that, like I said, So we just cast it toe cast what is returned here to our list off leave types. And then we just returned that. So anything that is calling this form son should be prepared toe receive a list off leave types, art, and that's it. That's all we need to get all the leaf types from our database. Now, the next one that we need to implement is fined by I. D. So that scenario for this would be that we want to see the details off AARP articular leaf type. Right? So you see that we have sickly where vacation leave. With this way of that, I only want to see vacation leave. Maybe those are spelling error. Maybe there's some detail I wanted to see who created it. Whatever I click on it just to see that one record. So in that scenario, I need to find that leaf type specifically, and I'm using the I D, which is the key or primary key in the database. I'm using that to uniquely identify that particular, um, leaf that. So the next one I'm implementing is fine by lee. No. Find by i d returns at leaf type object. Not a list, not a collection, but just one object, because, remember, we're finding one particular one. All right, so I'm going to remove this line off court on. Then I'm going to save Ire. Leave type. All right is equal to on their once again, I'm going to call my D V, which is my connection to the database. My database object that on the table I'm dealing with is once again leave types on. Then in this situation, I really just need to find one. So I have two options here. I can say that and c find so they give us an actual function called find that receives as a parameter any unique identify that should well, anything that should uniquely identify a record in whatever in order table we're looking at on that we just passing that permits is so we know that when we're doing it, we need to pass in that unique identifier on, then into different work. Will do the rest on find it based on that unique identifier on. Then we just return. Leave type. All right on. That's it. The other way off writing this And you probably see it written this way also. And I just commented Thought is that you could say, db dot the table Onda se leave types. And so this is where you're at a comment. If you want cold, that is not going toe or you want to write something that's not what interfere with the court. You just put slash, slash and that will come in toe that line. So it's a db dot leave types on. Then you say dot and then you would have something on. I just remove this quickly so that I can get it with the intelligence first or default So first or default, and then you go into some Lambda, um, statement. But I'm not ready for that yet. We're going to be doing that later on, so I'm not going toe go into that just yet. All right, so that's another way off doing it. Another thing. Another example. When we become more seasoned with the entity framework syntax so find by I d on. Then we we worry on, find one leaf type with that articular i D. Which is unique, that into fire it is returned and stored inside off this variable and and we're returning that variable and notice that that condition is satisfied because visual studio knows that leaf type is being returned on Leave type is the expected return type. No, we're going toe a little bit more fun. So we go on to the create. So this is when we're creating leave types of somebody feels off the farm, click save, and then the next speed refreshes with the find all data. So the great refreshes on whatever we just added gets display there. So the create function needs toe except the data on actually put it in the database. All right, so for or create function, what we're going to do is we're going to see connected database on the score DVR object right on. Then we're going to specify the table, which is leave types, so notes that we should be receiving some variable or some object off type leave type on. We're calling it entity. So once it hits this function, it's supposed receiving data in the form off entity. So db that leave types on. Then we're going to say that ad because these types is really like a collection. Leave types is literally a collection off records from the table leave types. So we're saying that I just want to add this entity or this new leaf type. So the collection off existing leaf types So we're seeing connected the database, give me the table leaf types are all of the collection off records from leave types on at this new one. So add on an open breeze and then you see, even intelligence is guided here and saying that what is expecting is something off type leaf type Now you can call it entity, so we'll call it entity. Now, this could have been called anything, and I didn't have to be called entities only called entity because we defined it to be entity here. I could have called it all BJ. I could have called it. Pop is it doesn't matter. The fact is that we're receiving some data type Andi in this specific case off leaf type, and we're just calling it entity. All right, so that's just a like a very busy man object name on. Then we They're basically done with that. So we say, D d, that's leave types that ad on, we pass in the entity. All right, so there's one more thing that needs to be done after we passed that it and that is the same. But I'm not really to write in the save function just yet, so I'm just going to make a comment there so I can remind myself that I need to save my notes. This is expecting a Boolean. So we're getting a red line here because one it's not returning until he's not returning the car data value. So I'm just going to leave that comment. There were going to come back on d fix it later on on. Then I'm just going to go ahead and implement another one on the next one. In line would be up it, so to do an update, it is basically following the same pattern. We connect or database. We get our table, the steps, then we call the function, and because we're a beating, they give us a form son update. Now I can tell this is a relief because back in the day, in earlier days, off entity framework it was not this easy. So no, we can to see that update on past in the entity just the same on then, having me that change, we still need to see it. So that's another thing that we need to save notice. We do have a say function, have not implemented it yet. So when we get around to implementing, then I'll go through and clean up the rest. All right, so we did that for update on the next one In line would be delete. So we have our read we have or create. We have our update on no wording or delete well for delete. It's pretty much the same pattern as we've seen before on what we will do is connect or database, get our table. If types on, Then we say dot On this time we want to remove All right, so it's not believe this time, but it's removed on. We're removing this entity from the collection on Once again. We need toe save, so please, not you can write this line. That's fine. Something will be done, but it won't be committed to the databases. Like a commitment to the database. Not this race. A database, actually. Run the query. All right, so, no, we need to figure out what needs to happen in our safe. So, for save, I'm going to remove this. Andi, all that really happens in or save is that we see on the score. Did he get the database? And then we see save changes, and that's literally all that needs to happen. To see it changes. So you could literally have put this line here. All right, so once you say DBC of changes, you could put that line there. But then because off whole I'm writing it, I'm expecting a bull. So if it was avoid function, then it would be fine because void functions do not return values. So by making it avoid form, son, everything would have been fine. But that's not what we have. We have a bull, so let's work with what we have. So the bullion is expected to say yes. Archangels made no change was not made. All right? So when we save changes, we need to know where change is actually made. Because if this was done, then I change is expected to be made on just to see him for every other one where I indicated that we need to actually, Seve. So when we do save changes, this will kind of return some form off into GIA that say's, um if if home any records would have been edited pretty much all right, So this is how many of records are edited. So that means it should never be less than one in a situation like this, if you are deleting something that at least one thing should be changed. If you're adding at least one thing should be changing. Your operating at this one thing should be changed. So that means they should always return something greater than zero. So I'm going to make it into a Boolean return by seeing return. And then I went to me this into a logical statement. All right, where I'm going to see, return the value if return the results drawer falls. If the value returned by this function, save changes is greater than zero. So then this bullion is no satisfied because it's going to evaluate this. It doesn't save changes, but I think a better infrastructures It's less confusing, though, and probably will work better is if I just put it in a verbal answer. Vier changes is equal toe on the score. Db dot save changes. All right, so then this is no one to store some integer for the number of changes need on that. I'm going to return after that if changes is greater than zero. So if it's great that ends here, then that's good. If it's not, then well, obviously we have a problem, right? So we save the changes and then we return. If it is, if the change is made greater than zero meaning it should never be zero in a situation like this on so we can return whatever our save function gives us. So in our update function, we're no going to return. See, if so, here's a flow. We update the entity in the database, Then we hit the return on. We call the safe function on the same function which is returning. A boolean is going toe me the change on. Then tell us yes or no. If the changes were actually see what Sorry saved the change. Andan tell us if that changes were actually saved or not. And then that return store falls. So then this update function on every other function will no true or false if it was safe. So I'm just going to take this return save function from here on, put it in the delete on notice. All that red line goes away on also in the create on that red line also goes away. All right, so those are the changes that are required toe have or crowd operations open running wherever creates off the elite. We don't want to implement or get employees by leaf time just yet. I'm going to leave that one blank. If you want to attempt it, then that's good. But I leave that one blank until we get more in tow our applications. But right now I'm challenging you. Toe, go ahead and repeat these steps in the other repository classes. So let's start with leave history. Um, I wanted to go through and do the create the elite, the find all all of those functions for this leave history and four leave allocation repository. No, I actually pause the recording and I hope you pause the video and actually went through and did it. But I'm going to do it. No. Oh, and I hope that you you worked smartly, right? So you can copy and paste and change the essentials because the court should look pretty much the same. It's the same pattern right across the board. So this is my leaf type repository. The one that we did together. I'm actually just going toe copy these functions, and then I'm going to go over to my leave allocation repository on I'm went up east on this one is a street. I don't need that one. So if you did that, I hope you are mindful that you don't need it. But then I have a bunch of errors because no, it seemed that I'm not implementing and that's because my data types miss much so I can actually do a find and replace where I'm going toe, Just take give allocation. Everything that is leave type. I'm just going to replace with the words. Leave a location, right, someone toe loop, control f on. Then use this carrot here, which drops the on the find and Ripley section someone toe find leave, type In this file on. I'm going to replace it with. Leave a location on, then I can go one by one on replace. All right. All right. Kendall, sir, please. All on, then after I have replaced all. Then you see my errors bore way and I'm done. Alright. So that's a nice, quick and easy way to actually just replicate the court. Because once again, it's the same pattern, right? There's another level of obstruction that we could do in the repository Procter. And where we actually just write this cooled ones and we just imposes which class it applies to. What? I'm leaving that level out of this. Do Toro on just keeping it simple. So I'm going to do that again for leave history on going to just do Ah, copy and paste on. Then a nice, quick way to do the replacement. I can just highlight the word and then do control f and it will automatically fill in whatever was highlighted. So I'm looking for or have it mixed up. So I'm looking for leave a location, Andi, I am replacing it with leave history. And then I can just do our place. All all 14 occurrences were phoned and replaced on, then. Well, I have a slight issue here because then this is leave histories are I s I e s sorry. That why, Yes. So I'll just have to manually go surrender. Place these on then. There I am. I'm done. So to make sure that I have no errors, what we can do is do a quick builds. They can use this, but sometimes you don't necessarily want to launch. So upset. And so you just want to check for errors. He can just hold on on control shift on dboey. And then that initiates are built where it just goes through, checks their code and make sure that everything is in order and that you are are error free . And I see here that I'm having a failure, which indicates that I have a list so you can click a release to see what the errors are on . I'm just going to go here. Okay. Sorry. That was some referencing girl from a previous video art. So I fixed that quickly. It didn't have the cart library for the island repository leaf type. Anyhow, if I do a build again on, then we will see that one build, Succeeded, known, failed. And so if I click earliest, I have zero errors. That's good. So, no, that we've completed a repository, though for leave allocation and leave history I no need to go back to my start up on Let my started by my middleware. So this this startup fire represents what you call middle. Where are the middle where configurations. I need to let it know that their other repositories already accounted for. I leave type repository. All right, so I need to just go through. And I was just meant to control de Onda. Duplicate those on then I'm just interchange these auto, I leave history story on die leave allocation. All right, I know that. Have me those changes. I need to make sure that the interferes and the class much So I'm just going to make sure that of the eye version on one side on the left on day, I have the corresponding class to the right, So I just did that quickly. I just did a copy in peace and remove the and all these things. So if you want to type it Oh, that's fine. If you want to do it this way. That's good. Also, whichever one works easier for you, no one off. The principles behind this kind of pattern is that you don't want toe put too much business logic to many places in your application. Each layer should be specific and responsible for one thing. So back in my early days, I used to put a lot off checks right here in the repository section off my application. Where check is this? No. Is this you know? Is this empty? Should it should I return it or not? I stopped doing that because I just want this file to be justly TBIs related operations. Right on then in the controller. That is where we do all the fancy stuff. So we do our validations that are pretty checks to do our police checks in the controller on thats where the actual logic can sit. So that's it for this video we have successfully set up or data access layer on connected it to the database. So of course, you haven't seen much action just yet, but we're doing the ground work on as application grows, then we have a foundation and a template from which we can replicate what needs to be done
13. Setup ViewModels and AutoMapper: Hey, guys, welcome back In this lesson we will be setting up or view models Onda configuring auto mop er before I get into anything toe heavy. Um, which goes through and explain when I save you models, what exactly that means. And then we'll take a look at Autumn Oper on. Then we'll get into the actual court. No, to begin with, a model is an obstruction off the database table at the basic level. That's it. In our case, it's actually the template for the database table because we're using a court first pattern . So entity for murky start low you to create the database. They still do. But traditionally you create the detail bees on. Then you would create a model diagram off that database inside off your visual studio project on. Then that would be the model off your data bees, and it would be similar to the database. Modern diagram, right? No, In this situation, we actually would have written C sharp classes on. Do let me just use leaf type, for example. So we wrote C sharp class called leaf type. We gave it a key called I D uh required property called name Onda. We give it a beat time property on. Then we forward engineered this C sharp class. All right, We've forward engineered it into an actual table and the table got generated in our data Bees and I just quickly find that table, and it's in our leave management database on. Here we go. So we have i d, which is a primary key, which is identical to the i d. Here we have name on, We have d created so everything that we would have defined in this class got created as a table. So this is a model for our table known with a lockable view models. It's an additional abstraction from the actual beetle model. So you don't want to necessarily interact directly with this If you don't tough. Do you want to use this for database purposes? But then for generating our views and doing certain operations in the controller? Then we're going toe, have what we call view models which are further obstruction off this on. Then we'll have to convert the data from the view model to the actual model before we pass it on over to our report that we would have set up toe, actually. Terrio the database operation? No, I mentioned another thing in the title. This is new models on autumn upper configuration. So Autumn Upper is a library that allows us to do that conversion easily. So we'll be going through setting up view models for a leaf type on. We will be implementing Autumn Upper No. First things first. I'm going to be putting all of my view models inside off my models folder in your project. So of my contracts controllers, Peter has all of the actual data bees class files. I'm going to close those. But then models no will have our view model. So I'm just going to right click on our Models folder sneaks. Add about a class on. Then we're calling this one. Leave type on. Then you can rattle the words view model if you want. I'm just want to call it VM, so that's my naming convention. If you feel better typing overview model, that's fine. But that's just my naming conventions. Instead of saying view model asi vm on then Well, pretty much this is an obstruction off the original database class, so I'm really just going to copy these properties from here on put here. So you're probably wondering. OK, so why Copy and paste? Why? Why bother with the View model if it's really just a copy on peace? So there are situations where you may have more. Are fewer properties inside off the view model than that actual Beat Abi's class will have . So that's the point of this obstruction, because maybe on the edit page there certain things you wouldn't want to display on and on the index. Peter. Certain things you may want to display me. Want to put in an additional property on calculates on the fly, so the view model kind of gives you that kind off flexibility toe. Customize whatever experience you want. User tohave. So the view Remember, we discussed that views are what the user see, so the view that is generated would be based on some class the fields that are exposed, the data that says access toe. So by using a view model you can with a ramp up or toned on the amount of data that a person has access toe in our particular view, another thing it allows us to do is the enforce certain pre checks on on our views. So when I say preach except me, like in a form, give me want required feels give me want some stipulations, our own data validation. So, for instance, I can put the required property in the view model on DSO on off course after include that library. All right on, then, Once that's included, What this will do is out any view that is, generate that inherit. It's data and it's behaviour from this view model is going to enforce that name is required . So if I have a form when I have a form to create a leaf type and you have to put in the name off that leaf type, they can't submit it empty because this is our acquired field. I, however, don't want to meet, be it created required, because that's something I'm going to be sitting in the box grown. So I'm not one to me, and that required. So then you would probably wonder. OK, so if I'm sitting in the background wire, bother me for for instant, and that's a valid point. So then a mother lived off obstruction is that sometimes you can have a different view models for different purposes. So, for instance, this could be the detail view model where I'm going to short every single detail of boats. This item Andi, I can have another one. So some people split these into different files on some people. Use one global file on just have the different classes inside off that file. So this is the details sport details around. This is the details view model on then may before the create view model. I don't need the I. D right. And for details this wouldn't be required because that display so there's no need to require data since the details you is really just showing NATO. This is a creative you model side, only the I D. Because, well, there's no idea at the time of creation, however, the name is required for creation on then. Maybe at the time of creation, I really don't eat the date. So these are little things that you can do with your view models. As I said to either toned on their boat, amount off data that is being exposed to the view that will be inheriting it or toe increase the amount off data. No, when we get to actually generating the views and the controllers, then you'll fully appreciate why we would be taking doing this hard work, because visual studio actually generates quite a bit off court for you when you use the scaffolding. And so if you scuffled, six feels and you only need to, then you won't have to spend time cleaning them up. If you're scaffold on top off of you, model that you already designed toe only have the fields that you need for that particular view, then you don't have to spend as much time cleaning it up because they already spent time sitting on the view model. So it's a chicken and egg kind of situations, a cash flow into one. It's whichever one you prefer when we get to the point off scaffolding, then we will see the true power off the view models. All right, so for the other two data classes that were going to be focusing on what you believe, allocation and leave history, I'm going toe create view models, and I'm literally just went to do a direct abstraction off the data class, and I'm just going to add some some violet de son attributes to them. I'm not one toe spend time cleaning up and city or BTS versus creates. I leave the lead type VM as it is, But then I'm going to go ahead and do the leaf history and leave allocation differently. So I just go ahead and create a new class once again on this one will be for leave history and I called VM on. I think add on. Then I'm just going to do one more for leave allocation. All right, So we have or leave a location VM or leave history and leave time. GM files are so for leave allocation. As I said, I understand to do a direct copy on, then I'm just going to modify the data annotations. So those attributes that we put at the top those are called data annotations. So for leave al appreciation removed. Key are more foreign key because those are not absolutely necessary in a VM, so they're absolutely necessary in the data class. Well, they're not necessary in the view model on then. You see here that the view Month is making reference to a data class, so it's trying to make reference to the employee data class and is trying to make reference to the leaf type data class. But then, ideally, we don't want Toby referencing the data class from a few models. So have you Model should talk to our view model on needs a class. You start to deter classes, So that's why we have that obstruction. So that means I need to set up a view model for employees also so interesting to create that quickly. All right, on then. Here's another situation where view model might come in handy because when we want to look at any employee where actually, can't I use a record? And if you remember the Users table, which is a speedy net users, which is what our employee data class is inheriting from, so employees really gives us all of this data. We really don't need to display all of this data. We're looking at an employee. We really just need maybe the I d. The user name the email address on certain key. Um, it's off data, so a view model once again helps us the abstract. Certain things from the database level on focus on what we really need to see so I'm just going to make reference to certain key fuels. I d use a name e meal on the ones that we added, which will be joined it off birth. First name, last name on tax I d. All right. So I took the day properties from the employee class that we put in on. No, I'm just going to add the others from the table. So I want this to be on the side while I'm typing so I can spin it for the duration off my a By my exercise here on day, I just time these quickie No. One thing to note is that while we're typing or when we're typing these across, we need to make sure that the spelling that won the data types much What What are in the the well, the data table or the data class. So I can't have string using him here, but be referencing char using him here that will fail. The mapping will feel because then they're two different properties on. Then it won't know that this matches with that. So evening typing holds the i. D. The user name on email. I most much the case and I most much data capsule Environ star is I need a B C's way of seeing string. So I have to say, string on Did use the name is camel cased kept up a case you and end after me. Sure, I uppercase anyone and seem for the email with a capital e on. Then I'm going to add four number on that will be the end off this exercise, so prob on full number is stored as environ char So for number must be a string here on phone number. So this will actually help it to march back toe the underlying class for employees which is identity user. So everything most much I'm done with the database, so no so I can just creep in it and I get that my really state. It's always good that when you're writing code, you just talk builds. I can point out where you're missing. So I realize, know that I did not go back and correct the eras in the leave allocation VM so no, I can change this store employees VM and I can change this one toe leave That will house a details. Sorry. This should be just go back and check and make sure I'm writing. So it was Leave that via my details. Leave type B. M. So I just used the details. Since details would have everything I need that should come back in that object heart and there are no errors on then it just knows that Leave allocation. Veum should be expecting some property off employees off type employee VM on leave type with details. Leave that GM so once again we could go through and create different view models for employees. You know, one for for viewing, one for creation, one for this one. For that, it's up to you. I'm going to do it both ways sick and at least have a template and see how it can work out on DSO. We'll move forward with the lightest, so I'm going to go ahead and do leave history. I'm going to do it quickly off here so you can positivity here and attempt to bring over the property's yourself on. Then we can continue together. All right, so I brought over all the properties and that changed out all the erroneous wants to the corresponding View model or VM class on then, of course, we have to take all these attributes because they're not at the cable in a few model. No, we can start adding some validation. Someone to go back to leave allocation firstly on. Put in some validation. So the number off days is required because when they're filling out the form and sitting on the allocation, they need to see the number off these that whoever it is has. All right, um, another thing that the leave allocation will need Tohave is access toe the list off employees and the list off leave types. If you notice that this is really one, this is not a list. This is one entity called employees. On This is one entity called Leaf Type and with the corresponding I DS, right. So while it's storing while the data table is going to store one employee idea and one leave type, I D. It. Really. When allowing the user to philo, the list will require them to select it from a drop down list on. So we'll need to include some mechanism that represents the list off the items that will have the employees and the list off items that will have the leaf type objects are so to do . This will include, in our view, model on I'm going to use on innumerable this time. So and I innumerable on there were using a data type called Select Least All right, Tim Onda. We are going to call this one employees. So this represents a drop down list off the employees in the database, and then I'm just going to include that library. All right, on, then we'll do the same seeing for over leaf type. So have employees. And let's just say we have leave types. So once again, the poor off the view model, this is going to pour the view. This is what the user is seeing, and what they need to see is a drop down or some form off list that they can snake a selection from. So we're putting in the select this in our view model class because they are far more flexibility with the data types that are supported here than we would have had in the actual leave allocation class that was used to model the database. So we've done that for leave allocation, and I'm well dressed in to go to leave history on. We'll just review that on we see here that everything looks in order, changed all the employees and the details. References. Well, this step is actually going to be used to store the leave. References are requests, rather Andi, whether they were approved or not. So just thinking I had If somebody is filling out a leave request, then they're going to put in the start date. The end. It, um on Ben. They need to select the type off leave that they're requesting. So that means I need a drop down list for the type off these. So I'm just going to use the same innumerable from leave allocation and put it right under here, because then this is the leave types on that. I just include that missing reference. And then I'm going to add some attributes to what I deem as required so start date that is definitely going to be required when the person is requesting Leave on. That does include that reference quickly. Um, the Indy, it is definitely going to be required. The well, that's all that's required. Really? So I can determine the requesting employees, or we will be determining that so the user would have to provide that information so they don't have to meet the required Andi. The requested eight action. All of those will be put in approved. Doesn't have to be. So, you know, on a case by case you know what is required and what isn't when you're thinking ahead. But at the end of the deal, we can always come back and we can add Subtract on modify as we see fit as our application , he falls. So that is it for setting off the view models, at least for no, that's it. Um, no, what we need to do, He settled for autumn upper. So, like I was saying, we need a wayto convert. The data that is provided into this class type into an object off this glass steps. So when it's a leave request goes in. So maybe I could have been done a better job called in this table, leave history. I could have leapt requests, but let's just work with it. So leave history when ah request goes in into this table on the employees. All of these data points are filled out. They are not data points. that the database recognizes because this is VM and the database only recognizes believe history table coming from or data classes. Right. So that is what it recognizes. The history, not leave history. VM. So that means we could manually sit down and reconstruct, leave history, object and putting, assigning all off the values coming from the VM in tow. The corresponding data class. Andi, that will be a very tedious method. It works, but it's tedious. And so we're going to work smarter, not harder. So we have a tool called Autumn Upper that actually will look at the two classes that we've said these two need to map. These two need too much on. Then it will much the properties with each other. So that's what I was saying. You have to be very careful and sure that you're much in the case and much in the data types. It's going to look for capital, our capital e requesting employee. I d on it. It's going to see Okay, I should be leave history and I'm mapping to leave. History V doesn't have that same property. Okay, I will take the value and assign it over, and it does that kind of automatically. So we're just going to go through the steps off, configuring it on. DWI can move forward after that. No, to get autumn upper, we're going to be using our new get package manager so we can just go over to our solution . Explorer, right? Click dependencies click Manage new get packages and then if it fears lands on install Just Goto bro's on. Make sure that you have include pre release ticked on and we're going to search for Auto Mahbubur. So we're going to be getting to off. These libraries were going to be getting Autumn Oper and we're going to be getting Autumn Oper extensions for dependency. Injection aren't so We're going to click on that. We can just slip the down arrow one time on. Just let that start downloading on. Then Newgate will do its thing, get the package and place it in the cart. Place inside off the project and then once that is done, then if you go to installed, you'll see listed there So limitless antic are clear the search. But no. You see that automobile is listed among your installed packages. If you dropped on dependencies and Goto packages. And you'll also see Autumn Oper listed right there aren't. So we'll go back to Breaux's and I'll search for Autumn Upper once again because I'm not finished. So all term upper on then. We're looking for this one. So we're looking for extensions. Microsoft dependency injection on. Then what? You don't know that version for John seven. Once again, make sure that include pre release is sticked. I know that that is downloaded. I have both in my project, so I can just look weak build. It's always recommended that once you install a new package it or build so that you know, all the references are kind of baked in. So just the control shift and be and do a quick build and our buildings complete with zero arrows and so we can move forward. So, no, where we have the references that the packages toe autumn upper, But no, we need to let our court know what to do with autumn upper. So the first thing that we're going to do is create a little folder. So, you know, we want to keep our core neat. So any time you have a little cords are little classes. I need heretic and discreet. A folder. Give it a nice name. So I'm calling it this one. Map ings are well mopping Zia on. Then I want to create a class file in there. Someone to call this cross file Auto my burn. All right, so that name wouldn't clash. That's my name for my class. So that name that word would really crash? No, inside off this class, the first thing I'm going to do is inherit from, ah, file or another class called profile. So I'm just going to do that. And then a loader reference of this knee Still putting our using autumn my personal. It's referencing our library. All right, so autumn, a prison library or the dependency that just got added through you get somewhere referencing it on. Then we're going to set up a constructor for our could us. So maybe this would be a bit confusing if I since I gave it the same name. So I'm just going to change this name toe my upper. So instead of calling our casts autumn a prime want to call it my upper? Justo, remove any confusion, right? So it's always good practice that whatever the class file name is, he also name the class inside. All right, so I just renamed the file to mapper dot CS on the class. Name is muh for Andi know I'm creating over constructor on. Then inside this constructor, I'm going to create the mops that should exist in our application. So let me just do one on explain as I go along, someone to say create all right, open angle brackets. And then I'm going to see what two classes should map. So you see, it's kind of telling you, Do you want you want a source? I want a destination, Right? So what is the source? I can see a source would be a data class. So let's see. Leave type is Anita Class. So I want that mopped. So on. Then I did have two classes are to view models for lyft types of details leave type and that create the steps I'm going to do one off. So I want that the leaf type data class, which is my source, is mapped to my details. Leave type trust are sorry and it's Veum. Details leave type VM so that data class, which is our source is mopped to my destination, which is my view model, and then understand to include all of those references so that everybody knows about everybody. All right, so, no, the mop knows that it should create, um up or we'll This is creating a mop between the source, which is our data class andare destination class on. Then I just close those braces on, then semi colon. No, The thing with autumn operas that it literally will do source the destination, which means that if I'm tryingto get data from here to store here, then you will know about it's based on the direction. So it has, ah, function. So after the open and close, very site Express said that And then I want to call another function called reverse map, which will then see it can be mapped in either direction. So that way I don't have to do one night and seeing this to that and that to this right, that ought to say, data class, the U Motor on view model to data class, reverse mop with automatically know that's well, either direction is fine by me. All right, so I can do that with the details and then, ERM aware to GM's. So where details on where. Create leave time. So we'd definitely have to do it because we expect that Autumn upper will note a map from this later class to this view model. So we have to view models here, and for every view model that we have, we would have to do it this week. So that's what I said. You can You can break out your view, mothers, to be very specific to the type of you, or you can just do one global one, so this would be done once. So what I can do now is just duplicate these lines on then, right? All the other map ings for history, allocation on employees. So I'm just going toe pause and do that. And you can pause here also on day try and do it before I resume. All right, so I'm done. I just duplicated those lines and changed all the names off the data class on the view model on De retained the reverse map. So this is pretty much all we need. And for every other data class and every other view model that will ever get introduced. We just need to add it to this list off mom pings. So the next step is toe actually let oh, our middleware or donna core application initialize autumn upper. And these map ings went in for the application is running are so we'll do that by going tor start about CS file and then we need to add a new service. So let me just put some space here. So they added these three services for over our present for repository. All right, so, no, I'm going to add another one, and I'm going to meet this one for our autumn upper. So I'm going to say services dot on then I'll see Odd motto, ma, for no notice the inter sin stopped. And that's probably because you need to include some library to get this function. But let me just finish typing it old before we go and add anything. So I'm seeing at autumn upper on. Then I'm going to say type off on, then in braces. I'm going to see the name off the class, which we had as markers. So remember that we called it Ma per that is over and it's in the new space or in the full of my pings. So mop er aan den, That is what is going to be here. So no, we need to include some references I need to say using Autumn Oper firstly so that this phone shown is recognized. All right, so we hit a bit of a snap because we call or class mop er, but it really shouldn't have that name because mapper is Noah Conflicting class, So I'm going to call it maps instead. So I'm going to go back to my file, which is my upper, that CS, and I'm going to rename this file toe maps. So the coating with the studios that if you rename the file, it will ask if if it should go through and really in the classes under references inside there, so Iranian distant mops. And so it automatically renamed the class and the constructor. Two maps for me, so understand, to see if that come back to my startup and instead I'm going to say type off mops right on . Then, when I include the reference, it will ask me if I want to include the reference so that file, which is my class file this time. So let's just review what we just did. So we're adding a new service, and we're seeing that when you know our core application is starting up. We want a service that adds on autumn upper configuration file in the type off or inform off this mops file on this maps file or class is coming from our configuration that we did with all of the mops. So, no, At the end of this exercise, when we are actually carrying out our operations with a view models on, we're getting data and we need to convert it from the view model version to the data classrooms on because honorable repository is not looking for view models is looking for data classes. So we need to convert the data stored in the view model object in tow data that is stored in the data class object that can be passed over to repository and by extension, the database. And so autumn upper will meet that process easy. So we haven't seen automobile, and actually, we were just sitting up on just getting an appreciation off why we need view models and why we need Autumn Oper on. Then when we're setting up our controllers, then we will see the true power off both.
14. Review and Add Changes to GitHub: Hey guys, in this video, we'll be revealing over changes or worked to this point. Onda. We will be uploading our project to get up. Now let's start by reviewing what we have done up to this point with our project, we have set up over repository classes we have set up or database connections. We have set up a few view models. Onset of Autumn Oper. We haven't touched our controllers and we haven't touched our views as yet. But at least we've done the empire to which is model, which is a data related operations? No, it's always good to keep relatively shorter cones off what you're doing. Meaning you implement something, you check it in. Um, so source control is designed to help teams collaborate on even as an individual developer to help you keep track off what it is that you're doing. So with that in mind, when you make major changes or you implement something new, you want to check it in because anything can happen toe your local machine or wherever it is that you're according on when you check it into the central repository. At least you have a back up off the latest changes that were made. So our source control engine off choice is ghetto Bob on dit is a cloud platform and you would or should have created an account already. And if you have not, then you can just and I'm just going to sign out off my get up quickly. If you go to get hope dot com, then you will be given a sign up sheet right here at the front page. This provide a unique using new your email address and a password and you're in. If you already have an account, you can go ahead and that sign in, and then we will create a repository for our project. No. Once you have signed up on our signed in, we can proceed toe Visual Studio Onda. We can go ahead and add this project source control so you have two options to do this. You will see in the bottom right corner at project to Source control at the Source Control and you click that and you see gift or you can right click the solution and you will see an option. That's his ad solution to source control. Now, if you see neither or you don't see gets, then that means you need to don't load, get it usually comes with visual studio, but maybe something went wrong and you didn't get it, So you can always just go toe get dash s c m dot com or you can Google it at least are good . I wasn't Fire also gets dash SCM dot com, and you can just go to dawn Lords on, then just tick the don't Lord. If you're using Windows off course, then that's the one that's for you. But you can choose according to your operating system on. Then once you install that, you can give your computer maybe a restart and then reopen your project on. Then you should see that get Icahn as an option, so I'm going to go ahead and click. Get so at the source control and I'm taking it. And what it does is create a local repository, so get creates two repositories, but get creates a repository on the machine it's on, so if it's on your machine, then you have I repository on your machine. But then visual studio is also very tightly integrated, with remote source control hosting platforms like guitar, so it's going to force it to save changes before it creates three Paluch locally. But then it's also asking, where do you want to create the backup off your local get cord words? It created a local copy off your cord so you have a local copy off. Your changes are local tracking off your changes. But no, it's asking. OK, do you want to push it as your div up services? Or do you want to use ghetto bar? Some other type off get remote repository. So then it's going to ask you that on dime using guitar because that's my weapon of choice for this tutorial, someone to say published to get hub. At this point, it might ask you to log. You know, I'm using pretty much the same log in tow. Tie everything together so it didn't ask me again. It knows who I am, so I'm just going to leave the name Leave Dash management. You can put in a description. If you want on, do you can click publish, So if you choose private repository, then people won't be able to see it on your profile, so that means you have to add people manually on, then that might incur costs if you need to add to many people. But then, if you leave it public that everybody can see. So, of course, you know, if your sensitive information it wanted public for But for the purpose of this tutorial, I want to leave it public so that you can look at my profile, go to my guitar profile and see the source code. If you need any reinforcement outside off what is done in these lessons, so I'm going to go ahead and click publish, and then it's going to work some magic on. Then at the end off that is going toe refresh and show me that the repository was created successfully. Andi. It's giving me a link to that repositories. If I click this link, then it will Bro's toe the repository ungettable with all off the court that I have written to date, Sisi was created. The last commit was two minutes ago. If I go into the folder that I'm seeing all of my folders and files that I have been working on, and so that this is a nice remorse horse, that version off my courts If my computer crashes, right? No. Then I can come back on, get up and get the latest checked inversion. So that's why I say it's important to check it in when you make major steps in your quoting on. It's also good practice. The chicken called. That works because if you work in a team you don't want to have an error on, then you try to check in that era on. Then somebody else comes along and gets your cord. That's what you call check out when they get here cord. And then they have Arisa contenders that were your fault, right? So always chicken code that your shore works and then you move forward. So that is a nice It's a nice way to collaborate Snow from here, and I can just dismiss from here. I can include more information create. I read me so that you know, if people come across this file or this report story, they know exactly what it's a boat. I can be more descriptive by adding, well, a description on the page at the top, so this is no description. It doesn't know what it's a boat. He can add a wiki So that persons who me, you know, this is an open source platform. So maybe you're creating something that you want to share with people. You can create a wicked, which is like a issue turned off logging O r problem, Andi solution kind of documents. If it is that you want to add more people, Toby, collaborators are contributors to your project, and you can go to settings and you can go to collaborator. So this. So you set up a team project. He has go to collaborators, and then you can just find them by using him and at them. And then all off, you would be on one team working on that central repository. All right, so that's pretty much how you get your court from visual studio into the tub on. Then as we go along and we built more models each time, we will make sure to check in those changes and keep this repository opted eight
15. Setup Leave Type Controller and Actions: Hey, guys. In this video, we will start building out our leaf type management module, and we will start with the controllers. In this video, we're going to be creating a new controller for our leaf type managements before a continuum went to spend a bit of time explaining whole controllers work, or what rule? The really plea aren't so. The controller does exactly what its name suggests it controls. It controls the flow between a user's request on the content at a servo. As a result, it is at the helm off any Web interaction with your application. So the projects when we created it came with home control are already there and ready for use. And you? We spend some time exploring how it works. We see that home is really the name off the area. But then the pattern is that we have ah name and then the word controller. It's always camel cased Andi. The controller inherits from a base class called Controller, which is provided by the project. The controller has certain functions which are called actions on. These actions have names on the return hunting based on the need. So even though both index and privacy will see return view. What really happens is that if you request content for the index speech off the home controller than it's been to hit this action and it's been to return view on, then what it really does when it is returned, view is it goes into the views folder checks. If there is a folder with the same name as a controller, so the controllers name is home. There needs to be a folder called Home On. Then it needs to see of you with the same name index, which it does. It needs to see some file, which is ah dot CS Isham of file on. Then it returns the content off that file on that is what the user sees. So to start creating our model, we need to set up the crowd. Operations are on the leaf type management class are tables rather, so the first step is to set up a controller. And then we will start setting up the views, her action in the controller. So let's begin. So to create a controller, we right click on the controllers folder, we goto add on. Then we see at the top off the list. We have controller, so we select that on, then were given the options often empty controller. So you see, Home Home has some called We can get it empty, meaning it only as a basic stuff the name space, the libraries on the fact that it's a class called whatever we call it inheriting from control. And then we do the rest so we can choose empty. We can choose one with reader at action So it comes stopped with the basic crowd actions like I'm saying that we the actions are these functions on any interaction with the application is really crowded here that creating, reading, updating our deleting data right, so we can get it with the basic but generic and and off course we have to write the cord for it. Or we can go ahead on do the NBC controller with views using entity framer. So what? This one does it. I lows. Us, too. Create a controller centered around on a four data classes, the room where we went wrong. We created data classes in this case, leave type, and then it will generate all off the crowd operations using entity for your So I'm going to do this on first on the number one to show you why this is not the one that we are going to press forward with. So the at the basically revered building a dominant core application that you're not using repository and view models and all of those fancy things. Then this would be the option that you go with where you just select this. You click. Add that from this dialog box you select the model class. So then you can in the list select any class you want. Andi, In this case, I'm going to go with leave type. So it's leave type coming from the data name space lionized data class on. Then I choose the context which would be application Devi context Andi. I don't have toe touch anything else, but notice that it's generating the control and in for me it knows that its building a controller based on the model class off leaf type. So it is leave types controller. Then I click add And when that process is done, we have a controller with a lot of generated code. So we got a controller with lots of court and we also got a new folder in our views called Leave Types of About a leave types control now that a folder called Leave Types with a number off files one for each off the crowed operations are in, so create the leads, Details and index would before read and editor before upbeat. Now, if we look at the cord that was generated in this controller, we see that it includes our application DD context, which, remember, is like over gateway to the database. I see that it initialize. Is it just the same way that we initialize it in or repository? And as you continue to examine what is there, we see that we have an action called Index. But we have a file in our views folder leaf types called Index. So for every action that was generated in our controller than we have a corresponding view file for that action. So you see that I mean, it's pretty much does much off the courting for you for creating to see to one is to give you the foreman, and the other one deals with the the submit action. So after you fill out the form and then you click. Submit this. Http post version off create handles the data erratic, got and does any pre and post checks that it needs to do the same can be said about the edit. We have the editor and we have the form on the corresponding file, but and we also have the post version off the action. So really interested enough that the scaffolding would have done majority off the courting for you. And then you're probably wondering, so why bother with repository if we can generate all off the score? Well, the fact is that yes, it generates, yes, it will work. But then there are certain restrictions or limitations to what you really can do certain validations that you can enforce because remember that we don't want to touch the beta classes and enforcer and validations like length, and you know certain little things that the user should be seeing. We want to kind of create that live off obstruction between nobody user sees and what the database experiences. So that's why we have you models toe handle the view generations, and we have the data classes toe handle the interaction with the data bees on That's what that pattern is all about, creating that live off abstraction and maintain ability. So what I'm going to do is I'm going to just remove these. So yes, I generated it. I was just showing your host. Scaffolding works someone to delete the controller on den. I'm going to remove that views folder also. So these never existed as far as I'm concerned. So the demo is over, and no, we'll do the real work. So I'm going to go back to controllers rightly click Add Controller. And this time I'm just going to do a generic controller with read right action. So there's nothing inherited in this one. It's just general on. We will fill in the gaps and generate the views as we go along, so I'm creating that with reader at actions at like add on. Then I'm going to give it the name leave types on troller, so click add so once that is done and we end up with a very generic looking controller, there's nothing spectacular here. Yes, there's some quality. Give us all off the actions that create the two creates do and it's etcetera. But if you look inside of them. All of them are empty. The only thing that they really have is the return view. So we're going to, firstly set up this controller toe inherit our repository class. So the thing about dependency injection is that you're not going toe actually reference the class itself. But you're just referencing the inter fees that implemented or that the class has implemented. And then another dimension to this is that we need to also make reference to the Autumn Oper that we're going to be using. So I'm going to start off with a private on, Uh, we can make you read only, but I'm just going to make it prayer it on. I'm going to say I leave type repository, And then off course has been to ask me to include the reference for that file some distant . If I had any clue that reference on, then I'm going to call this report. So underscore reports. Remember, once you have private, we use an underscore. That's just a little naming convention are courting convention That helps us to law, what is what's current. So I'm going to make it read only there, saying I should make you read only I make it read only. So that's for the re poll on that. I'm just in to duplicate this and I'm going to include I mop er on, then went to call this one ma upper on. Then I'm going to make that reference. Also using autumn opera were including that reference for I mop. Er So this is a demo off. What dependency injection really is. So dependence injection is just referencing one object, and it implies what the dependencies are there for that object. So I'm referencing the interferes here. But then this interface knows the functions that need to be called, and by extension, it will call them to the repository class. So, yeah, that's a mouthful. That's somewhat academic. But let's just go through and see exactly how it works, Right? So I need a constructor service using the key. The shark would seat are aan den. In this constructor, I'm expected to pass in two parameters, one for the repository and one for my mom upper. Right? So just the same way that we did the DB context. We're doing this, but then I'm taking off the underscores here. So that's I leave repository reporter and I'm upper mapper Andi inside. Off this, we will know initialize report tohave the value off the so underscore re poison to have the value off our parameter re pool on on the swarm upper is going to have the value off or parameter mop er And so we just completed form off some parts off dependency injection in tow, this new control so forever control that we're going to be doing for any report that we're going to need. We're going to have to do these lines. So in some controllers going forward, we're probably going to need some functionality from the I leave type repository as well as the employee it repository. So we're going to have to include them just the same way on initialize them in our constructor. Now, with that done, I would have completed initial set up off this controller on. There isn't much else to do in this particulate lesson. In the next lesson, we'll start setting up or index view. All right, so in the next video, we will continue from here. But if you've completed this, then good job
16. Setup Leave Type Index View: Hey, guys, Welcome back in this video, we will start sitting up or index action on view for relief type controller. Now, we've already set up or controller and we included. Our dependence is in the form off the leaf type repository and over mapper. And no, we need to write some amount off court such that when somebody brose is to the leaf types controller or to leave type speech to that module. The first piece they're going to see is Index, and we need to show them something on the index page. As it stands, we don't have any view. No. What? We don't have any folder that corresponds. Is the leaf type controller on? We don't have any contents to display. So we're went toe one write code that we're going toe query the database, get back all the leaf types in the database on, then return a view that this please all of those records, It's over, user. So the first thing I will want to do is actually will find all leave types. So, inside the action, I'm going to use my repository object in the form of underscore Re pull on. I'm going to call the function that we define that is supposed to return all off the leave types because the index is going to be a list off the leave types that are in the database . So I'm going to use Vier to define some variable, and I'm calling leave types on. Then I'm going to make it equal toe whatever over report dot and when I say not use notice that we get all off the functions that would have bean defined inside off our leaf type repositories I want find all because I returning all off them. So I'm just going to see people not find out. So whatever this returns will get stored inside off leave types. No note that this function find all is returning a collection off leave type objects. It's not returning leave type, view, model objects. So remember that we went through the fact that our view needs to get view model objects, not the data objects. So no, we need to map what is returned in a form from our data class or view model class. So I'm going to save fire model on the model is going to represent the marked version off the data so far, Mother is going to be equal toe or mop er object dot mop and then map I lows us to define that were getting this or we have a source meaning we're getting the data class in this situation. But we want to be the other one, so we'll see what the source is and what the destination is our what we're getting on, what we want. The muck, Toby At the end off the mapped results should be at the in the the operation. It's always him up on. Then I am actually getting a list from this. So this is actually returning. At least it some my collection. But if we go back to the function definition on, I just held on control and for unclipped and I went to find all and I can right click Or rather let me just go to my leaf type repository on. We see here that or find all is returning at least right. So I'm going to see that I want my upper that mop to get the list off on. Then the list is off type leave type because that's what returned to leave types It's a list off, literally. Leave type on. Then I went to see comma and then I want to mop the list off the data class. Leave type toe a list off our A list off our leave type the M object on. Remember that were too. So I created tool on Dime went to use the details, leave VM So I think that one is good for this situation. So details leave that VM All right, So this is how you defended its direct the word list, and then you open an uncle bracket, and then you specify the data type that the list should have, So this can be after into camber of type string. Or it can be an object type, like, in this case, leave type, which is over custom defined to us that we have created some mapping from a list off the data class leaf type toe a list off the view model details. Leave type V M on. Then at the end of that, I need to close the initial angle bracket from over map on. Then I'm going to see what object should be. What object are objects? Data should be much So the data is really coming from leave types because that's what's hosing what is returned from over function, cause I'm going to copy that and put it inside those braces on, then closed. So no, I have a bunch of red lines. I need to go through Onda. Mop that up. So I'm went toe include all the libraries that there may be seen on. Then I handled it. We're getting one more red land where it seemed that it cannot convert from I collection from system No generic I collection to system generic list. All right, so I have two options. I can either put a to list on the end off this or because I didn't have the dysfunction is really returning collections, even bloody that to list in the function here. It's really returning I collection so I can either change. I mean, I can always use this to just be list, or I can change this and foot honor that. So list Andi, That will do another conversion. So, yes, it's returning. I collection it returned list here. Then it returned. It does I collection, and I'm re converting it to list and then everything is OK or I can actually change from list here toe I collection. So whatever I'm upping I'm up can be from almost any generic data types of any genetic deal at the time. As long as the mumps are defined, then you have no problem. So I'm just going to leave it here as ah dot to list on that solves our problem on then know that we've gotten the data on then we've marked the data. We mark the data and they were storing them up data inside off models. If you hover over model, you see that it's really off type list. Details VM on That is what we want to past our views of the past data. To our view, we only need toe have returned view. And then in the open breeze we put in the data that should be passed. So now or view once it's loads, it will have access to whatever data is present in the model. And that's why I keep on saying that our view mothers far more versatile than the data class itself because I can put almost any amount off static data as well as the enemy later in my old class, Andi, I can manipulate and massage hold should be formed before the view actually gets it. So no, we need to actually generate the view that will display the data from that model. So to generate the view, we have two options. We can manually go and rightly care and open a new folder and then give it the name leaf types and then create a view off course That was one big multiple visual studio makes it easy for us. As we saw with scaffolding, it was much easier. But we thought scaffolding or without generating the entire controller and all the views, we can do them individually nonetheless, by right clicking on the worldview. And then we see the option at view on. Then from ad view, we defined the name so the name would have been inherited from whichever action the view for the action that we're implementing, We can specify a template. In this case, I would want a list. So an index is usually a list, so it will actually give us cold that Juries a table listing off all of the records being returned from, or query, we can routine the the model class or the model class will have too much whatever data were returning. So our model classes off details Leave type VM so I can just find that in the listeria details. Leave VM on. I can leave the application db context on, then go ahead and click at. And once that scaffolding operation is done, then we end up with a folder with the same name as our controller. Leave types leave types on the corresponding view for what we just generated, which is index on. If we look at the sea ization of file, we see that it looks, well, somewhat unique. But what it really is just a detail at the top with a create link. So that's a template, right? So the list Tempe gives us an angel and tag button for create a table with columns, and these columns are determined by what columns are available in the model class that was used for the template. So if I look back at details, leave details, leave type V M. That's hold on control and person click. Then I see that we had columns I D name on did created and as a result, the index speech knew it legally should leave out I d on top listing. Right, cause you don't necessarily always list the primary key when we're viewing data. But it didnt through the name on the be created on. Then it puts enough for each. So this is some Reaser action happening where it is for each item coming back in model. So model is a key word representing the data that it got right. So I could have named this anything I didn't necessarily need to name model from the controller side. But in the views perspective, the keyword model with a capital and represents whatever d top it cut. Andi, It knows that it got a list. If you look at the top here, you see, that is defending that. The model is at least our I knew, Maribel. Off type this type of object, which is details Leave type VM. So it is seeing that I know I got a collection. And so for each item in this collection, I want a new rule with two columns, one for the name on one for the D created or three columns. So one for me, One for the created and one column dedicated toe edit details and delete links. All right, so we're just going to take this for quick test Run this pinto go into debug mode. So I clicked Are start on and we'll see if this works arts or application has launched. And then I'm going to go toe manage and click leave types. But if you notice that in the bottom left corner is just on Astor's, because we really did not set up any link for this, So I'm just going to go back and still in the boat moored Go to my solution Explorer, find my shared folder in views on a Lee Haute. So my Leo Page has the links on. So we're going to look at whole week about linking on well, setting an anchor, talk to the redirect toe control and a particular action in a controller. So we have helper tugs here, and we can just say SP dash, and then the 1st 1 we want this controller. So the controller that we're working with is leave types, and then I see SP dash again on December 1. Action on the action that I want is index So in other words, when this uncle attack for relief types is clicked, the expectation is that it's going to look for the index action inside off the leaf types controller on DSO. When I meet those changes and save, I go back to the webpage and refresh on, Then I'm going to try again. All right, on when I refreshed, I noticed that the change was not made. And that's because sometimes you need to You may need to restart a project or you may need toe enable this thing called Rose Erling. So I'm just going toe go and enable browser link Right on. I'm also just going to restart my d boat motor just refreshes everything regardless and all the changes that I've made should be reflected. All right, so the project is refreshed and I'm going to go ahead and grows once again to leave types on this time, the link is up and there we go. So, no, where on the page that would have the data. So we're looking at the table with a column for name and a column for Did Created on notice . All d created this kind off Kate on. It's literally the way we wrote it in the class. That's how it's presented here, which is not necessarily desirable. But that is what it is, and someone to show you how we can modify the view model toe handle this kind of experience . I'm and not have to do it manually in the view file. But there is no data because we haven't added any records as yet on. If I could create new, then it's going toe given error, because then it looked for the create view on notice it saying that it could not find anything inside anywhere called Creates that CS HTML. That's because you haven't generated that viewers yet, so at least we know that it's working if I do a break point. So I'm going to go back into my project to go back into the controller on going to set a break point at the first line off our index actions, Understand, to refresh that paid someone to click on the link again on then it's going to hit the brake points. It is just it is lighting up on. Do we see you here where? Okay, it hits the brake point and then it goes into the function costs. I'm going to use F 11 toe, take a step by step into what is happening. And so it goes in tow. Our repository class, it's calling find all on. Then it's going to use that chord that we wrote toe interrogate to see if there any leaf types. And if I over I see that a county zero there were no leave types to be brought over. So I'm going to continue with 11 and then it exits the rib poster class goes back to the controller. No leafed types in the controller has all the data it needs are known in this case. And then over my upper goes into action on then if I just do if 11 we see that it does the mapping and then it returns of you. And so I just do f five to just continue and ignore any other bricks on. Then it reloads the page so we can see that everything is working as how we have wired it toe work. Now I'm going to show you how you can make adjustments on the view model that will affect hold. This plays are done in the view. So I went to exit debug mode because you can change some called in debug mode. I can't change some court. So the view model cord is among those that you may find difficult to change while in view in debug mode. So I'm going to go over to leave type VM on. Then I'm going to add an attribute over the deed creative property on. Then this one is going to be display on then this plea isn't have a brace and then I can see name is equal toe and then I'm going to say deed created, so noticed I am going to I am putting a space here because it was coming or Camel K is just the same way. So I said, this playing name equals did space created. So it looks more reader friendly, someone toe refresh. I'm going to make those changes going to debug mode again and see what difference that made in the display. All right, so our application is open. We bro's to leave types and then you would notice that the printing is different. Label is different, so that's what we can control the labels off or feels in our views without having to do it manually, because you can imagine if we have 10 views that are using this same view model on then for those 10 views you have to go through and change it manually. So we're using the view model. We just change it one time. We just say, when you're being displayed, he's display yourself like this. All right, so even name name is kind of generic. I can probably put a display name off leaf type, identify or leave type name. Whatever it is I want to put their on. That is what will actually get rendered in the view to the user. All right, so that's how view models work with views and make maintenance easier. All right, so just a quick recap of what we did. We set up our index view where we used or dependency injection toe make a B two b square called, and we used arm upper to mop the data coming from the database to the view model structure . And then we generated the view based on the view model passed in the data, and we verified that it hit the database, got the data are known in this case on did the operation as expected, In the next video, we will work through our create actions on. Then we will start creating data so that the next time we look at the list off leave types in the database, then there will be data Toby displayed.
17. Setup Leave Type Create View: Hey, guys in this video will be working through setting up or create action for our leave types , controller and model. In the previous video, we would have already set up or index, where we quarried for all the records in the database on Ben returned them on, generated the view that would show them off course. There's nothing in the data base, which is why we're know when to do the create so that we can start creating records and actually seeing that we're interrogating the database. So I'm going to go down to Meyer, create option on, then what I'm going to do is generate a view based on the create leave value model. So I'm just going to go back to my models and go to my leaf type view model and the Here we have the create leave type VM on. All it really needs is the name because we have name, we I d will be generated once it's inserted into the database on. Also, we will be responsible for making sure that we provided it created. But we want the user to get a farm where all they have to provide is a name for the leaf type that they're creating. So I'm going to go back to my controller on I'm going to generate Have you someone directed the word view, Click Add View. And then it's already implying that it's creating that the View name should be created because it knows the action on going to choose a template. Create andan. The model class that I'm going to use is the create leave type VM. So, like I said before, you can either create one big view model, and then you spend time cleaning up the farm or whatever view you're generating. Or it can spend time creating multiple view models specific to each view that you intend tohave. So I have the creates leave type view model on. I'm going to leave everything else as is and click add on. Then that scaffolding generates that few all right, so we and coincident era where it to seem that there was the few could not be generated because it requires a primary key on it has to be defined. So by that logic, we cannot use that particular view model or idea behind the view model to create that view , so be careful when you're choosing the feels when you're spitting them out, you have to include the key. So based on that, I'm just going to go ahead with the details. Leave type VM because that one had a key attribute and I'm going to go ahead and click out again on Let It Scaffold the view. So I hope you learn that lesson that you know you need to be careful with the feels on. Generally speaking, scaffolding is looking forward to having a primary key. So based on that logic, my initial approach off having the details view model different from the create type view model is flawed. So what I'm going to do is just condense them someone to remove the idea off the create types. I'm just modifying my view models here on. I'm going to add the attribute for required above name here on. Then I'm going to take off the special name off details league leave type, so off course, if I do all of that, then I'm going to have to go through ongoing toe after refractor the court. So wherever I may have referenced details, leave type VM. I need to know rename it toe leave type VM and visual studio will make it sort off easy for me by opting to just rename Those references are owned my project. So if I go back to my comptroller, then you see that I know of leave type VM and no longer details Leave type VM Also in my ma pings folder, the changes were made so no, I no longer have a creates. I can remove this line and I have just one line for my leave type VM All right, so, pursing on, we're going to go back to your controller on oil. Sorry. So we had just created our creative you on. I'm just going to go over to my create view on Look at it again. I see here it's nosing lyft vm Even though we created it with details Once again, visual studio refracted the court for us. I'm going to take this line out. I don't need this each for lying specifying are declaring what the the data type is that it's built on top off. But this is the create on do you notice that is really just giving us a farm. It's seeing that we have Ah, well, it's a bootstrap form. So photobox I'm not sure if it's pollster, but we will see it in a few. So ever form on, we have, ah, validation summary. So it gives there any errors with the model. Then we get to print them out at the top here than we have on input for name. So we have the SP four, um, tag helper, which basically lets us see. Okay, You want an input? What data point from the model that was used to generate this templates. Do you want this input for? So I want an input for name. I also want on input for be it created. So we'll have to do something. And especially with the creative, because this is going to be a DEET on. I don't want users to be putting in the DEET free hand. So we're going to putting a deed picker manually to control what value goes in to be creative. All right, so if we go back to our form tackle, notice that we have another type helper, that's his SP action equals create. So this is b action equals create is going toe. Once we click summit look in tow or controller and fan create. So we have created we have another create with the http post attribute, which is actually the going to be the one receiving and processing the data that is coming from our submit action in the create. All right, So the first thing we want to do is actually look at our handiwork. So I'm going to just go into debug mode. I we're going to look at our creative you all right? So to get to our create page, we're going to go to manage leave types and then that would lead us to the index speech. And then from our index page, we can click over create New Link, which is already wired up to lead to the create page. And so we have or create page. So we have our field for name and we have the field for the deed created. So, like I was saying earlier that it would it's a date time so contextually the bro's or knows that he should put some form of date picker inside off the control. But the down side using the boroughs ear's date picker is that each pros it has its own version of a date picker. So you want consistency across user experiences so you don't want to just leave it like that. And one person is using chrome. Another one is using edge, and they're seeing two different things. So we're going to insert are only pickers so that everybody sees the same thing, which, in the long run, if you're if you have to support this application, will work all better for you on to demonstrate what happens when we click create. So I'm just going toe, go over into visual studio quickly and set a break point at the second Create action on Den I'm going toe. Firstly, click create, and then you notice that it's saying that these are required fields. And that's because we specified in the view model that they are needed someone to put vacation Onda and I'm going to try and put some bits using the date picker or having change . It'll just yet, and then I'm going to click create again. Okay, so actually needed to specify the time also in this date time controller so you can see the danger is there if we just leave it because we really don't need the time or we really don't want users be putting that in any at all anyway, so I'm going to go ahead and click Create hits. The break point that I set up on the second create function. So once we click create from the form, it's going to hit the post function and then we're expected no to do our post checks and make sure all the data is wholesome and massage it's on. Then send it to the database. And then if everything is successful, then we read Arat toe over listing. If not, then we catch errors and handed them accordingly. So that's why we have a create at the top on this one is I get in the way of the create with the post someone to exit debug mode on. Then we're going to write some court. So the first modification I'm going to meet is with our date created. So I did say that would put a date picker. But the reality is that I don't want a user to be seeing the creative that's for our auditing purposes, someone to remove this control altogether on. So we just have the field for name. All right. On day I'm going to meet this button, so we're using bootstrap buttons. So first, where he's in class control form control, which is, Ah, bootstrap class for you know that those rounded edges I saw in the text box. If we look at the the span that's displaying the arrow, we also have a booster classes as text dash danger. That gives us the red takes that we saw come up. So don't here for the button we have BT and Bt and dash primary that gives us a blue button on. I want this blue button to fill the entire space. I'm going to say beaten dash block, and then that will meet the button stretch from one end off the screen to the extreme end on the other screen on. So this is a really simple form. Andi, That's it for the form, at least for now. So we can receive those changes. No, we need to control what happens after a sublet Has a occurred in back to the controller, I'm know, going to modify over http post actions. So firstly, I know what kind of data I want on the data I want. Coming from my form is off type leave type VM. So I'm going to just make sure that the parameter that is in my creed caused option is off type leave type, and I'm going to call this one model. I can call the date I can call it anything is release a parameter. So no, anything that I'm doing regarding the data that was just submitted will be stored inside off model aren't on. Then I went to transaction on catch on error. So this is, uh, cord blood that says I'm going to try something, and if it works, that's good. If it doesn't work, then this is what I want to do. That's what the try catch is. So I'm going to see Firstly, model state is what it's so model state would be like a state that literally the model is in meaning. The data that's coming over once I submitted was all the data that's required actually provided. And if it wasn't, then what do I want to do? Someone to say, If on then I have this thing this property available to me, call the model state on, then it has a property or a cast was like a static class on it has a property called is valid. So that's returning a bullion. So it's basically seeing if it is valid, then what do you want to do? So I'm going to kind of flip this around, and I'm going to say if it is not valid. All right, so I'm checking. If it is not valued, then I just want to return the view because I like to check the bad scenario first and taken action before I deal with the good stuff. Right. So I'm going to say if it is not valid and the exclamation sign is what makes it not all right, then. I really just want to return view. Andi, I'm also going to include the model in that. So whatever data was brought over, if it wasn't valued, I'm going to return the view, and I'm returning the same data that just came in the view that I'm returning fire on. Then if it if this doesn't acute, that means everything was good. Then watch the next step. Then I'm going to say vier leave type is equal to, um up version off this data from Lyft I V m toe the leaf type data class. I'm just going to say underscore mapper and then call the force on that map on. Then I'm seeing that I want leave. Type the data class leave type. That is what I want on. But what I want to be him up to that is model. All right, so model represents on object off leave vmc. I'm just seeing my upper. Please mop this model this object off leave via into this data type And then once you've done that mapping the store it inside off leave type on Then once it's stored inside off leave time my next step is to call the report. So I'm going to call my pre poll dots on its going toe Have a function called create someone to pass in my newly mopped object off type leave type in tow, create and then remember that create is really returning a bullion, which means that if this was not successful, I can take another action. So I'm just going to have another function. Another very Glancy is success is going to be equal to whatever this function called returns on then I'm going to see if not is success meaning if his success returns. If this is a false value, then the action I want to take is going toe. Add on error to the model state. So modesty, or really represents? Well, it has a property that's a collection off errors that can be displayed. So that's why we have the error summary section here, right? So I'm going to add So with the mother state someone to see a model states thought errors or add modeler or other on. Then I'm going to define Well, im would leave key blank, but I'm going to define a Mrs. This is something went wrong. All right, so that means something went wrong in the operation. There were no rose change. Even though we got the model, we got the data, we pass it over on, then we pass it into the create function. And it did what it did to the database. But zero changes were done, and we're seeing something went wrong. And then if something went wrong, then we want to return the view once again with the data. All right, so now we're returning the view again with the data, but this time with an additional era for display on. Then if this does not get executed, that music goes right up to the return where it redirects toe the action called index, which is our least No, I missed one step where I did not provide a value for the date did created. So what I'm going to do is I'm going to see after mapping. Then I'm going toe say leave type dot it's created is equal toe on. Then just call did time Dot knows that means whenever the operation was run, whenever it gets to this point in the court, it should assign the beat and time off the server. That application is being hosted on as the values they created and then proceed to submit it to the database. So that is so when I said that we don't require the user to do that, we are going to be providing it. We can actually do anything we want to do with the model and all the data that is being passed between the form to the database. We control all off that inside off the action before we send it over to the database. No. One other thing that we need to do is modify the the view model so you would have noticed that it was required, even though I have the required set up over name, and I don't have required set up. Over the time when we were feeling on the form, it actually required the daytime. So I need to meet this daytime value. Notable Silas. He's a question mark for a daytime, which means that at the view model Lovely won't pressure me toe provide a value for it on. I can provide a value for it at any point that I which so I'm just going to go ahead and press F five, which is a sharp cookie to start debug mode on. Then we'll see what over Labour has needed it or application is I'm going to start off by putting a break point at our oh, it's already there, so we'll leave that there and then we'll go ahead on and go through our right. That's so let's go through the application so we click, manage, leave types, then we click, create new and then for our form, and you can see that even the put Bt and Block. It was a smaller but it's a bigger but no. But there there must be something else that's restricting it to the space so we can modify the aesthetics later. But we just need to provide Ah name somewhere to say vacation and then click create on then debug mode are R D Bug. Our break point. Sorry is hit so I can hover over the variable in debug mode and see you exactly what's in a variable. So if I hover over a model, then I see that I have the three attributes Have I D, which is zero it created, which is no Onda name, which has the value vacation that we just put in the farm. Aren't someone to actually just step through and see what happens? So I'm going to just use F 11 and then it goes. So our first check where it is is the model state valued on. That is true, so that means this won't get executed. So if 11 is going to skip past that, if statement, then it's going to go into the my upper chord. So it's going toe map the data back toe the leaf time data. Classify looking leave type. It's off type data dot leave, type on, defy, expand. Then I'll see that they created has some generic value because least on the design, it has to have a value. The i. D zero and name is vacation. So we see that the data that came over as leaf type VM is no successfully mapped into Just leave type the data class. Then we provided with the actual date time. No. So no did created has to these date on. If I look at the object once again, then I see that all the properties except I d now have values. And of course I'd easier because I d get set once it's created. So then we move on to the land of court where it actually submitted to the database. So we over to repository and it adds it and then we move on to our sea of changes. All right, on then, if we look at changes, we see that it's one. So it's showing us that at least one change was made So this is going to return true on dso are positively class returns. True also And so our check to see, if not success Success is true, so it's not far. So then it skips over this statement on goes directly toe Ari direct. So I'm just going to press F five at this point on, then let it read Arat on. There we go. No, we see that we're reading from the database, and we just submitted data to the database and this is excellent. No, What we need to do is modify or set up or edit on details and delete functions, and then we're on a good roll. So I'm just going to exit the Bogan would here. I'm going to take off this very point, know that we're sure that this is working kill debug mode, and then we just review what we did. So we set up our creative you by generating or view based on the view model that we would have set up on. Then when we submit, we set up the http post action for the corresponding create action on we set it up to receive data in the form of leaf type V M. And then we check to make sure that everything was valued so Like I said, validations can be done from view model. That is where the date annotations and attributes come into play on. They checked against those data annotations and realize that everything is OK. Then it went on toe map back to our original data model. Transferring the detail also on Ben submits to the database and then, upon successful submission, it returned are redirected rather to the index speech, showing us all of the data. So that's what we did for the try for the catch. We This is just a nice way off handling errors. So for the catch, I'm going to do something like what we did for the success where I'm just going to add a model state error to see if something went wrong and we're going to return the view with the data. All right, so that means if some exception was thrown, maybe the database connection got caught or there was some abnormal occurrence while the operation was happening. That's when the catch really comes into play on. Then the way you handle Eros determines whole users will perceive your application. So if you have the gracefully where you just say, well, something went wrong. But here's a form again then maybe the user, if you better than just seeing one big, nasty error spitting things that they don't really understand. All right, so
18. Setup Leave Type Edit View: Hey, guys, in this Listen, we're going to continue our developments by setting up or edit view now similar toe over, create actions we have get and we have opposed for create. So we also have a get on ah post for it. Andi. It's the same rational We gets the data on in return of you with the form that would be our edit form. And then once you click the button that submits the form or something's the changes that were probably made in the form, then we go over to the post to then do whatever it takes we need to do to make sure that we're getting the CART results. No, please know that for the get action for the edit action, we have a parameter that we're receiving in the form off i d. So it needs to get some I devalue that it will use toe, identify the record that needs to be edited. So if we go back to our index file or index view, you notice that for the action links that were generated on, we can focus on the edit that we had the edit button on it passed in some thing in this wrote I d s B helper in this issue, A little helper tug our attributes and it's it s B roads I d. And it passed in item that I d. So remember, item here represents the items coming in the collection off records being rendered in this view. So we're getting all off the leave types on for each rule that is generated or for each item that is in that collection. Off leaf types were generating a rule on. We're putting its name and the date created, as well as three buttons, each of which will call different action spotting in the I. D or primary key value for that rule on. So what we need to do is make sure that we're using that I d toe Fitch, the particulary record that needs to be edited once you click Edit on a roll. Now, the first thing that I would want to do before I move forward with this is our rather, the first thing I want to implement inside of this action is a check to make sure that whatever I devalue is being passed in, that there is actually a record in the database for that I devalue. And so what I want to do is modify the repository for leaf types. I'm going to go back toe my leaf type repository on. I'm going to implement a new function. As a matter of fact, I'm going to put it in the based repository because it can be useful across all off the repositories, inheriting from a repository bees. So I'm going to include another phone son on this one is going to be a bullion on I'm going to say is exists. So this board and is just going to say yes or no, does that record with this idea exists on this is taking into tidy on then off course. If I put it in the repository beers and I save, then that means everything that is inheriting from Repository Bs needs it implemented. And so I need to go back to my repository classes and I'll start with leave type repository and you see that there's an error on it, saying I need to implement the repository on so I get my is exists function and I just do that for the other two. All right, so is exists exists in all in every posturing. Leave history as well as leave a location are so once again, once you put anything in the interface, you have to make sure that you implemented in the inheriting class. So now my next action would be to configure dysfunction within the context off the leave types. So I'm going to take this out on I'm going to save Our or 12 are exists, is going to be equal toe DB. That's why db object on. I'm going to see leave types, and then the function that I'm going to use this time is that any so dot any is going to return a yes or no, but then it's returning yes or no based on some conditions. So if I just say that any, just like this is basically just going to return if there is any record inside off this table. So if you want to check if a table is empty, this is a nice quick way. It's either empty or it's not empty. So if if there are any records and it returns true, there are records. If they're known that it returns follows, there aren't any records, but then specifically, I want to know if there's any with that particle. I d someone to have to use what we call a lambda expression on dso Inside off these braces , I'm going toe invoked by Lambda Token. I call it a lambda talking alarmed variable whatever it is you want to use. But this can be anything can be w can be exit can pick you Q is the most frequently used. Once you secure in most examples for lambda expressions that you may never see on, then I have equal on degree to then sign on. Then I'm going to see are equal and arrow. So this is like an arrow. I get confused, migrated and in less than saying sometimes. So forgive me, but we have to you and then an arrow on. Then I want to see a cute that so Q embodies any object that is inside of this collection and so I can have access to all of the properties that anyone object might have, including the I D. So I'm just saying, Is there any object in the collection off leave types that has an I D. That is equal toe the idea being passed in through the perimeter here, so I just say I d on. Then once I get a result for that, understand, to return exists. So whether it's true or false, it's just going to return that on. Whatever is calling this function will get a return value off true or falls. So now that you've written the court ones here off course, you can just take it and replicated across the other repository files on. I'll just do that quickly. Were this copy in peace and then make sure to change off the table reference relative to the faster This is the history. Some we can leave histories. If there any with that I d on doing the same for leave allocations on, then that is done. All right, So now that we've put in that function in our repository, we're going to go back to our our controller, and then we're going to meet one modification off our one other modification as you build up. So it is going to need to know if there is any record with idea before it tries the ways it's timeto do any operation. So this is checking if there's any record with that I d. So remember I said always the worst case or the bad case first. So I'm going to say If not so, if this evaluates the falls and what we want to do is return and then we have a nice function here that we can return. That's is not phone. So we knew are using websites and get that four or four era when you click on a link on to get a not phoned era. And that's what this will generate for us. And we give back, not phoned or a 440 So the user, Of course, you can customize that experience a bit more, but for this situation, we're just keeping it simple. So if there is no record with that, I d, then we return are not phoned. Otherwise, we want toe get the leaf type. So I'm going to call a leave type is equal to re pull dot on. Then I'm going toe find by I d. So you see, we set up the framework already on. We're finding the record with the I d. That is being passed in the parameter here. Now our view needs to be set up with our leave type VM or View model. So, like we've been doing for create and any other view that we've set up, we need to do a map somewhere to save. Our model is equal to on the score. Mapper dots mop on. Then we're muffing to leave type VM. That's the data type were mapping toe on the object that were mapping to that data type is leave type on. Then we can close that on DSO model is no going to embody the data that was copied over from, or data base class or a data class toe. Our view model class. It's knowing model on. Then we're returning the view with the data in model. So know that I've done that set up. Have validated that we didn't get a dummy I d on. We're trying not to waste time or research strength of Fetch and I D. That doesn't exist on. Then, after very fine that we got the record that she's being requested, mopped it to the model. I know we're returning the view with models, so no, we need the actual views I'm going to right click go to add view on, then I'm going to select the template for it it, so we see that we have a template for it. It on the model class that is going to be used is leave type V. M. So I find that in the list. On this time, I'm going to actually put in a Leo opiates. So it's is usually opiate. Remember that we had spent some time setting up a Leo PH earlier. Andi. It will basically always default toe one so you could go and specify by going toe by clicking this ellipsis button on, then go into views on shared Andi. You can find the little so we only have one, but you can have multiple Eos. I'm just showing you that if you have multiple layouts, you maybe have different templates working with. Then you can select which layout you want this particular view tohave so there's no harm in actually selecting it. It's their by default anyway, because the only one we have, and it's also set up in the View start file. But then we go ahead and click. Add on, then it's scuffles out the view. Okay, so now we have our view and I'm just going to clean it up, Remove this each for tug on. Then we can just take a look at it. And we realize that it looks just like over create view. We get a form and we get input for our text, which will be the name and the input for the date created, which we don't want. So I'm just going to remove that because they created shouldn't be edited. Right, Onda? One additional thing that I want to point although, is the presence off this? Give that Sorry this input. Sorry, that has a type of hidden on. We notice that it's S p for I. D. So the thing is, we need to track the i d off the record because the only thing that the controller knows is what the view is sending to it. So if we were to remove this line with the inputs, the hidden input for I D. Because I don't need to display the primary key to the user when they're editing the recorder. But then we have it has hidden. But if we remove it from the form altogether when we click, submit or save in this case the controller when it hits the auction for the TTP post, it won't have that that that model won't have that idea. All right, so you see that it's prepped to get an I d here, but this is by default. But the way we scuffled it once it is there as a hidden field, it will be included in the whole model on deter sits that is being returned. And so for the leave types controller on, I'm just going to see if the change that I mean here and I'm just going toe modify the button a bit. So this is save. I'm going to me. This save changes on I'm also going to meet this Bt and success So Bt and success gives us a green button instead of a blue button which is beaten and primary on dive. Also going to meet this one bt and block someone to leave or edit view looking like this for no if they're in their adjustments to meet them later on. But I'm going to focus now on the post action for the edit, someone to remove the default parameters that were generated for us and we can use the same kind of promise that we use in the create host action. So I'm going to just put back leave type VM and call it model on then in the try. The first thing I'm going to do is validate that the data was vital, validated the data hurt. So I can actually just take this if statement Andi Otik back because it's the same check. I'm checking that the more the state is valued because maybe we edited the form I would put in a blank leaf type name. So when we click submit, we still need to make sure that the model state is valid. If it is not, then we just returned the view just the same way, and it will return the edit view with whatever data was put in. All right, so after we've cleared that hurdle on, we can actually just war Ah, lot off court from what we did with the create action. So I can once again take the leave type. Andi, I can Muppet box remember that this line is mapping it. Some just inter borrowed that line someone to mop it from leaf type VM toe leave type or data class and storage in this variable on, then I don't need to modify the date created because they created should never be changed because that gets set when it's period and doesn't change again. But then I can say virus success. So I'm just gonna step so far, is so success is equal to or report dots on. Then we created a function that said up the it on then albeit is expecting on entity or some objects off type leave type, which we have here. So you see, we're passing leave type into our opiate function on. Then we are going to check. If not is success. Then we're also going to return or view, and we're also going toe add a model state error, some just mental ones. Again, borrow this land of cord and stick it in there. Andi, that should be it. So if it is successful, then it will redirect store in the experience showing us the list again. And of course, you can always change where read Eric. So if you have a particular flew in mind and you can always change the redirect toe action and you can even see read Eric toe on action in a different controller if you wish. But I'm just going to modify the catch area. Also, put in that model state error Onda return the view with data on. So that would complete most off what we need to do for our and it actions. So I'm actually just going to going to debug and we can test. All right, so let's never get or edit page leave types on dawn are in experience. We're going to click it. So if you look in the bottom left hand corner, you see the link being generated. Leave types slash it it slash one. So that wanna represents the i. D associated with this rule as well as that I devalue that is going to be passed in tow. Our action. All right, so I'm just going to go back Click Edit and expectation is that the former is going to load with the data for that articular leave type. So if I change this idea in the link on, let's say 10 so I only have one record. Obviously there's no leave type with an idea of 10 and I press enter. Then we get done arrow. So that's that not phoned. Called executing their because, Well, it looked for one with 10 and didn't find it. And so it returned that mart phone. So of course he can manage that experience better if you wish, but I'm just going to serious and go back toe the edit view with one on. Then I'm going to see vacation leaves. I'm changing the name from just Vicky, son. The vacation leave aren't and then I clicked, save changes on. Then it's going to hit the post. Submit the changes to the database on then if you notice the date created, got reset. So I did say that we were going to be sitting the date created because that should never change. However, because it came over and I'm just going to put a break point on that post action so you can see exactly what's happening. I'm going to put it in this line, all right, so I'm going to go into edit again, and I'm just going to see if she changes so that you can see what exactly is happening with that date value. So when I hover over leaf type, you see that that date values resetting because I'm not setting it in the controller, But I'm also not tracking it in the edit. So it is something that I need to truck. What I'm going to do is I want to come out off the boat moored on. Then I'm going to go back into the view for it. It on dso they're created is something I don't need to display, but I need to track. So I'm going to treat that created the same way I'm treating the i d. I don't need to display the i d to the user. However, I do need to truck it doing it during an edit. So I'm just going toe duplicate this line, and then I want to see I want a hidden form, um, elements for it created. Okay, so I missed a vacation, so I'm going to leave vacation alone on going to create another one on Ben. We will see exactly how that works, so I'm going to go back into debug mode, create a new vic, leave type on, then edit it, and then we see that the date created is tracked. All right. Someone to create one and I'm going to call this one sick leave on, then create. No, it's editorialist, and I see that it has a better date created value. I'm going to edit it on going toe, maybe take off the word leave on, then save changes on. Then we're going to hit the break point. And when I hover over it, you're going to see that it created value is routine. So we still know the date created value. Second us. Go ahead and continous. I'm going to remove the break point on. Continue on. Then you see that it routines the data. So any time you have data or you have some object that you want to routine certain elements off because off the nature off our model and view model relationship and the data points, what is being tracked? What isn't being tracked? You can always create hidden feels that will retain the data in between on serve it up when needed. So I'm going to Well, we need to set up our details and delete someone toe have toe. Well, I'm going to remove vacation leave and I'm going to create it again on then it should be okay after that if we get to edit it, so in the next lesson we're going to set off the details you were when we click, details will be led to a page that shows just the details on whatever required it is that we want toe focus on.
19. Setup Leave Type Details View: Hey, guys. In this Nissen will be setting up or details view in our leaf type management model to set up or details view. We'll just need to do a few checks. Want to check if the record that were requesting details on actually exists on, then? If it does, then we proceed to get the data on. Render the view so we'll start off firstly by doing an if statement if and they will call our report object that is exists. So we're going to check if it exists, and then this will return. True if it exists, I want to return or I want to check. If it is going Toe safe also is exists and it's expects a perimeter in the form of an integer. So we're passing it. The I D is going to check if that record exists at all, or if it does not exist, then we just want to return, not phoned. So will refine that experience later on on. Then, if this does not evaluate or this piece statement does not get executed than what we want to do is get var leave type is going to be equal to over report dot find by I d. So we're going to find that particular leave type by its I d on. Then we're going to create another variable. Call it model on in this one. We're going to store the mop versions or calling my upper, not mop on. Then we're mopping beef. Type the data class in tow. Leave type V. M. So I say leave type V M on. Then we're passing in the object that's storing or dita on. Then know that we have that model we know. Just pass it over toe our view. So the next step would be to scuffled This view based on this leaf type VM based us Some just indirectly view goto ad view. Choose the template on in this case we want the details on. Then we're choosing the water class, which is going to be leave type V M on. Then everything else can stay as is. And then we click. Add on, then. Hello? It's to generate the view. All right, so no, our view is generated and, as usual, understand, erase this 84 tag on their we can just take a quick look at what is being displayed So we have a BT and D d tabs eso as usual. You know, we can modify this but I understand the leave it as the default template. But this is what we get as a view. So we get a peacefully name for on then we have a display for and if you notice, it's using Lambda Expressions sightseeing. I want the HTML helper display name for function which is going to display the name and the name there is really let me find my model. So the name there that is talking about is really display name. So remember what we said That tribute for date created where we said the name should be beat space created. So what this helper does really is it says give me the name that is specified as the name four for the attributes in the model. All right, so we're getting the name for whatever property called name there is in or leave type VM on . But then it gets the actual value. So it's no displaying the value and we say display for so we can actually just wrap this entire block off reserve takes inside off anything that we want in a P tag in an H one or H five top. Whatever it is they want to do, we can actually just wrap all our HTML are owned thes helper tags to get the contents kind off whole. You wanted to look all right. So in the same way it's getting the display name for and the date created on. Then it is displaying the actual bit creator and then blow. We see that we get a link so on any page and it is passing my model. So we know that once were clicking at it, it is expecting toe have a value for the i. D. So we're passing more model that idea as a parameter on. Then it also has a button just to go back to the index, which is labeled as back to list. So I'm quickly going to execute this and we can take a look at the details speech. All right, so from our index page, I'm just going to click details and then we're going to watch it navigates to the details for the item with the I D to, and that's what the details speech looks like. So name on it is sick and then date created its space created because it's displaying the name on that bit off details so I can see it's a very simple thing. It's very, um, simplistic, as I just said, but we can modify it as we so desire. If I click edit, then it will redirect into the edit pitch. Vacillate back to list. It goes back to index. So it's always a good rule toe follow when designing a webpage where you can get to any page from almost any other. PH. It's a good rule of thumb, all right, so just by the scaffolding off the views, we kind off realize that they're helping us with that rule. Where if I'm on the edit page on, I want to go back to Index. I don't necessarily have to come here and take this again. But there's a link right. They're accessible to get back to list. If I'm on the details speech on, I want to edit it or go back to list, I can do either, so it's a good rule toe. Follow on, then, from the index speech, I can always just goto create a new one So that's it for no on our details speech. The next thing that we're going to do is work on our delete functions.
20. Setup Leave Type Delete Function: Hey, guys, in this Listen, we're going to be configuring the delete actions in our controller. No, by default or controller generated code. Give us to delete actions. We have one that access to get and one that acts as the post. So pretty much like get is more like it's going to give us a confirmation screen. Are you sure you want to delete the record that you just click delete on and that is going to give us like a yes or no? If we select yes, Then it's misc elegant. Act like a form. Submit on, then the expectations that we pass it over to the post on, then execute the deletion in that host action. Different people approach deletion differently. So some people practice what they call a soft delete where they don't actually remove the record from the database. They put it in a state off in activity that would take some more customization off our court. Andi, some people just delete. So right now, I'm just going to do the base delete as a project expands. Then maybe we'll see the need to do a soft elite instead off. Hardly so for no, I'm just going toe set up the view for the delete action to get action, and then I'm going to set up the logic for the post processing. So by now you would have done both the creator and the delete, so you'll be familiar with the get on the post. So if you take a look at what is expected, it looks very similar to what we did with our did. And it's so literally just going to copy everything that we did for the edit on. I'm just going to paste it inside the delete. So we're checking if the record that is being passed in exists on just remove that extra line. If it does not exist and we return the not phone error if it those exists, which means this statement was not executed. He was skipped by. Then we want toe find it by I d on. Then we want toe return that data. So our views I'm just contracted view on goto ad view and then this time or template is delete. So they have a template for the elite. On as usual over data are our model classes leave type VM on. Then we click Add are so the view we get looks very similar. Tore delete view Understand to remove that H for tag so we get delete and it gives us a message. Very sure you want to delete this off course. We can change the wording as we so desire on. Then it gives us the details off whatever record is about to be removed, and then they give us some any form where it's looking for the option. Delete. It has the hidden element for the i. D. Off the record that is being displayed on. Then it's seeing Do you want to submit? So it says delete. I'm just going to say Value leader records that are changing the text in the button on its already Bt and danger, which is a red button. So this make it Bt and dash block as usual on, then we have a buck to list. So if you get this fire and then you look at it, any a few remorse about the fact that you're deleting it, then you can always just think back to list and go back to the listing if you change your mind. So I know that we set up the get on the view. No, we need toe set up the logic behind actually executing the deletes. I'm just want to borrow cord from our existing post actions because you realize that we're doing a lot of the things. It's the same pattern. Really. So firstly, I'm taking the model. Well, I'm actually not going to take the model because really, n truly it's only passing on I d So notice or form in this situation is only passing on I d on. That's the only data that we can expect from the form that is being that is invoking our http post. So in the the elite host, I'm really just going tohave into idee. I'm not going to pass any model over. So to get the model to be passed over, I would have to go through on actually fill this form with all off the elements, Like what we would have seen in the Creator and the edit form. Onda, we don't need to do that. We just need the idea. So I'm going to show you whole with just the idea again, Still operate. So in the delete we pass in the the i D. But then it's giving me an error. Oh, yes. So this area is because it seemed that there is already a function Action results delete. I can't with that that is accepting a perimeter into my de account off a mother function of the sea and return type. Same name with the same permitted. So I understand, toe put in the model. But this is really to no avail. This is just the distinguish between the post delete action on the get delete. All right, so what's going to happen here is that I'm going to see Well, the model is going to be empty anyway, so that doesn't really much about we're expecting at least the i. D. So know that I have the idea. The first thing I need to find is the entity. So I'm going to save our leave type is equal to andi. Report. Object docked. Find by i d. Because assumed where I can really identify it in the database on dso No, this is the entity that I'm going to be the leading. So the next thing I'm going to do is I'm going to save Ire Is success is equal to underscore re pull dots. And then we had a delete function which is expecting on entity perimeter off type leave type, which is embodied by the results returned by find by I d are on. Then we put it into that function call on, then we can do our esteem and to see if it was successfully deleted. And I'll just borrow that a statement from an existing block. So if it was not successful than return on, put in an area the model state on, we actually don't even need to put in an air in the model state. Really? Because we're not validating the model state since all we're getting back is the idea. Anyway, on there is no riel validation summary being placed anywhere here. So if it was not successfully deleted, then we just returned the view with the model. Otherwise, we redirect to our index. I I'm also learned to check if this I d or the record exists, so I'm going to see having gotten leave type, I'm going to put in an if statement on, say, leave type if leave type is equivalent to know. All right, so that means he got an i. D. It looked it up on. Then nothing was returned, so this is still empty. Then we just returned, not phoned. So it's It's a similar thing to what we've been doing so far. It's slightly different because of the floor off. Whole were sitting up record what? Ultimately it's the same net effect. So you know there are multiple ways to ride the court and situational. You may have to write it differently. So this is one way off. Implementing I delete another way you can implement a delete is by doing everything in just the one get action. So when the person clicks, deletes, then we just do the look up inside off the get do the deletion and then redirect So we really would not have ah confirmation view. But we just have on action that actions the delete and then redirects the index. But of course you want to put in your checks to make sure that this person is absolutely sure that they're trying to delete this record. You want to make sure that you're putting in offensive in peace off any user error. All right, so let's just check and see how this works and I'm just going toe. Well, if there's an error in the try catch, then I'm going to return the view with the model. Also, suddenly just put that in. And then I went to go into debug more than let's tested the heat. All right, so we're at Index and we're testing over delete function. So vacation leave this kindof messed up because the big created value doesn't make any sense. Toe us as human beings. So I'm going to delete this one, and then I'm going to create it again. So I'm going to click, delete, and then he's going to bring up the confirmation screen. There we go. So it's showing us the details. Are you sure you want to delete this on then the big red button that says Delete record or about to Liston? Once again, we're going to fix all of those aesthetics, but for no will just like lead to record on. Then it redirects the index, having removed the record from the data, be successfully. So I'm just going to go through into a full crowd so that we can be sure that everything works. So I'm going to create a new were a card on. I went to the Recreate vacation leave and then I say, Create on. Then we see that we're getting a sensible be it for our vacation leave record. I'm also going to do or edit sick because it should say sick leave and not just six someone to say sick leave and then save changes on. Then we verify that our edit function works if we click on the details and I'm just middle clicking, so it opens details in two different tabs. So we're seeing the details for the sick leave, and we're seeing the details for vacation leave. So we're assured that details work on. Then we just verified that delete works. Now I'm going to modify our delete functionality a bit, and I'm going to take all the need for it to go to the confirmation pitch and then we delete again. What I'm going to do is put in a little confirmation message. So if the person clicks the leads, they're going to see our pop up asking them. Are they sure on Then if they click yes, then it proceeds. If they click no, then nothing happens. But it wouldn't have toe navigato a whole other p just the Ascari shirt if you're ready to delete. So I want to go back to my accord on I'm still in debug mode. I'm not going to come out of debunk more on. I'm going to go to my index view. So I find Index and then I'm going to modify the behavior off my delete button. So inside off the uncle toggle for delete, I'm going to put in a Java script a function called on click. So that's an event so unclear. Ecbc. I wanted to do some things I say on Click is Equal toe And then I would just, like, insert some JavaScript code inside of these quotation marks so that it will do something when it's clicked. So when it does that I wanted to return and then I went to see confirm on then. This is what's going to show the papa box so confirm is going to invoke a pop up box. But then I want a message inside that bubble box I'm going to define. Are you sure you are? You want started to delete this record. So we're asking the user Are you sure you want to delete this record? That's when they click. Delete. It's asking that right there on the Peach. All right, so that's change. Number one, the second chains, I'm going to have to come out of debug mode because no, I'm going to change the behavior off our actions, someone to do everything inside of the gets on. I'm going to do away with the get return view and then confirm, So I'm going to come out of the book more than made those changes. Now, we already saw that with just the idea. We can actually get the record that we want and manipulated as we wish. So literally. All the core that is put into this of this http post function could have been put inside off the get. So what I want to do is actually just take all off this where I find my I d on. Then I check if it's no on. Then I tried the delete, and then I redirect, I'm going to take all off this court on, actually, just replace what's already wrote inside there with that court. So when I click the delete button, it's going to hit this action. It knows the idea is going to find it by I D. It's going to check if it's small on return a 404 If it is on then is going to see I want to try and delete and then we're going to check if it was successful. If it was not successful, then there is no view that I'm returning. Instead, I can return one of those built in functions. So I'm returning, not phoned. Here. I'm going to return something like bad requests, which is a 500 arrow that's, you know, pretty popular when something goes wrong. So I'm just going to return our body requested. So if you're trying to delete it and something went wrong, then we get the body request on. Then we redirect index. So making those changes, I can actually just delete this If I want what I want to leave it there, I'm not want to remove it on goingto go into debug mode and test out this new delete functionality. So to test the thought of going to create Ah, random one number is going to call this one test on create on then we're going to test if we can delete it in one go. So when I treat the leads, we get our pop up. Are you sure you want to delete this record? So that's that confirm dialogue box being triggered by our JavaScript code on. Then I click OK on. Then it's going to action it and redirect, So it's almost like nothing happened. But the record is no missing, so it's not the pages that are many. Refresh on the record went missing, and even if I refresh you notice it, Where's the database again? On it doesn't come back. So that's a nice, clean way off doing a delete without going to a whole other page. Just to ask the question, Are you sure you want to do it on with that? We have completed our crowd operations in the next few videos. We're going to be modifying the look and feel we're going to be changing. Hold the edit details and delete links. Look on, modifying whole or views. It'll no, just a few tweaks. Just make it a bit more appealing on down. We'll be done with the aesthetics, and then we will check in our changes to get talk
21. Add Leave Type Data Table and Font Awesome Icons: Hey, guys, welcome back to another lesson in this session. We're going to be implementing some eight a grades for our index page on. We will be implementing some icons. You know, just add a little more style toe our pages So far now, just to review the work that we've done so far, we have completed crowd operations for our leaf types. We have done over index page where we list all of the leaf types currently in the database . We have created our create form and understand toe open each one in its own top. We've done our delete or details on our at it. So we have our create form, simple but elegant. Wherever edit form on. We also can view the details and we see that we can click Delete on Did it will promise us . Are we sure? And then if we click OK, then the delete will actually happen. So if completed crowd now what we want to do in this Tu Toro is change the way the look and feel off the table. So you see the table. It's static, it's it's literally just on html table. If there are 100 records and it looks simple. No, because there are only two. If there were 10 you would probably reach midway the page if there were 100 you would end up scrolling. So we're going to be implementing eight a table. We're the number off record. Well, the data table will actually transform the presentation off the records giving us paging on . Also search won't implement a search. No, we'll just put in the data table and then we can refine it as we go along. But at least we'll have the data table there so that when more records start going in, we doing tough to worry that the tip is just going to keep on adding rules and that will have to scroll. Eventually, Body will add in pagination so that it will show maybe 10 records on the first speech and then we have to go to the second paid for the next 10 etcetera, etcetera. We'll also be adding some styles to our links a c create new. It's just one bed link. Edit details, lead. They're all just you know, playing links will be adding some styles and also importing some icons into our application to add a little more flair to the look and feel. No. Before I start all of those wonderful, exciting activities, I just want to go back to visual studio on point, something out real quickly. So earlier I would have mentioned that, you know, when in debug mode, if you make a change to the original page, then the changes would be reflected. If you just refresh, you may not have that experience, and you would have enabled browser link on Still not have had that experience. So visual studio actually does the school thing where one it actually hosts the website in a. In a very small version off Internet information services are s as expressed on it allows you to actually launcher application independent off the boat, mood on make changes and refresh and see them. So, for instance, I'm not in debug mode right now, but I'm going to go to my brother and launch the application on. I can go ahead and click create new on you see that the pH changed. I'm going to put in a test type click create on the application it was created. So I am doing all of this independent off debug mode know the downside to that is if I set a break point, then it won't be able to stop in the middle off the process and actually allow me to see the variables and actually debunk the application. So you know, when we're doing maybe design changes, you know, user interferes changes, then this method would probably be quicker where, especially if you have two monitors, you have the bro's on one side, any of the court on the other side. You made the change your refresh. You see exactly what's happening when you're doing other modifications, the court and the logic, and you want to actually debug the C sharp chord. Then you probably want to do it in debug mode, so you have to my thoughts. You can use them as you see fit. So for this session, we're going to be using the Broza Link version off debugging on. We will just make some visual changes on we just bones between visual studio on our application in the browser. Now, with all that said, let's get into the phone. So I'm on a website data tables dot net on. You can see that it is an advanced interactive greed. And here's an example of what you can expect once you implement it on, it is free. The directions to get started are to the left. They say you need to include two files, one for CSS and one for G s. Now, if you look at them, you notice that they're actually Web links. If I just click in the CSS on copy and if I open a new tab and paste, then you notice that a file pops up in the brother. So these are what? Because CD and links CD and insured for content delivery network on what people do is instead off, requiring that you don't load the hard CSS file like, Oh, we have the bootstrap CSS file in our application, for instance. And others go there, ensure you what? I mean, so in w w we have the CSS Sorry. In lib, we have the bootstrap on an indistinct CSS, and we have the actual fire here. So instead of requiring that we have the physical file on the machine, what they do is host it on the Internet and I lost just embed the cord through their hosting So once again, the first step is toe embed are to include the CSS link or the link to the CSS file in our court. Some want to go back to visual studio on find hourly, old page. So I go down to views shared on open layout on then, in our Leo page, we find the era where the CSS files have been included somewhere to include it underneath the bootstraps. So I said this before that order matters when you're including CSS and JavaScript filed. So you ensure that, you know, bootstrap is probably at the top because a lot of things inherit a lot of other frameworks inherits from bootstraps. CSS file. So I'm just I just did control de on duplicated that file on. Then I'm just going to replace the air treff toe bootstrap with CD and link. So what this does is when the Leo page renders it will include the reference to the CSS fire that we just saw through our browser on. Then they also say that we have to include a Js files on vegetate this Js link and then I went to do a similar operation where I'm going to go down to the JavaScript section on. I'm just going to duplicate this line with the boot straps on. Once again, I'm putting it after Jake where I'm putting it after bootstrap on. Then I'm just going to replace this link with the CD and Link. I know that we have included those. The next directive is to call a single function on, so we're going to have to write some JavaScript to get this function card. So I'm just going to copy this boat, go back toe our visual studio and go to our index piece because our index speech has the table that we would like toa turn into the data table. And just as a reminder, I'm goingto go back to the application. And this is that tip that I'm talking about. So this table needs look something more like this demo that we're seeing here. So I'm going to include I reference to that JavaScript snippet. But the first thing I'm going to do is give it on i d. So I'm going to say I d. And if you're familiar with each similar, then you know that an idea is like a unique identify where for any HTML element someone to say I d is equal to And I'm just going to call this one tbl date. So after labeling our table with the i d tbl data were just going to go to the bottom of the page. And we're going to create a section for the scripts. No. In our layout page, you'll notice that the, you know, below all off the inclusion off all the script files, we have a section where we see render section scripts. So this allows us toe in Stan. She ate a section where we can put JavaScript court if needs be. So to do that, I'm going to say at sign section, and then I'm going to have to specify the name, which is scripts. So if we look back, that's name scripts and then we open on clothes, braces on, then inside off these braces. No, weekend rights are JavaScript. So I'm understand to open up a script section and then I'm going to pace the cord coming from the website. So I'm just going to fix the formatting a bit here so that it's there now, inside off this g A query. So this is Jake worry on inside off this block, What it is doing is seeing I am looking for an element with the i d. So that hashtag and Jake or er in JavaScript in general really means on intimate with that I d. And then whatever comes after the hashtag is the i d that it's looking for. So because this table TBL data is the one that I want to convert into the data table, I'm going to make sure that I see hashtag TBT l data not data table. So this is calling our function, and this function is phoned inside off our file that we are data tables far that we had just included. There we go. So So the danger off, including this reference after we're calling our Jake or record, is that it's going to give a nursing itand find dysfunction because once again, sequence matters. So once we've done all of those activities, we want to see it So you can see that once a family to see if it has an asterisk, they can see if you can build if you want. I'm just going to use control shift and s and what that does is it seems all the changes, so as many facts as you have open on our unsaved control shift in is will save all of them because we're changing client facing court, meaning javascript on HTML, we don't have to build. So if you make c sharp changes, then you have to build to make sure that everybody knows what's going on. If you're just making visual changes, then saving is OK. But now I'm going to go back to our application, and then I'm going to refresh, and this might take a while on after the refresh. Then you should be seeing something looking like this. If you're not seeing something looking like this, then you probably have some missing references are some misplaced references they can always right click, go to inspect. And then I'm hoping that you're probably using cruel more was most modern browsers have the console anyway, on then, the council would probably be showing a bunch off errors in highlighted in red. So if you're getting those errors, he can share them with me, and I can help you through them. If you're not getting any errors and you have a clean console like I do and agreed being displayed as it should. Then you're on the right truck. You know what this greed allows you to do is while you can just start by D created all right, almost effortless. Start by names as many columns as you have you can. It comes by default with starting. He comes with pagination. Like I said, so I only have three records and it says show 10 injuries. So if I had 20 then it would have age one than Page two. Andi. I can even change a number off records I intend our would like to see on the first peach, right? So it's a very It's a very nice way to just get a nice interactive table on day, even include a little search feature. But you have to work a bit harder to get this. Oh, they're regal. It works right out of the box. It works. So even when we're looking at the list off employees, you know you can just click search on, find the one that you want. So that's a nice we off setting up beat a grid Andi that we'll move on to the next activity . Know where we make our buttons a bit more attractive. So know that I'm done with the data tables. I'm going to close this tab on. Then I have to other types available or open to me. So we're going to be using funds awesome to kind of bring some life to our application with some icons. Right? So I have to tops here. I have one, which is bootstrap cdn dot com slash fund. Awesome on I have another one that is fun. Awesome dot com slash the 4.7 points or slash icon. So I want to explain exactly what I'm doing within, and I'm going to start with the one with the icon So fun. Awesome provides, you know, nice, clean icons that we can just embed straight issue male. All we need is a CSS file, and then we can just embed icon So a plus sign for ad, maybe pencil looking icon for it. Whatever the purpose, they have an icon for almost every situation. The website is nice and clean, but then you will see where they're urging you to upgrade to version five. So I'm on four on. Dwell by to be specific 4.7 because with 4.7 is the latest version that four had to offer and Version four is much easier to settle out of the box than version fire. So I'm going to stick with 4.7. Ah, lot off Modern applications still use 4.7, and they still have good icons that we can use for some while. So we're using. Once again, 4.7 on the icons are as listed. Andi, I mean, almost for any occasion you have a Nikon if you want. I conduct suggests email. They give your envelope if you want something for database. If you want something for information, they have icons for almost everything. And if you have an idea in mind, you don't necessarily know the icon boat. You have an idea you can always search on. More than likely the name of the icon much is whatever you're thinking about, so you can always filter quite easily. So, as I said, we really just need a CSS file to use font. Awesome. Andi, they give you the CSS file to download. You can actually get the CSS file through the website, but then, if you just Google fund Awesome 4.7 CD and then you be led to decide bootstrap CD in On, they give you the Cdn link that they are hosting so we can just use the Cdn link instead of getting a physical file and trying to embed it in our applications. So they say, All you have to do is click in this section and it's copied to the clipboard on. Then I'll go to leave management, go back to my Leo or Paige on. Then I'm adding a new CSS for someone toe at this one under all the other references. So I just did control be duplicated that line for the data table CSS file. And then I'm replacing that link with this CD in. So, just like with the data tables example, if I say that Cdn Lincoln pace in the browser and bro's to it, then you'll see that it is just one big CSS file. And the reason this CSS file look so jumbled and complicated if you don't already know is that it is what you call men. If I so unification is really take off all the white spaces all off the you really fun characters and was species and brake lines. To me. The file in size smaller because a computer likes it like this. It looks confusing to human computers. Absolutely no problem reading this. All right, so it's just a bunch of stars and eat style Pretty much gives us on icon, so it does need to reference the icon star that we like on. Then we can embed it in our age, so I'm going to go back, having included the style sheet on. Then we can go back to the index page in. We can make some changes. Toe are links. So let's start with our create links. So I have an uncle tug on going to just add some classes to it. So it's a plane uncle tag. And when I say class equals, you see that the intelligence is giving you, ah whole host off bootstrap classes that are available. So first I'm going to make it look like a button. So I'm just going to say Bt and so bootstrap follows it. Make a link. A regular Uncle Tug looked like a button, so I said btm on then I wanted to be a blue bond, Someone to say BT and Dash Primary. All right, But then I want a plus sign, so it's going to look like a blue button that says create. But then I want, like, a plus sign before the words create new. So I want to go to fund Awesome on. Then I'm going to search and see if they have any plus sign on you see that they have plus and up close circle and they have different variations off a plus are what? I'm going to go with a simple one. So I'm going to click on this on then. What they do is give me the embed court so I don't If you can see someone zoom in a bit today you can probably see the cord a bit better, so I can actually just copy this block off text. Go back to my cord on, then placed it inside off the ANC atop. So we have the anchor tug on. Then we have the text to be displayed inside the ankle tag on in the close, Someone to put it inside off the text area. So the ankle tag no has this I tug, which is referencing Effie on F A plus. So these classes are coming from over. CSS Father, we just included for fun. Awesome, right? So f A and F A plus on. Then we have create new somewhere. Stand to put the space between the icon Andi or words create new. And then I went to control shift as to see apology adjustables layout on the index speech on that, I'm going to go back to my application and just refresh to see the changes. Okay? And that's a start. So we have index and we have created new Andi. I actually want to change the text. Index goes Index doesn't tell me what page? Amman. Yes, I know it's index, but we're going to have many index pages. They probably want to be specific someone to change the sticks. That's a minor change, but the rial objective here was to get the button to look a bit more. You know, the pop a bit more. So we have creating you on. We have that little plus sign there on. Then I'm going to do the same changes for any delete, delete and details. So going back to my cord. Firstly, let me change in extra leave types and probably put like an each are. So that's short for horizontal rules. That puts a little line there on do you know, a little separation and then we have or create button and then I can scroll on and then we have or edit on delete and details. So first, them just going to copy the class. The class directive. That means the button the link look like a button. So I'm just going to pace that in each one on then, Based on the operation, we can change the color. So yes, primary. But then maybe it I'm going to put warning because I want Eddie to be orange. I want details. Maybe to be a success. Green. All right, Actually, I'm going to flip it around. I'm going to leave, beatings us primary, and then I'm going to change, create toe success. So create is going to be a green button with a plus sign, and it is going to be warning details. This primary and delete is going to be danger, which would be a red button. So if I mean those changes quickly, save on just do a quick re fresh just to see what is happening. That we should see them looking more like buttons. All right, there we go. So we have any it details delete under green create button which in the texture on Behar's onto rules. So, you know, I mean, this is my little style. This is me keeping it simple. You may have other ideas, so as you evolve, then you can customize your application and use your own colors as you see fit. But if you understand what's happening so far, then you're on the right track. So for edit, I'm going to use a pencil somewhere to go back to fund. Awesome on. Then I'm going to search for something like a pencil. Maybe if I type the word it they would have something for me. All right. So I just type the word edit, and they gave me a bunch off icons that suggest editing. So I'm going to use a simple pencil. So this use pencil, I can click it. I get the same eye contact with a different class this time. One for the pencil. Andi, I am going toe. Add this to the edit button are on, then for details. I'm going to use an in full. I can. So I go back on, then I just see in four. So I just search in four on. Then they give me info. So, I mean, you can go back and forth, back and forth and quick and copy and paste. Or you can just realize that whatever the name is that they're giving you that is basically the class name. So I know that info if I want this simple in four. Let's I want info, desk, circle. So to get in front, assert that can reuse the same Doug I have Effie on. Then I have Effie Dash in four dash circle. All right. On Espo circle, Incorrectly Circle. All right. On then, for danger. I'm going to just insert or surf or delete. I'm going to insert another time, and I think for delete are I think they have an icon called trash. If they don't, Then we left toe. Revert on. Confirmed that I'm also going to take all these bars. So the bars Let me just go box. You can see what I mean by the bars. These are the bars. Those lines are pipe some people call impact. So I'm taking those out off the display on. So we have edit details on each one, has its all icon on a space on. Then I save on. Then I'm going to go back and let's verify if what we're doing is working. All right, so we see here that the edit has a pencil details as that I I call and delete has the trash . All right. But then, I don't know, maybe the buttons look a bit wordy to me. So I think that a typical use if they see the pencil and the orange, they probably will deduce that this is at it. If they see just the I probably implies that they see more information. And if they see the trash, that implies delete, especially given the color coding off each button. So I'm just going toe modify medicine again because I don't like the words there, and I'm just going to leave the icon. So I'm going back into my uncle tug on. I'm just going to break the line so you can see exactly what's happening inside My uncle tugs. So I'm just putting in a the ankle tag and I'm taking all the word delete out off my orange . But former editor on then for the details I'm taking over the world details on I'm just using the icon for info on then just the same way I want to take all the word delete out off the red button on. I'm just using the trash can. So I mean, once again, your own style will chip in and you can customize it how you see fit. But and this is so I want my index speech. Looks I see of that. And then I'm going to refresh one more time art, and there it looks a bit neater. And so we just have the pencil, the info and delete Andi. I mean, this this column had a religious have any words. I'm just going to put the title tasks there. So for actions, Yeah, those will be action. So to put that title hitter, remember that we had in the table, we had the table headers and we had the display name for name where the date created, and then where this empty one on this empty one represented on MT. Table head off for the column with the actions I'm literally just going toe were at the word actions on then that would kind off completes the changes that we're making. And there we go. So I'm just going to leave with one suggestion. So when we set up the data table and we set of the script Section four data table, please know that each time we have an index pitch because every time we do crowed operations for a particular data class, our table we're going to end up with the sea and four views All the time index create details on did it? No, That means that each time you're probably going to want the data table to be on whichever index speeches being rendered at the time. The way we did it here is that you're going to have to do this every time you have an index speech. Now, what you could do is in the Js file. So in our layout, Page were already referencing Js file that we would have gotten as part off the template on that is inside off w w root Js on site that Js you could put the javascript court here on. Then you could be disciplined enough to know that once you are, you know, you have an index speech, and you want something to be a data table that you call it. I'd tbl DT for data. Sorry. Tibial data. No, the the possible down side to this is that you can only have one element at that time with one idea. So if you have multiple tables on the same page that you want to be table Evita's data table Sorry, Then you're going tohave to modify the cord tow target, each one going forward. However, I can write this script once, and I'm just going to teach this section on, put inside off site dot gs one time so I could write it one time and then be disciplined enough to know that each time I have an index, I'm going to make sure I give the table the i d t b a later so that one side Jesse's included, which it always will be because it's in the layout page anyway, Then that table with that i d will automatically be a data table. So I just made that change, and then I'm just going to refresh on show that it was still work. All right, so the refreshes don't and we still have or data table. And this time I move the court from directly inside the view toe are JavaScript file that is being referenced by the lay low pitch. I remember the layout pages really governing all of what we're seeing at least right? No. So that's it for the modifications to these two views Are these few views I could use this opportunity to tell you that when we go to the create page on, we see that it's already taking up some of the page if you wanted it to take up more or all off the pain. So you see that the page really stretches from this margin, toe that margin to the right, All right, so you can use that line to kind off gauge where it starts and stops. But then this is only taking up some of the space. So, actually, what's happening is that in the creative you and I'll just find it quickly. Leave types create it is using a diff class call. MD four. So, in bootstrap, you can set the width off your entire page using this call MD directive or class. Rather. So if I wanted it to take it goes from one toe. 12. Sorry. Ah, yeah, 12 12. So I this is taking a before. So that's what I third off the potential space. If I increase that to it on die, save on, then I just go back and refresh. Then you see that all the content takes up more space. All right, on. There we go. So it's no taking up it off the potential 12 columns. That means between where the text box and buttons stop on the right. Most margin that was 12 species on oil. Four spaces rather on accounted for are not taken up. So people who have forms that stretcher at the cross Sometimes they just do call MD 12 or sometimes logistical that give. They don't bother toe specify and a low the controls to just feel the entire space. So I just change it to 12 and there we see it's filling the entire space. Andi, I did say Bt and blocks of the button is filling the entire space. No, our battle list links still look dead. I'm challenging you to finalize creative way to set up your battle ist links in inside off the individual views for create edit details on what leaders who have any view anymore. But I'm challenging you to find a nice, creative way toe represent the battle list on any other link that might look plain.
22. Review and Add Changes to GitHub: Hey, guys, in this lesson, we'll be checking in our changes to our source control. But before we get into that, I just want to recap what we didn't the previous lesson, which is where we modified the links to look, you know, a bit more lively at somewhere color to the pages on Guy left you with a challenge to actually input some styles in tow. The buttons and, you know, be creative. So I actually took the challenge myself, but I didn't do too much. All I did was well for the Edit page. I added style. A beating started back to list on that beach in style would be Bt and Dash outlined dash secondary. So if you wanted more references for the button stars and what's possible, then you could always check all the buttons section off our bootstrap documentation. So there is gets bootstrap dot com on, then you know, in the documentation, just look for components on buttons right on. So they show you each off your options. You have primary secondary Andi each while the name in each border is basically the class and the color that you can expect. So you have in four different from primary. So actually I could have used or should have used info instead off primary for the details . So I'm just going to me that change quickly. So that's that's something hired change to me. So all I have to do for details instead of saying beaty and Primary S A Bt and dash info on DSO, it's butcher makes it easy to this ad colors and then they have another set where they say outlines sold. You get the color outline and you see the full button when you hover. So that's what I did for my back to least. But I made it on online and you get a color when you hover. Card. I did that for it. It I did it for details. Also on Di did it for treat but and four create. I had the button for create as Bt and Block. So I just made backed a list, also beating block and I see that they just took up as more space, you know, full with off either line. So those are the changes that I made you problem. Eight other changes and I'm eager to see what you did. But the objective off this video is to check in our changes. No, As we've been going along since we added or project to source control with each father that we modified, you noticed that there is a red ticks. So some have padlocks and some have heretics. The padlock means that it was checked in on hasn't been modified since the last version that was added to source control. The Reddick means that it has been want ified. So if you just hover, you see ending at it. That means some editors made on it is pending a check into the repository. It has not been registered in the source control as a modified file. So, in other words, if I was to lose this project right now, if my project if Michel Butor sorry, crashed, then everything that I would have ended that everything with a red tick would have been lost are those changes would be lost because I feel to check them into source control. So those are the ones that heretics. You'll also notice some with green pluses. And those are seeing pending at So. The plus sign is that since the last version off the project. This file was added. What? I was modified or not. I mean, it was added. I don't know anything about this file. So the local tracking mechanism on the computer, which is the get engine that we would have set up initially that local tracking mechanism is seeing that I know the previous version off the project. On these are the change that you have me. You need to let me store them so that if you have to recover your fast from me, I will have records off them. So like I said, if I was to lose everything right now, everything with a heretic and every green plus would be lost. Then I would have to go and recover the version that was last checked in to source control . So in this video, I'm just going to check in or changes. We made quite a few changes. We added crowd operations for our relief types. On we added view models. We added Autumn Oper. We change some interface interfaces and added some new files along the way. And no, we need to check in so check in. I can distract the solutions. Remember the solution is at the top off the tree, Iraq, the solution on. Then I go and see commit though the comet screen is going to tell me that they're 18 Changes spending All right on. Then they're asking for a message. No, the message needs to be descriptive on for two reasons. If I am developing this by myself, when I'm committing a change are committing you know the cord. I want to remind myself what was done in this version that I am adding to source control. That serves a double purpose. Because no, If I'm working in a team, then somebody who comes along after I have committed court can look at my commit message and kind of deduce the kind off work that I just put in on what it is. I'm checking in. So in this section, you know, they they actually require it. And I said just that you are descriptive. So I'm going to see I did leave type repositories. Andi added. Peter tables, Onda fund awesome icons. All right, so that I think that pretty much sums up all of for we did. We added repositories. Oh, and I'm going to say and crude so we added, leave type repositories and crude on at a data tables on fund awesome icons. Now, when you click Comet, it's going toe comet. Locally, it's not going to push it to get up. It's going to start locally, so to do everything. One time I just use the down arrow and I say Commit all and sink so I will do it locally. Make all the changes here on. Then you will connect to get hope on. Then push all the changes to get up art. And then once that's done, you should see successfully synchronise incoming and outgoing payments. So it does two things. It does a synchronization where if you are checking in court after somebody else has done so, then it will don't load the latest version that is in the source control on, then at your changes. So it kind of make sure is that makes sure that there is parity in the cord at all times and in your court. So once again in a team scenario, when you have multiple persons making modifications to the same application, once you do that synchronization, it pushes air changes, don't loads other people's changes So at this point, if somebody else was making changes on building Autumn other model while I was dealing with these types, once I did that synchronization, then I would have their changes they would have. My changes are So I went to get top, and I'm just very fine that the changes that I made are present on. You can see and leave management in the folder. I'm going to see the comet message added Leave type. So if you stumble upon it on. But that's the latest commit, which was done one minute ago. We can always see ah history off. All the committee you see that are six commits in all. If I click six commits, then it will show me the history off everything that I've done. I did some project files I created the read me on the last one or most recent. One I did was still add the leave leave type repositories. The last one I just did on it also merged the brand so I can look at branches in another lecture. I don't want toe get into branches in this particular to Tora, but at the end of the day, we have checked in our source scored to get up on. Our team has access to the cord if they need it.
23. ASP.Net Core Authentication Overview: Hey, guys, welcome back in this. Listen, we'll be taking a tour off SP .net Cores Identity features what I say. Identity features Identity is the feature set or the library that a speed on it core uses to manage authentication? Andi users So far in our application, we have done quite a bit off work. We've set up the layouts to some extent. We've put in soccer some crowd features for relief types where we can add leave types. Remove leave types, edit them. Onda review them. No, I'm sure you're probably on the receiving end off these lessons and thinking, Well, I'm sure that in a leave management system, it wouldn't be this open for anybody to be able to go in and manage the leaf type. Something like leave types should be reserved for maybe an admin user and Mimi nuts are regular user in the same way. We intend to put in features toe, apply for leave and, by extension, manage leave applications meaning approve or reject them. Also, managed employees and these features would kind of suggest that the users need to be in different categories, right? Somebody needs to be ableto one logging, which means that on a contest that exists somewhere for them to put in my user name on the password and actually authenticate against what we know. So what we would know is what is in the database the information for any given user in the database. Somebody comes in and puts in the information, and then we verify that the information they have put in is correct on. Then we grant them access toe, whether the application altogether or to certain aspects off the application. So in this video, we're going to go through what it takes to actually set up the log in functionality, allowing people to register in our application grand, actually allowing them access to the application or rejecting it. No. When we created this application, we had indicated that we wanted to create it with individual user cones. Support on DSO because we selected those options in our main menu in or enough bar. Before we started putting in other links, we noticed that we had a log in Link Onda Register Ling. All right, so they gave us the lie the underlying framework for this to happen And so the feature is there one thing we had to do was run an initial migration, which is where we actually rolled out the tables that were required for this functionality to be supported. So, you know, before no, maybe we would have had toe. And when I say before, no, In previous versions off dotnet framework on dwell dotnet programming and in most other applications, you actually have to sit down and build out your user tables and, you know, outfit all of those things. What happened is that they actually give us the framework. So we just had to run a few commands on they were actually created for us, and we can leverage it on. Then they have a number of features for security reasons and that we can leverage, build on top off on improve as we may see fit. But then the fact is that it is a pretty robust log in system that they're giving us out of the box, and we want to just have a better understanding of it before we start modifying. Now, back in visual studio, I went to my SQL server object explorer on. Remember that if you don't see that pain anywhere, you can always click view on. Then you would be able to just select it from view, and then you can drag it toe whichever section off visual studio's window, you feel more comfortable with it being I like it to the fire left. So I'm just going toe dark. It's on this side, Andi. I went into SQL Server than into my locals. Local db slash m s SQL db instance On data basis Leave management as that's the name of for database on. Then I'm just showing you that there are a number off tables here with the name SP that dot net or rather the there pretended the names of the tables are pretended with s be next. All right, so all off, those would have been included in that initial migration exercise where we scuffled at the database tables to begin with. Now all of the's tables play some form of role in managing our users. So I'm sure you can deduce that s P Net users is where the users are being stored on If we expand this and just look at the columns, you see that we have an I D. Which uniquely identifies any user. I use the name and email address on We have password hush on phone number. And then when we were building out our models, we actually created an employee model which inherited from the underlying SB net user class on. We extended it by adding some more fuse that we deem necessary for our system. But the fact is, out of the box we got from discriminator toe I d or from I D to discriminate. Although scale standard with our identity libraries, we also have SP net roll. So the rules table pretty much the story. The name, um and will normalize name and I d on d some other data. So what's really important is the name and I move saying that that's the most important between Ayman Normalized name because that's the name off the rule is an administrator or is it an employee role? Is it a supervisor? Or, you know, different applications have different levels off users, and that's what we call rules. So the rules themselves are stored in this table because then you don't want to create a user and then assign a rule. And maybe you you spell administrator in currently on this occasion, and then you end up with the same rule with different variations. So we just start arose one time on. Then we have another important table called is being net user rules. So this is, if you know, database well. This is a many to many relationship because you have many users on. Many users can embody many rules because you can have on an administrator who is also an employee, so they would have to have more than one rules. So to avoid any duplications in either off these tables, they created another table that meets, um, kind of halfway, which is the ESPN. It's user role stable, where it stores the user i D and the role idea. In other words, if I'm user one on I am an employee and employees role I D to then the recording is be net user. Rose is going to look like User I d. One with Rule I d to. If you are maybe a supervisor on gun administrator, then you're going to have two entries in the user idea and let's their I. D. Was five. So we went out 5 to 1, which is administered and five toe three, which is supervisor. Whatever it is that the point is, this is where we create the association between I user Andi he's or her rule Onda. For this video, those are the three. Most important, it was under three tables I'm going to focus on while we understand exactly how user authentications work, no going back to our application. Our first experiment is still create a user, So when we talk about creating a user, it's really registration. You goto facebook dot com for the for first time. You want to register your literally creating. I use a record inside off Facebook's registry so literally, when you goto Facebook and a fellow that form and click sign up, all they did was stay that information from the screen, put it in a database just like the one I just showed. You put it in a user stable on. Then they are low you to log in, and each time you put in your user name that you specified and that password, all they do is stay that information and check if there's a record in the user stable that actually, as I use the name that looks that way, Ana Pastor, that looks that way on. They tell you yes, it's correct. Here, here's the information. It's incorrect. Please, Dragon, that's literally all that's happening on DSO. A speed on it makes it just that easy so I can literally go toe register on. I can provide an email address and I'm going to use Ah, a legitimate email address, someone to put in one off my less used email addresses. And I'm going to put in a password. So the password I'm putting in is the word password. And then I went to Click Register. So when I click register okay, so it's specifying that my password needs to meet certain standards, and that's fine. We can We can be the standards so out of the box. You see that they're kind of telling us the password strength that is required. So the postures strength they're saying that I must about these one non Mary corn non alphanumeric. So, in other words, I must have a capital letters. A Capital P. I must have some character that's not a number or, ah, where are our letter? So I'm going to put the at sign for, you know password s W O R d Andi. They said that I need to have a number, so I'm going to put one. So that's a capital P at sign. S S W O R D one. I don't want to try again. All right, so then it moves on to a page called Register Confirmation and then they give us a little message saying we don't have a really email sender registered, so you can read docks to Seo to configure it, which will be doing later. But normally this would be email, but they're giving us Ah, like a fierce a feeling so in in standard English. In case this doesn't mean much to you when you're signing off for most websites these days , they cannot see peace. Check your email to confirm your identity. When you go to email, usually see an email from them. Where did the sacredness link on? Then you're officially registered. So that's all they're saying. That we need to configure something that will actually trigger an email that does something like this. But in the meanwhile, here is the link that you would have gotten in the EMEA anyway. So once again, we can do that. That's a later day. But let's just continue with confirming or registration. So we click here to confirm on. Then they say Okay, confirm email. So? So I went back to my homepage on and no, I can try and log in. So when I click plug in, I'm going to put in the email that I just used on the password, which is p at sign. Get sorry. Capital P outside s S W O R d one. In case there is in the same password as me on. Then I just click log in on then you see that were loved being and notice that No, the text in the here that said log in and register No changes the hello? Some thing, which is my email address. Andi, they have a logo button. So if I click longboats obvious that I would terminate the session. But just by being here, they know that I am no log in. Now I'm going to go back into visual studio, go back into our database and I'm going to show you the changes that happened when we did that registration process. So in s peanut users understand to right, Click that table and then I'm going to save you data. And then this, Lords, that data PN showing all the data in the database and specifically all the users in the database since SB Net users of storing the user's information on If you pay close attention , you notice that the first true actually has in information for that user just created the user name is Lone Crusader 1989 at Gmail or the same email that I typed. Normalized normalize usually means that they bring in tow one standard. So if you may have written it in mixed case, they're going to make everything upper case, you know, just as I feel safe in case, um, you know, different people type certain bits of information differently. So there, normalizing its to one standard to reduce errors. Um, the email address is the same that normalize it so you can look through all of these, you see, email confirmed is true. So when we did not click the link, this would have been falls on. As long as this is for us, that user wouldn't be able to log in. But then, because we click the link or on a normal circumstances, The email would have been sent toe the registering party on. Then they would think that email it would then change this flag to true. So all of that is built in its own off the box on literally. This is all that these big companies with registration systems that seems so advanced and robust, asking it to confirming email. That's all they do. They have, ah flug on onto you. Click that link. That flag is not changed. So when you try to log in, they say, Boy, you need to change that flag. All right, so we have email Confirmed is true. We have what you call a password has and understand to expand this column, and we're going to spend some time looking at the values in there. So remember that my password was capital P at sign S S W o R d one that's it in English or whichever language we're in. But it was on Avenue, a combination off letters, a number and some character. No, look at what is stored in our database. One. You should never be storing passwords in plain text. That is dangerous because Then if somebody got access to the database and saw your password just Louis to say the word true, they could just see your password, then that's a clear security risk. They know Have enough information to go ahead and access your cones. So whenever you're storing passwords and this is universal to any system or any developments stuck you're using, always create what we call a hush. Now, out of the box, the identity framework Oh, are set off libraries. This feature actually hushed the password so you don't have to do much more work after asking the person for the postured, maybe enforce a standard. But then the storage of it is being taken care off by the feature. All right, so this hush you can never tell what my password was originally by looking at that block off text moving along there. Other columns that are for this video, for the purposes off this video. Less important, boy of security stamp concurrent system. We have a full number, um, field onder when it wasn't confirmed. So we see four number and full number confirmed fall. So then that scene that you could build in a feature where you send an SMS to the number some something starts off Like what Certain messaging platforms do. Um, then you can move on and you see that all of these other fields are no there really know because, Well, the user record was created based on information that was given on the farm. The farm did not request date of birth be joined. First name, last name tax. I d know enough that was required at the time off registration. So off course, in modifying our application, we can either require the information by modifying the form making sure gets submitted to the database. Or we can, you know, set up some interface that we can actually, um, request that information at a later date. But at the end, off the d, we want to keep our registration simple for this system. Off course, we look into hole. We could modify it later on, but for the purpose of this freedom, want to keep it simple? We need is a user name and a password or an email address and a password, and you see here that were used in the email address as the user name. Also, this is also something that we probably would want to modify because I use the name Doesn't always scream password. Sorry, I use the name because it always creep email. So we we want to modify this, that we allow them to enter user name, enter an email on a password, and then they're into the system. Now if we click hello. If you hover over the block of text that tells you hello, you notice that the hand appears, which suggests that it's clickable right on. When we do that, we see that we get, ah, manage kind of dashboard, and you probably see a message saying Thank you for confirming your email. That's fine, but you'll see all of this. And from here you would be able to view the profile off the user or the user who is lobbying Rather can view their profile. They can view their email and probably make an update. They can change their password by putting in the current one and putting in a new one. It supports two factor. Authentication, of course, would have to configure this properly on. Then they allow you toe view, make a backup off your personal data and also delete your account. I'm showing you all of this because once again, all of these things are out off the box. All you have to do is have an appreciation for whole They work on, then modify. But the initial build that work is not there because Microsoft is seeing Let's get these little things that everybody wants out off the way and focus on the things that really matter. So they give you this out of the box, and then they say, Okay, well, if you need to modify, then go right ahead. No, we've been looking at views and models and controllers all this time. Andi, I have shown you that in the court. If you wanted to see and understand back to visual studio, going back to the solution that if we wanted to see the controllers that we could always go and see the controller on the controller caused the action. So we know when he caused it. Index action is going to look for the view index on. Then we're going to see the index. We we should be comfortable enough with the concept off that by no, But if you take a deeper look, you notice that there are no controllers that mentioned users. There's nothing here that has anything to do with users. Yet if we look at the link, it suggests that there is a section called Identity on a Count and manage on if we know anything but about the Lincoln. Others goto leave type, since that's one we built when we say slash leave types is going to look for the controller called leaf types. If we click on any link like if we click on edit, then we know that it's looking for the controller called Leaf Types, and it's looking for the action, called it and then this passing the permitted to. So the fact is that based on the link, we can kind off the dues where exactly in the court, these actions are being taken, so I can easily find that Oh, it's calling the Edit action, which is getting the tool on. Then it's returning the view that we know we can find inside off the views folder on. We can just easily look at it. No, once again, the point is that the identity structure is not there where you can find the views. Onda. I mean, I can spend some time looking through it. Oh, are you can pause the video and just look through and tell me if you find them, but they're not as readily identifiable on. That's because they did not create a structure like that model view controller structure that we are creating. They didn't do that for the identity features. Now you may be onto something if you pause, then you started looking for yourself. And then if you went into areas on expanded areas, you would see that there's a folder here called Identity on. Then inside identity. You have pages, but then you only have one paid riches of you start, which is only saying which layout it should use. You can have multiple layouts, but that's something for another day. But the fact is, that's all we see suggesting that there is some identity feature somewhere. So I'm as a final act for this video. We're going to build oats. All the pages or other have visual studio providers with access to all the pages that are being used inside off the identity management. All right, so you can just do these few steps and then you have all the pages And then we can start our modification store forms and whole our logic operates. So firstly, I'm going toe right Click on areas on then I'm going to click. Add on then and you don't. It doesn't have to be eras, but just right. Click on then see new scuffled items. See, that's what we've done Controller, You don't class this time we're doing you scuffled item So we clicks new scuffled Item on then this is then going to ask us what do we want to live it? And then in this in the side here we'll see identity. So you just click identity on then click. Add on then is going to do some work. Then they give us this dialog box where there say Okay, we're about to add identity What FAZ do you want so we can select you know one by one which ones we want on once we select them, then they will be provided to us But then I'm just going to say I want them all So I'm just going to click override off fast So the files are implied, so to speak and I see implied because we don't have visibility on them, so they're implied that they're there. So they're saying they want to override the imply it fast with the physical fast. So I'm saying it's over at all files. Give me physical fast attack and see on modify, as I wish on. Then they're going to say, OK, what is the data context class? We know that we have Application DB context as our context. Russ on. Then we can just go ahead and click at. We don't need to provide any other information on. Then we will do some more work are so that might have taken a while. But once it's done, you get this nice bitch with a read me, letting you know that the support was added. Andi, if you need to do further things, then they tell you that you can add these lines to your start off dot CS file. But if I look in my start of that series file and I would see that they're kind of already there, I already have my approaching an authentication authorization. All of those things were there before, so they're just letting you know you can do this in case, right? But we already have it, so we can actually just take this off and then proceed. Now, if we look to our left inside off the pages inside off entity and areas, then we will see that we have a bunch off new files. And if we explained accounts, we see we have lots off new fares. Each of these new fires corresponds with a view that we would see when doing some user related option are some user related operations. So, for instance, we did a registration. Just know. So if I click on the register, then you see that it gives you the court for the registration form. They ask you for the email, they're asking for the password and then ask you to confirm the password right on. That is what gave us that registration form on then. Another thing to note is that we still don't have a controller, So you're probably wondering, OK, so I see the front end or see the HTML and I see on the form is, you know, be rendered. What happens after I click submit. So remember that with our NBC models, NBC According when we hit, Submit it caused but the controller and what we do after you click submit, we would have specified inside off a controller. There is still no controller anywhere here for anything identity related. And that's because these views are using so the identity views are using something called razor Pages. So, Onda, with this, I'm going to close this chapter, and then we can delve into it a bit more. But I just want to have an appreciation off what's happening. So we have our register that CS html. We know that that's a view, right? And we look and we see that. But if we look closely, we see that there is ah correct to the left, or this is the arrow that suggests that there is something else attached toe the view. So if I compare that with the views that we have, so I just went back into my views folder on I'm looking at the leaf types views and you notice that these user just that fast, there's no correct to the left. There's nothing else. These views only correspond with what's in the controller are, But then in this situation, this view, which is the same HTML front and and you know raisel front end. It actually has a C sharp extended extension file that is underneath it. So when I expand and expand anyone off these speeches that was generated, you see that there is a C sharp file underneath it. So if I go into the register not sensational that c sharp, then I'm going to start seeing court that would kindof look like what we've been doing between our models where we built a class. So this year, I have a public class and I call it input model on. I'm doing some properties with some data notations specify the validations. Andi, I'm also doing some functions where I see get Onda posed. All right, so once again, I'm not going to dive into deep. I'm just letting you know that whatever logic is governing the behavior off the registration page outside off the front end is actually being done inside off the dot CS file that is attached toe the view file. So in the next video, we're going to go ahead and modify the register on the log informs
24. Customizing Registration Page and Process: Hey, guys in this video will be going through hold the registration. So in our previous video, we went ahead and we scuffled it all off the identity related pages. We also took a look at the register page where we saw that this view had the form or this file, which is registered at CSE Channel, was the view which had the form for the email imports and the passwords on. Then we went on to notice that it also had, like, a code behind file in the form of a C sharp file or C sharp class, that I load us to control the flow off the application. No, we'll be spending some time and understanding exactly is going on here. And then we'll get a better understanding off. Hold the razor pages work. So these air called razor pages, where the C Sharp Court is directly attached to the few file. All right, so let's go section by section. So we know the using section is where we include all of our libraries. We open up our name space, which is our project. That's the folder structure coming down to the faster that's eras thought identity, dark pages and you see that it corresponds that are ConEd on. Then our file is inside off their corn folder. That's the name space. I have a class, and we call it register model. So by no, you should be familiar with when we say models we mean view models. We mean classes that are designed specially for the particulate view on the view is designed toe interact with the properties being given up are served up directly by the class in question or the view model in question on then this this particulary view model is inheriting from ah based class called page Model. So Page model is built into the speed on a core on our class in this situation is inheriting from it, which allows it to certain things that our regular view models probably have not been doing . Or we haven't had the need to do because our functionalities more spread oats than in the court behind for the direct view. All right, so then we go ahead and we initialize some off. Our dependence is, and we already know about dependency injection. So we have dependencies on because signing manager user managers. So these two are very key in helping us get some functions toe interact with the user database and user data as you go along. We have the logger so longer Just keep struck off What's happening At what point on we have the email center removal on tour constructor, which initialize is each of these dependence is on. Then we move on to some property. So we see here that we're property called input model. Andi Input model is a class on its properties input and then we see it as a data annotation that is buying property. So buying property basically says that if if if something is this said in the class or yes , we have the model, right? So if something's they said in a model on we give the property buying property, it basically gives the view visibility off this property. So in this situation, we're telling the view that it should have visibility off some class called input on. Then if we move along on input is off the type Sorry, some object called input on its off the class type input model. On we have a return euro, which I'll get into the purpose off eventually on. We have a list off authentication alternatives are external logging. So that's if we can forget, like linked in and Facebook and all those you know, Google. All of those other kind of single sign on solutions can be integrated, and we can add them to a list but won't be getting into that today. So if I move on, you see that the next thing is the implementation or the definition off the input model. So we have implement input model implemented here, and it's implemented in the type in the form often object called input shore. But then the definition off our class input model is writes below. So input model is a class on. It has the properties that are being boned toe the form. So I'm going to bones between the form on the model, um, far be it here. So we way we see that we have the properties, email, password and confirm password. You see that each of those has a notations that speak toe validations that need to be carried out. So we're seeing that this is required. The email is required. It is supposed to be an email address so validated as such. So you can validate based on data type an email addresses just there. You can see it's supposed to be an email address. On that. We can see the display Name is genius. I can easily changes to, say, email address. I don't want to display name to just be email. So this pretty name, remember, is what gets displayed on the form as the label for the input for whatever property it is being set for or above. Now, if I go back over to my view file and take a look, I'm going to see here that I have the section for the email on it, as the label is before input that email. So remember that in O. P, once you have a model, we can access the public properties by just using the dot operator. So I have input as the model or we have input model as our class step, and then we have the property. That's bone to the form being input. So input is our object off type input model, which means we can say input that email input that pastored input that confirm password on we can do all of that on the form. So no, it is saying that this is the label for the email property inside a four input object. And I also want an input for that seem property on also the validation. And then it does the same thing for password and the same thing for confirm Posser, which then means if we needed to add more to this form, all of that to say that if you wanted to add more to this form than we would have to go back to our input model on add additional properties to the form to get more detail in there. So I'm just going to go on, see that maybe on down which reference my employees. So remember, we have employees as our data class on employees. In addition, toe all of these properties here. So just looking back, I'm seeing what else we need. So maybe when somebody registers, I want them to provide at least their date off. Our lemina used it after this. Use their tax I d. All right, So when you're registering, you must put in your email address putting a tax I d onda password. All right, are you know, what? Let's use first name, last name, since that's common enough. So we want the first name on last name off, somebody who is signing up when they're at the point of registration. Right? So just using that example, I'm going to go back to register dot c associational SCS on. Then I'm going to add those two properties toe the input model, so I'm going to see required because I require that you put in your first name. Andi. I'm going to see that the data type expected here. I'm not sure if data type string is going to be that strict considering that seconds a data type dots on, then it would list. Oh, the type of data types that it is supporting on. These are in. Um, so you see, it has quite a few Denham's for the data time that it will allow, but I think okay, there sticks so I can just say text to specify that, you know, texts should be what goes into this field when it's validating it on. Then I can set off a display name. So say display on the name is equal to on this one will be first name. All right, so that's my 1st 1 on. So those are the validation or detail notations that will go over in the validation. But then I need the property itself. So it's a prop string on then. This is first name, uh, that wrongly, and he just speaks that quickly. So string tub first in person. Enter on DSO We've added first name and l this copy all of this because it's good to be very similar for the last name. Although change is the display name to last on the property name also to last last name. So no, I just added to feels toe the model. So as far as the CIA station or the View knows, it can support two additional fields. So, no, I need to actually write cord toe, add them to the form. So I'm just going to push the limits. I'm going to take this entire block that is this entire deformed group for email. I'm going to copy it on, then I'm just going to add it twice right above. But then the 1st 1 is going to be input dot First name on the The input is for input. That first name on everything in this whole form group is relative to first name on. Then the 2nd 1 is going to be for last name. So everything here is relative. The last name I know. You see that the registration form just thought a bigger no, you have feels for first name, last name on email. Ah, password on needing to confirm the password. If you needed to put in using him, you could put in using him if you wanted to put in other things that could put in other things. I'll show you later on why the email address ends up as a using him. But the point is, if you didn't want that anyone to them to specify I using him, then you could actually just I have the property with the required validation or the, you know, whatever is preferred as a validation for that field on. Then make sure that it is represented inside off the form. I'm also going toe, um, changed this room beauty and dash primary to bt and dash block. Just, you know, minor changes. But I the end of the deacon. Whatever. And then if you look further down in the form you see the section where they are allowing it to register with another service. So because this this list that I showed you earlier inside off our on the line model there it is there is nothing in that lifts. Nothing goes into that this on. So there's a little esteem and that is being run, which is saying that if the list is empty, then show this message. If the less list is not empty than producer button per enter in that list, right, so you can contextually print are not print HTML or whatever based on different conditions using simple if else using, you know, very C sharp looking court. All right, so I'm going to save those changes. I can just do control shift and s to save all changes. Actually, I feel better doing a build someone to control shift on, be so holding down control and shift and expressing be on doing a build. No. After a successful build, we're sure we have no errors. And I'm just going toe put a break point inside off our model class here, so I'm going to scroll down to one of these functions on Then I'm going to put a very point on the get function, and I went put a break point on the on post. So we have ungh ETS. I will have a cure there, a sink on we have on post facing. So I'm just going to put those very points there and then going to debunk more than and let's see exactly what happens it step off the way, All right, so now we're in debug mode. Let's try to register a user, so I'm going to click register on Ben. It's going toe pause, and then visual studio has been to light up saying that all you hit a very point. So you see, when I click register, what it's doing is loading. It's calling this function, which is just saying, Set a return your and set up the external Loggins list so that list gets initialized here on it gets it from some service that would know if we had configured any external logging lists are not which we haven't, so this is empty, but the return you are is basically like if you're up, let's say you're on amazon dot com on you were on the product speech. But then he said, Oh, you want to log in or you want to register? Sorry. So you click register while you're on the product speed. You fill out the form and you your registered and they automatically log you in. But they return you toe the product speech. That's a purpose off return you are. Oh, so the return you are I'll get set contextually based on you know where it is, which bid you are registering from on. Then it was So this is the page he was on when you registered. The reason says, Equals and all is it's just saying that if no values provided and make it, no, that's all it saying. So if no value was provided inside off this variable, then it's default. But it should be no. So as it stands, we're getting a no return value. Return your URL on an empty, leased off external Loggins, but it's no it knows it's going to the view, So it's not returning of you or anything because that's called that is running behind the view anyway. No. When we look at our screen, we're seeing okay, we have the first name the last name the email address the password under the confirmed Posser on we see to the side here where they're saying that. OK, remember that statement? If there were no external logging services, then display that, Mrs that no water, water, whatever that is being displayed there also. So, no, I can go ahead and fill out this form. So I'm going to say test user, that's first name last name and I went to see a test at email that com know the email doesn't have to be a legit because, well, it's not going to send an email anyway, on then the pastor, I'm going to use the same password p at sign S S W Apple rd one on going to reuse that on. Then I'm going to register No first. Then I'm going to make an error in the pastorate and confirm password. I click register. It's validating and seeing the password confirmation that they pass it on the confirmation . Don't much. Andi, if you look back at our model, you would see that that was the message that was being sent. So they actually have Ah compere gitano t show it is okay. I'm just comparing whatever value is going into this with the value that is going toe, which of other property which in this case is password. So our property password and then the data annotations is compare password, which is that property with this property on then the Aramis. It should be the pastor and confirmation pastor. Do not much so right There is not even submitting to the post and knowing if it's valid or not, is just telling me they don't much. All right, on DSO I'm going to go ahead and re type it in a way that it much is soapy. At San Assessed A Bort won on in the same way. If I did not put in the first name value, it's telling me it's required because I did specify the data on notation that said required . So everything in the form is required on DSO in filling all the form, it will automatically will prompt you, basically at the same time. So unlike with the controllers where it has toe, go to the post action and then check if it's valid, then return with a message. It's like it's loading the entire model and consuming it and letting you know under Fly that, Hey, you're in Violet's son off What the model sees, the values are low to be So first name, last name email address sponsored. Everything is in order. I click register and then we hit the next break. Points are next. Break point here is in the post on we're seeing here that well, we'll step through and look at what each line does so well, the return you religious being set based on what is being passed in. So seeing if it's if it's not empty, that I want the value. If it is empty, then just send them back to the homepage pretty much. That's all it seems. Um, the external Loggins. You know that these are already empty, someone to just sit another break point. And a cool thing is that one you can use F 11 to go line by line, but I really don't need to go to these two lines because they have no value to me. So I can set another break point somewhere else, and then I can just press five, and it will continue to the next break point so that that yellow IRA shows you which break point Or which line is that? So I just removed those two and nowhere. At this break point, you can also hover on the line and actually click this icon on. Then it just runs execution to that exact line anyway, So we have multiple options off debugging or destructing your court as you go along. I went over over Model State. It does do the check on. I'm just going to do an 11 and it says it's valid, so it moves down in tow. The oh, here it is. So model state is valid is it's evaluates to true, Then what it does, it's is give me of ah var. Users of our user that's a new variable are new objects. So viers a very big he word that you can use to see. I want a variable. I don't know what data type it might be. So just give me a variable. Andi. It will assume it's tight based on what's assigned. So if I said Vier Nome, Andi said, equal one that he knows it's an inter facet of iron dome is equal toe open quotation marks on put in a sentence than Gnome is no a string. So that's the support of the Varty word. When you're not sure what data type you're expecting, you can to save ire on DA a variable name on. Then it will. It will assume that object type afterwards. So I'm seeing here. That var user is equal to a new identity user. Andi were passing in the using him on This is all the user name value ends up being the email address because it's passing in the user name as input. That email on the email as input that email. Now there is no feel for the user name. If you had put in a few for the user name, then you just say use the name is equality input dot Whatever field a mutuals email is equal toe the input that email Unless you change that property name notice that is creating the user with only those who properties. But we had a dead other properties in the former first name and last name. So we need to modify our court to make sure that when we create that entity user it knows the user name. Email. First name Onda last name after doing all of that, it passes in the possible. It's a creates another variable called results on. Then this is user monitor, Doc. Create a sing so it passes in that user object that we just created via identity. Um, the identity user he passes in that object as well as whatever password we just entered. This function pretty much will take you off the hashing off the password and the insertion into the database on all of those wonderful things on Dennis's. If result that succeeded. Meaning, did we successfully create this user in the U in the database, then I love that it was created. So log EA was created good on, then generates the cord. So remember that right? Nowhere doing some email confirmation stuff. So we're going to generate that chord. Um, and then it does that funds necessary. Generally, it's all of that court, and then it sends it to the confirm email page. So this is a redirect. So the confirm pH on. Then it goes on toe involved the email center service, which we have not configured on. Send off that email to whatever email just was provided with the text confirm your email. Please confirm your identity by clicking the link in in the body off the email that were Senate seats sending an ankle tag with a link to whatever who just generated as the the confirmation cord in this block off court Here in this block. Cool block. Appear sorry. All right. No, after it does all of that it checks. Doesn't really require confirm, um, account Andi. If it does, then read Eric to the page. So this is actually an option. We can turn off someone to show you hold to turn it off. But I'm still going to configure the email sender so we can check Holter. We can turn it out. So it's sticking. Is it turned on our off it? If it is turned on, then we want to redirect toe this speech, which is another identity papers that we got in the scuffling with that email address on then Otherwise, we just want to go ahead and log in the person. So that's what that block off court the signing manager has to do with your sign incisions . If you're logging in logging roads, that signing manager dot dysfunction lugging this user on DSI is persistent, is falls on. Then we redirect toe wherever you were coming from. If there was any link at all assigned there, if there are arrows, then we specify the arrows that are being generated on. At the end of all of that, we return page. No, that was a mouthful. Um, I mean, the court is pretty straightforward. It's kind of it's very Yeah, it's straightforward. If you just follow the sequence, you can kind of Did you see this? Pay attention to the names off the objects and the names of the functions. You can kind off deduce what is happening, and it's dead because create a sink. I see user. I'm sure you can figure out that this is creating the user with the password, right? Sticking Did that succeed? Was that successful on? Then it does whatever you know it's supposed to do as it goes along. All right, Someone to go ahead on the continents, actually, just mistakenly. But I clicked the play button that line. So if I just click this play button, you see, just jumps toe that line, it just executes as it goes along. So everything that is supported on gets done, and if you just want to see what happens at a particular line, it will just move along. But then at the end off this, it's no finished. It's no longer pausing for me to debug on. Then you see that we redirect to this speech, you're seeing quicker to confirm your calling time, Justin, to confirm. And this is thank you for confirming your email. So that's that next page it moves on to once that's confirmed on. Then I want to come out off the boat moored, and then we're going to look at the data base and I'm just interact with the table and save you data on. Then we see that another. Oh, I had it open already. So if you already have it open, you can just click this refresh button appear and then it will rerun that select worry on re display the data that is there and we see here know that we have to users. We have test now. We just created, and we have known Crusader on notice that we still have no first name or last name for anybody. So I'm going to modify the court so that were assured that the additional fuse actually get pushed to the database. Before I do that, I'm going to delete test user. I just created it. I'm just going to delete it so I can reuse that email address Onda built in is also validation that you can't reuse and email address are using you. Well, yeah, I even adjust are using him if it already exists. So all off, those validations are already built in. So no, I'm going to go back to my razor ceremony registered at CSE Schimmel that CS file and then I'm going to modify our creation off the identity users are conditional. Bed into the user says, use the name email on No, I want to say comma on when I say come. I'm seeing all off the other potential fuse that are coming from the database also, But then notice Identity user doesn't have the additional fears that I created when I put in the employee. So when I'm looking at additional fields that either these are all the default ones I'm not seeing first name not seeing last name on. I can just bring back the employee data class where extended identity user, and I did these fuels toe I didn't to use about, really. I added them to the table, but not to the class. Guidance to user. So in creating a new identity user, it doesn't really know about these because these are parts off employees. So what I'm going to do, then, is instead of creating a new identity user, I'm going to create a new employees on then off course, I'm going to have to bring over the inclusions after run that's running through the file, and I'm seeing new employees on user name email notice nor headlines because employees does know about the identity user fuse using him on email on When I press comma on, I use control spaces to see the list. Then I'm going to notice that I'm seeing all off the identity, use their fields in addition, toe my additional fields for employees. So I'm going to say also, first name is equal to inputs dots. First name on. Then I'm going to see last name is equal to inputs dot last name, all right, and I understand to breathe the lion so that I don't have it going off screen too much. All right, so this form of the court a bit. So now I have a new employees being created and remember, employees extends identity user soas, faras Anything that requires identity user is concerned. Employees looks just like identity user. So I'm creating a new employee and that I'm passing up into the A sink. Create. And if you look in the if you discreet, hover over, create a sink and then look at what it requires, you see that it requires identity user. I'm passing an employee. Once again, it's extending identity user. So as far as create ISS sink is concerned. It's getting an object that looks enough like islands User, it has more problems. I'm going to remove my break points on. Since we know understand what's happening in this post facing function, I'm going to do another registration. Some just inter save all changes on. Then I'm going to do another registration and then we see the full feature. No, this time I'm not going to go into debug more like I said before. What I'm going to do is use bro's air links. So this refresh arrow beside the star button understand to click that Dawn Iro Andi Firstly , need to any of the girls Airlink, if you haven't already done so I'm going to click bro's Erling dashboard, which brings up this dashboard to the left. Well, to my rights, it may bring it up somewhere else on your screen. But then I want to save you in, bro. Sir. Now, when you do that is actually going to launch a quick version off. I s called Eyes Express, which is kind of built into visual studio, but then it will actually host Ah, staging off your website without you being in D both Morneau once again, if you're in this more if you make any adjustment, will you can track your changes the way you can When you're in people more defensive, Rick points hard. So I'm going to go ahead and register and I'm going to you reuse the same test user Andi email address and the some doesn't use their end of the militaristic on. Then the password is the same Pastor p at sign assist of the org one on. I'm just using one password because I don't want to have too many pastors and not remember you know which is which. So no, I see. First name, last name E militarists. Oh, no, I'm adding the additional ones and expectations that when I click register and I'm registered, when I look in the data base, I should see I use a record with the first name on the last name. So when I click register, it goes on to the confirmation illustration. And yes, we know all of that. We click here, toe register on, then we can no go and verify in the database. I'm going to bring back visual studio Still not in debug mode. But I'm going to go over to my object explorer on Look in my table. I think I already have it open. Yes, I do. And then when I click, refresh then it will show me the record for the newly created user, which is test user on the first name. Last name do have values. So for anything that we wanted to enter, we could just, you know, modify our registration cord and make sure that we're counting for it. You'll also notice that in discriminated seeing employees versus guidance to user, so discriminator is actually attracting which class are based classes being used to create this user records. So he knows that identity user is the class in this situation because that was a default one. But then we modified it and know we're creating employees. Are you creating records is in the employee class instead off. So that means you can actually have different classes per user type on. You can easily discriminate, which is which, based on the discriminator. But this is more of a class of listen that real. It's like for roles are anything like that is just seeing Oh yeah, this base class was used for this record on. So maybe it's easier for you to manage on quarry. No, for the the registration requirements or the requirement that at the end of our registration, we send a meal. I'm going toe disable that feature by going toe the start of dot CS So it came enabled for me. I'm not sure if it's unable for you. If it's not, then that's fine. But if it is for you and you want to deceive Lee, then we can just see that we're removing this line. So when we're sitting off the default identities services that at default identity, identity user on you can change this way. You don't have to and I want. But we could change this the employee or any other abstract class, but I leave the defaults to the defaults. Right. But then for the options. I don't want these options. You can add many other options. You can just say comma options dots on. Then they will kind of show you the other options that are available to you. Sorry. Uh, well, actually, I would have to refractor the court. Sorry. So you could have multiple options. You just start off the Lambda Options expression in the nude. Open quotation. Sorry. Breeze. Race is open and close on. Then with each option, it causes the semi colon and Anisa options on. Then you see a dot and then you would be able to see the other options that you can take and specify a password strength from here. You know, if you want to require uppercase, require lower case, require unique characters or you just wanted to be simple. You could enforce that from this level. You could set default time over Tarlac oats number off At times. You know the it could limit so many things from this point or enable so many things from this point. So one off the things that is enabled is the option tohave the require confirmed account is true. That means require that they confirm they're going through the email. I'm just going to disable that we've done quite a bit off work on, so I'm going to disable that on. We won't be confident that email service at least not know So no. When somebody registers, they don't need to confirm their email address again on DSO. We probably have to go back to our register on DCI and something still to reflect that gene . So we have here that the person is ready stirred on. Then we have that we're sending the email. So if we disable the need for the email than we actually don't need any off this school, as a matter of fact, the only call that needs to happen after the person has successfully lobbying is the fact that we're going to sign them in and then redirects them because everything above that will apart from on the longer put, are the longer blind. But everything under longer is geared towards sending that email, redirecting them to the page, having them click something to confirm. All of that goes away if we're just allowing the person to register. So I'm going to take over that entire block off court. Andi, I'm just going to take all this straight breeze on. What's going to happen is that when somebody has successfully registered there was simply get signed in on, then return to their water repeats there were on. I see that know that registration, um, block off court looks what simpler Someone toe test the salt and I went to register again. All right, so I'm in the process off feeling all this form and actually attempted to use the same email address, and it's telling me that it's already taken. So once again, that validation is there for, like, the user name and, well, this is on using him. Not necessarily on the email, but I leave that for later, so I'll see a test at test dot com, and we use the CMP at sign S W O R d one the at sign assist of the already one, and then we click register and then we observe that we go straits toe allowed the in states a redirects to the homepage on We are no longer being so. There was no need for registration on confirmation. We just register and then we're logged in. So that's all we can go about simplifying our customizing or registration experience. Everybody's going to want a different experience for their users.
25. Review Login Functionality: Hey, guys, in this video, we're just going to be looking through the log in functional. We're not going to be doing any modifications or any work too much. I just want us to have an appreciation off what a log in process really is. No, I'm sure Way all use systems. I mean, you have probably log into some form of system to be ableto consume this very video on DSO You are familiar with the fact that to log into a system you have to provide some names, some unique, identify air for you on, then provide a password which, well, if either one is in cards, they will reject your attempts to get access to the system. Now, in simpler terms or in terms, talking about, you know, the whole flow between the form and the database and the logic in between What really happens is that you put in a name you put in a password, you click, enter something collects your information on, then checks. If that name on this password exist in the data bees. And so that's what we want to see exactly whole, um, our application, our whole dark net core actually helps us toe accomplish that kind of functionality. So I'm already loving here as test that test in common with the Click Lago. And then we're back to square one where we have logging and register. So we have a few users in the system already. I'm just going to click log in on then on our log in screen. They're asking us for our email and pastor, and once again we have access to the log in peace so we can customize this. We can remove this if we want. We can change the labeling. We can make our text boxes bigger buttons, bigger. Whatever it is we want to do. We can do but for no, I'm not troubling the aesthetics too much. I'm just focusing on the functionality. So when we provide an email and I went to see a test a test dot com on, then I went to prevent a passer Duchess p at signed S S W O R d one on. Then I click log in what's going to happen, and I just bring up the court. I'm not in debug mode, but understand to bring up the court and we look at our at the function together. So I'm finding blogging and looking at the court behind or the Rays are the court, the court file for the Rays of PGE. So I'm just going to open up this court file and then we'll just look through what happens together. So we see that we have a model. It's inheriting from the page model where war initialization is, and and then the injection stuff happening up there we have or input model. So they're trying to keep the same name as they go across. There's nothing special about the name input model. It is trying to keep the same name so it doesn't look, you know, too confusing. But it could call this one logging model and another at the PGA Call. It released a model, etcetera, etcetera, but well granted, you can't do that cause they already have that. So I'm just pointing, or that the use off input model in both the log in and the registration page. It's not any keyword, Percy. It's just that that's what they're calling the class. So we have our models and our properties that are being boned to the form and then inside the input model we see here that we have ah, field for email, which is required, and it's off type email address, which means that it must be email address format. We also have our required password, and then we have something which is a bullion for Remember me or not on get it renders the page pretty much. That's what it does. It does, says Return. You are if it's no RMT display messages if needs be set up. The return Euro Sino tiff, If anything, so that you can have a clean logging process, it tries to clear any cookies that might be there and then on the post. That's where the work really gets done. So once I click, submit or I could clog in on the form. It triggers the post action, which then sets the return. You Earl validates the state off the data. That is the validity off the data that is being submitted and then it goes on to see results is equal to signing manager docked password signing a sink so postured signing is going to pass in and you can just hover over the function and then you get a hint as to what it is requiring. So he really quiet requires the user name on the password to sign in. So it's seeing Give me. I use the name, Give me a password, Give me a bully and give me a bullion. That's what it's asking for So we're passing in the email because we're using the email as the user name, at least by default. That's what it is. So unless we change its under registration form and change the logic and we don't need to change this but email input, not email on input the password on then they're asking, Do you want to remember me? So that's what they mean by persists that I persist this person's information even after they close the browser. Should they come back and still be logged in. So unless you think, remember me well, whatever you decide that's gets set on. Then it kind off tells that the lockout on failure is true. So that means if somebody comes and transfer, log in or ever failed logging attempt and lock it right. So then this function really takes your information hashes dis postured because remember, our pastor does not store the way we spell it or we would identify it on a piece of paper that's not so certain database. So this function is responsible for transforming the data in tow. What a reform is necessary, Checking it against the records in the database on, then seeing yes or no on. Then that is what gets stored. So the results get stored and it has a flag. Was it successful or not? So if it was successful, that means person was loved being on there. No redirected toe the homepage. All right on then. If the if you know, based on the all come off the results, then different actions can be taken, and that's pretty much it toe logging on. Then, later on, they actually have this function on posts and verification. Email, meaning, Um, this is similar is always saw in the registration page, where it's sending some verification to confirm your cones. If you try to log in before you've confirmed their cones, then they would can trigger this. So all of those are there for use off course we can take or what we don't want on customize what we want, you know, in a particle away But the foundation is already said It's understand confirmed that the log in functionality works by just clicking log in on. Then the experience is that we get redirected. Tore homepage on. We can see that we're clearly logged in because they're identifying us by our user name or , in this case, the email address. Whatever value stored in the user name section, that is what the North has. If I click, then we go over toe, manage and then manage aloes a set up or profile. So all of the's ones again, our pages that we have accessed oh on we know that profile has much more to it than just use a name and phone number, not your Continue to use the name right are released by default. They're saying you can't change your using him, but we can change all of that different ones. We just goto profile on me. Just find it so it's in manage. So we have to go into manage and then I can find the profile view, which I'm sorry, maybe I'm looking for the wrong, so it is slash money slash index are so it's really a cone slash manage on remember that the first speech that you would Lord is usually Index. So I just have to find the index file. There we go. And that is our profile. We see or using him on the full number on if we go into the court behind. Then if we wanted the full profile off the user, then we would have toe put in more properties inside off the model that is being boned to the view and then a lower still, actually, you know, odd are subtract from the person's profile peach on what they can and cannot change. All right, and see here where they put in the flag. Disable. So that's literally all that disables that input for using him. They just said, Disabled. I can remove that on. Then I load the user to be able to change their profile are changer user name. If they need toe on, then on post, meaning this person has submitted some change. Then we can put in court to make sure that we're accounting for any modifications that they may have made to their profile. Now, as a final act, I'm just going to walk you through what happens or what the court looks like for the header . Six on on. Okay, so this is using seemed different Leo page than the one I have. I'm just going to go back and go back again. Onda, I'm just going to walk you through the core that governs what happens in this section. When when we're loved in what we see and when we're loved, all what we see on that is available inside off the shared views understand toe collapse, are areas altogether and go down to views than shared on. Then we can look in over logging partial, so are long, impartial. Basically, it inherits the CME signing and use a manager that we've seen on. Then they just say, if sanding manager, that is signed in. So this is like a check to see is their current is they're on active user session right now . If there is an active user session meaning somebody has signed in, then I want to display in enough bar Ah, link toe the manage on the the text. Hello at user dot Identity that name. So whatever the user name is What the reason the user name column off this user who is loved being That is what will be printed as a result off that So I can change all off this if I don't want to say hello. I just wanted to say the user name. That's fine. Um, and also there is the law goat button that when we click lock, go to just posted logo Pass, which Termini its decision on if there is none. So this is if there is a lot of the in session on, then the else's. They're saying that Give me the register link and give me the logging link on. That's basically all there is to log in. So once again, you can customize your experience if you need any assistance. You know you have a particular idea in mind and you're not sure. Exactly. Hold executed. Feel free to drop me a line and be happy to help
26. Add Default Roles and Admin User: Hey, guys, in this video, we're going to set up a few defaults, some default rules. Onda default, admin user. The point of having these defaults would be that when we have our application there certain rules that are going to be there on we want to make sure that at least one user is going to get created because if we finish developing into here and then we move it to a fresh environment with our first database. The point is that when the application is launched in use to create certain things in the upper in the data base so that well, we can have some authentication and someone with a function functionality so two off these rules will be administrator and employ year old on. Also, we want to make sure that we have won at least one administrative user because, well, when everybody registers, they should register under an employee rule. No, just a quick reminder. Our role basically defines who you are in the system. What is it that what is it that you can do so an administrator than that role implies, or that role name implies that this person should be able to do Every single thing are, you know, administrative things in the system, Onda user. Well, we know what a user is. I uses a personal louds in, So the rule identifies what this user can and cannot do in the system. So once again, we want to have on employees and an administrator role on also at least one administrative user. So to get started, we're going to jump into visual studio on. Then we will go into our start up class. So we go for start of that series and then we have to make some modifications here. So what we're going to do, he set up what we call a seed class seed are seeding is something that it's a term that is used to describe what you do to a database when you set up defaults. So by inserting default data into the database, we're calling that seeding the database or putting in things without actually going through the motions off the system. So we're forcing data into the system, and that's what we're going to set up now. The first modification that we want to do is in hours configure services function. We want to find the line. That's a service. Is that our default identity on Dad into different work? So we need to add an additional lying to this. I'm just putting some space on. Then after the part where it adds default identity and says Identity user, we go to the next line and then I say dot on then what I want to add is rules. So I'm going to add some representation. Four rules. So I say add rules. Aan den. The default class for was coming out of identity is identity rules. Sorry it identity rules and then I open and close parentheses on. Then I may need to include something here to get rid of that red line. Actually, what I have here is a spelling error. So it's an entity rule, not identity rules. Sorry about that. So we have at entity User and we have identity rule. All right, so we just add that to the services when we're initiating or default into the engine. We're just making sure that rules will be initiated also. So, having done that, we're going to go over to our configure function on understand, to breathe these lines because I'm going to be adding other lines to this parliament. A list on what I'm adding. The 1st 1 I just goto after end. If I put comma on, then I'm going to add user manager and then I'm going to open my under brackets. And in this I'm passing in the the identity classes for users on which by default, I'm using Identity User. So I'm going toe reuse identity user here, so whatever the default is. So if you're more advanced than you probably would have changes to employee or to whatever data class you're using toe over ready, then that's fine. But whatever the class is that you're going by, let's just reuse that class I'm using Identity User on. I'm going to call this user manager and then I used up Come off on, then the next line is going to be roll. My nature have been under bracket and then am tastic passing in identity rules and just copy and paste that on. Then this is going to be rule manager. All right, so then we have these two new parameters inside off or configure function. No, What we need to do having completed off this is set up. Ah, I'm going to set up a static class, our class that is going to be called inside off or configure function so we could set of the functionality here. But it's good practice to keep this court as clean as possible. So any hefty lift or any additional cording that's not necessarily just vanish initialization. You should probably put somewhere else and then just call it in this in this function or in this source, start about CS file. So I understand to go ahead and go over to my project in Solution Explorer, right? Click my project, and I'm going to add a class on. I'm going to call it seed data. So create that class seed data, All right, So not aware of our class, the first thing I'm going to do to this class is make it static. So in C sharp, when we make us a class static in means that we can call the elements in the castle. The properties are the functions without having to initialize an object off this class. So I'm going to display that in a few. What exactly? I mean, but let's just make it static on then I'm goingto have, ah, public static. So once the classes static, then everything else inside there needs to be static. So if you have a formation, it has to be started. We have a property tax, be static, but I'm calling this function seed on. Then, inside the parameters for this I'm taking biscuit. The same two permitted that I just set up in startups. Understand, Koba, and copy them. So have the user manager on the roll manager. I just copy them them as the parameters inside off the seed function on. Then I'm went toe open and close various and then off course, I have to go ahead and include any missing name spaces. So I'm just to control dot on bring over all the missing name spaces on. There we go. All right, so then that's what one function. But then I have two other functions someone toe have one. That's a seed users and one that says seed rules. So I'm really just into copy this line because I'm not going to type it told from scratch. But I'll explain what exactly the changes are. So this one isn't recalled seed users on this one is only going to see the parameter for the user managers. I'm just removing that role monitor from the original one and we open and close. Brace on. Then I can just repeat that step below. But this one is called seed rolls on. Then this one does not have the user manager. But this one has the role manager. So at the end off this exercise, you should have one form song called Seed, which has, with user manager and rule manager perimeters one called seed users. Which only takes the user manager permit er on one called seed rose. That only takes the roles parameter. All right, no, let's start off with the set up off our rules. So I'm doing it this way because we want the rules to exist before the user. So on day, that's the logical flow. So I'm just doing it as a logical flow. This is not really required to go in this direction. I'm just doing It s a logical flow. So let us set up or rose. So we already identified that we need admin users and admin users will be the ones who add remove leave types that leave allocations, Um, approve or reject leave requests and such on Then our employees will be the ones who just log in and apply for leave and maybe look at their profile and not be their own profiles, stuff like that. So we need to rules once again, administrator on employees. So the first thing I want to do you see if on I want to check if the rule exists, because if the rule exists, then I don't need to create it. And after the first time, the role is going to exist. But it's not like I'm going to me this. May this class or write this scored, put it in the start up, make it, create the rules and then take it out of the start up. I'm going to leave it in the start up. And that means if I run it 20 times, I don't want this rule to get created 20 times. So what I'm going to say is, if the rule does not exist, then created all right, so every time it runs, it's just going to say, Oh, doesn't Rolexes okay? I don't care. Then if it doesn't meaning, maybe it's a fresh database. Ah, fresh system on there. There's nothing in the data base initially. Then it's going to go ahead and create it. So that's what that's a poor off seeding. And when you're at your core properly, you can, you know, go on, bypass a lot of redundancies and missteps. So where Winter at this properly and see if not roll manager. A notice rule manager here is the object that were passing in the parameter rule manager docked on. They were going to use a function from rule manager. So we see we have a number of functions. What? The one I'm interested in for this operation is roll exists. All right, so it's seeing, if not roll exists that a sink and then I'm going to open up my parentheses on then the parameter I'm passing. You know, the value in passing into this function is ah, string with Well, the name off, the off the rules. I'm checking if the roll ad administrator exists on, then we'll to get the bully in the actual bullet. And for this I have to say not result. All right, so all of this is going to return a boolean so saying, Does it exist? Yes or no? But then I'm forcing not. I'm only checking, if not so. If it doesn't exist, then the action I intend to take is to create a new rule. Someone to save ire. Role is equal to new on DSI identity rule. So the cycle when we're creating, I use a Web identity user. When we're creating a role, we have identity roll, and then I'm going to initialize this new object by passing in a name on the name is going to be equal toe the role that I'm interested in creating, which is administrators. Name is equal to administrator and then use a semicolon. So I'm checking. If it doesn't exist, Then I want to create a new role object called Administrator, who removed that cynical. And so I'm creating a new role called Administrator. That's just the object. Now I need to actually action the creation. So the action, the creation I'm going to see roll manager dots create, do you think? And then I'm passing in role on that does it. So basically it's saying if the role administrator does not exist, then create their old on, then I'm going to do the same thing, so I'm just going to copy this block on. I'm going to do the same thing for the employees rose. So already do the check. If you take this, I'm just changing this time from administrator to employees on. I'm going to make sure that I create a role called employees on. We take care of it just like that. So no when it executes, when this block off court or dysfunction is called in the start up, it's going to see if there's no roll call administrator created. If there is known called Employees created on for as many rules as we may need, we can do similar blocks off court. No, I need to see the admin user. So I'm going to write a similar block off court again. I'm going to see if user manager I remember using managers the object that we used in passing and department er something if user manager docked on this time I'm using a different function, so I'm not want to see is exists. But I'm going to try and find by. Well, I went to try and find by name. All right, so find my name on They use the name that I'm giving to my default. Admin is literally just at me. So any the admin user, the default admin users just want to because Acme on, Then I'm going to have to say that result. But then the results this time is not giving me a bully. And it's actually returning the user. So to check, if I got the user are not. I'm just going to say if the result is no. So the 1st 1 was returning a bullion. This time I'm getting on objects under seeing Did I get a full object or the leg? Eternal object. So if I got a null object, that means that name does not take this or no user with that name exists. So I'm going toe save our user is equality new on we're creating. I use this amusing identity user then T user Andi, open up my curly braces on Then I'm initializing the user name. Well, I still spent spent identity wrongly. All right, so let me try that again. So if I controlled space now I get my intelligence. I can see user name is equal to on I'm sitting the user name toe admission on. Then I'm going to set also the email So e mail is equal to ID Mean at local host, some arbitrary. I had mean email. I mean, it's not, you know, it's it's ah, generic user. So that's my object. And then I can close or sorry, use the cynical and and finish on. Then I need to actually create them. So I'm going to save our results. Is equal toe user manager dots creates you think? Andi, if you remember anything from or registration process when we're creating a sink, we need to pass in a user and a password. So I'm going to pass in the user object that we just created, uh, which is identity user. You can see tire lighted and then you say comma on. Then we're expecting some string. That's going to be the passers I'm really, really just going to keep the pasta is simple on right, the word password with a common p so add mean on password on, then I'm I want the results. I'm going to say dot results. So then we're seeing store the results off this operation please. In this variable after we got there it off the operation. No, we need to check. Was it successful? Are not so I'm going to see if result That's succeeded. Then we want Toe added this user to the rules. So let me slow down and recap a bit. So you understand exactly what's happening where checking if there's any user by the user name admin. If something comes back then this is false because we're checking to see if it's no. So if something comes but then it's not know. So obviously nothing happens here. If nothing comes back and we get no, then we want to initialize are create an object off type identity user called User on. We're passing in the using him admin in some email address for this user and they were going to try and create this user. Now if this user was created successfully with the user name off, add me in this case and a passer off bastard on off course. This is just me writing and trying to keep it simple. You probably put other values, but the point is, we're checking to see if this was successful. So if this was successful and we find that are basing. If result that succeeded, then we need to assign this user toe our role because we just created the user. And we've seen that we can create users. But there was no association with a rule, at least not before. No. So, no, I'm creating this user on. I'm going to make sure that upon creation of this user he gets a Scient or or someone to say, user manager dot odd to rule, um on. Then I'm adding this user, so it passing the user object on the role that I'm adding issues. Itto is administrator goes with the administrator, rolls off course. You want to make sure you write this word properly because it's looking for that name. It's not going to try and create a rule to fit whatever you put in there. So if there is no world by the name administrator, probably to get an arrow, But we know that the way where winter at the court is that administrator most exists before the user is created, right? So after that, we just see dot weights, which is basically going to just application. Make sure that this finishes before much else can happen. All right, Aan den, know that we have are two functions configured. We need to put them inside of four main function, which is what is going to get called, which is then going to call these two. So once again, the roles most exists before the user gets created. So I'm seeing seed rules first. Aan den. Well, it expects a parameter of type role manager on the variable value, mostly road manager, which we would have defined in this, um, parameter before. No. So I'm just going to pass the value seed rolls and passed in Roll Manager has object. And then on the sea Rose, I'm going to say seed users on. Then I'm passing in the value used their manager. No. With all that done, we have one more step, which is to me the startup dot CS Call that function upon. Well, obviously on startup. So we need to add the court that cause that function are those set off functions in our startup file and that will be done inside off the conficker function on. We'll do it after we set up, or authentication and authorization services are up. My thuds on then what I'll do is call the static class. So once again, a static class allows him to just call it so I can say seed, it's, uh, which is the name of the static class on. Then see it docked. And then I have access to all of the functions I can because what I really just want seed. As a matter of fact, what I'll do is me these private. So I just made the two functions that I don't need to call from anywhere else private. So I mean seed users and seed rose private Andi Well, seed is public. So when I call seed seed will know that it has access to seed arose and seed users. So I just called seed aan den as parameters. It's expecting user manager and rolled manager, and we have access to those from our firm materialists. In our configure function, soldiers past the tool monitor objects that it's expecting. So she is just one big daisy chain. So we just injected them until the apartment a listing here so that we know we can have access so them on then we're Daisy, chaining them to our static function that we set up, which is then in turn going to just pass them along to the functions that require them. Now, the expectation when I execute on bond launch my application is that when I go into the database, I should be seeing two rules. And I should be seeing I user called admin Onda at least an entry in the user roles table showing that admin is assigned to the particularize All all right. So I went into debug mode and I got this error and it's seeing something about me starting another operation on the same threat. So I'm goingto come out of the boat moored on. I'm going to refractor the court of it. I'm instead going to assign the results of variable. So I'm just going to save our results is equal to on. Then I'm going to say, create Ihsan cruel on, then get the results. So just the same way. Actually realize that sometimes it's more stable when you just to the result, or you get the result, even if you don't have to use it afterwards. So we're just going to do with that on. We'll try again. Andi measure over degree of success that so the factor is that Roe manager not create a sink passing in role that was urging a bit off court. No, I'm seeing virus old is equal to that same block off court dot results someone toe execute once again and let's see. All right, so this time or application launched successfully. But let us verify if what for data got created Some going back into my project going into my Escalon object explorer on. Then I'm going to expand. Well, it's peanut users. Firstly, Andi, I think of the top Open already. So just a quick re fresh on. We had to users. Now we have three. Andi, I'm here looking at them and I see that that mean was not created, are Let me something probably went wrong with the court and we can go back. But I'm not just going to check if the rules were created, though, So I just look in the ESPN, it's Rose Stabler on. Well, okay, so at least we got our administrator and employees role rules so well, if the user was not created and I'm sure the user and Rule Association was not created, so I won't bother to go in there but come out of the book mode on We can recheck our seed beat Ah, configuration our guys. So I put a break point inside of the seed users function on Ben. I executed the application again on did a step through. So using F endeavor, I step through each line off court and I see the error off my ways. The problem is with the password. So the results. If I hover over results, then it's going to tell me that object is telling me that it failed because the pastor requires non alphanumeric. So I was trying a couple of unease away to put in a simple passer. But it is enforcing the rule that it requires a complex password. So I'm just going to put in a complex password and then we should have no problem after that. So I'm just going toe retyped this past season P at sign S s W O R D one on. Then I'm going to once again execute on. Then we should be seeing our admin user Onda the assignment to the administrator rule. All right, so it was low dead, error free and then Let's look back in our database tables, so I expect to see the user. So the streak of the top open. So when I refresh, I should have four users. Here we go on, we have on admin user, newly created aan den. If I look in the SP net user rules, remember that this is a table. That's is which role which user has. It's going to have a reference of the i d for the role and a reference to the i. D for the user. All right, so this is what the role I d looks like. And this is what the user i d looks like as against their both for complex looking strings . But those are the ideas. So, essentially, if I want to make any off the existing users belonged to a particular role, then I will need to find that users i d. So I would have to go back to s peanut users on Let's say I wanted to make the user t at s that be I want this user to be in the roll off employees so it after take the employee I d . And I'll just do it and flow year old I D and put it in the rule I D column on. Then after go and get this user on, put them in there and get their i d. And put it inside off there. Implore the user i d column and then I can move down. So once you moved on, it commits to change to the database that so you can manually insert records in the database. So I'm going to do that. I'm going to make everybody else the employees. So we already set up Adminis an administrator. I just said this 1st 1 as an employee's under is going to go ahead on. The change is not a reason I'm doing this manually. Is that they existed before the role existed. All right, so the mere if i that they existed before the role existed means that there's no way I can really go back and say, um, that they are which Rose are I'm doing it manually because there's no other way for me. Toe associate them, at least not yet would have to be Lota dashboard that are closest associate the user with the rule that we want. So I'm doing it manually, which clearly is not feasible because we're setting up a system where people should be able to come and register on the registration should be unique to employees. So there some sun or a safe assumption. I'll come out of debug mode, and I just made sure that everybody who isn't who was in the system is no on employee roll on that. We have the admin rules. So once again, the next time the system runs, it won't create, recreate the admin user or recreate the rules because they're already there and we put in our checks. No, I was in the presence of seeing that it is not practical to have people register and then go back into the database entry and assigned them to our role. So I'm going to modify or registration cord someone back into areas and back into our account pages and finding or register cord that caught behind on going to modify this registration process where it creates the user. So we we just did this, it it built a user object on. Then it created the user on. Then, he said if the creation was successful, then do something But That's exactly what we just did in our see data. We did build on object for our user. We created the user on, then went on to say if it was successful than we wanted to add to the rule so we can take this block off court here on, put it in our registration logic. So I'm going to say, if the if the registration if the creation step was successful, then I want to add to rule on, then have to change the object type because we're dependence, injecting or we have the dependency or an object represents the user monitor other someone to use that user manager object on it has the same function at to roll. It's going to take the same user because we're consistent with our naming, right? So you're consistent within a me across the application. It can use the same names in multiple places and move the quarter on with ease. Some winter assign this user to the rule, not administrator, but employees. So whenever somebody registers assigned them to the rule off employees on, then we can move along with whatever else happened. So then they can get signed again and once again moving forward. When people register, you assume that you're in a particular road and think off any other system when you register for you to you, too, would never make the mistake off, giving our regular user on add mean role by accident or anything like that. They know that when you were in Mr Through this form, you're going to be a regular user. So we know in our application. When you register through our form, you're going to be an employee. Were seeding on admin on. Then we can set up a mechanism toe. Add more ad means maybe as we see fit, but for no, we have one admin user, and we have the potential to have as many employees in the system as we may need. And with that done, we're basically don't setting up the four rows and default users on. We also put in court so that the non default users, you know, ad hoc users, users who marriages that any point will always get a default roll off employees. So next, where are going to set up some authorizations to see that if you are an admin than your menu, me look like this. And if you're an employee than your many may look like that also, if you're an employee, you don't have access toe administrative things on. An administrator shouldn't be able to apply for leave, you know, things like that. So in the next video, we will set up the authorizations Parool.
27. Control User Access with Role Authorization: Hey, guys in this video will be looking at configuring rules based access. No, for some context. With our application, we have a few options. We have the option to apply for leave, and we also have some administrative options where they can settle, believe times, leave allocations, leave applications and manage employees. No within a real application. And employees should never have any business managing these administrative things in the system and that the same way. And admin probably would never be applying for leave on DSO. We want to restrict based on the Turow's that we have, which are admin on employee, what each 11 sees in the menu and two can actually access. So this video is geared towards looking at how we can authorized access to certain parts of the application based on, well, whether you're loving or not on. Furthermore, based on your rule, the first thing I want to do is set up more context to a marked menu. So when somebody gets it this screen, if they're not logged in, they probably should only see home. And yes, we know wherever playing homepage, that's fine. But at the end, off the day we don't want them to be ableto up. Click apply for leave, so even if it's displayed, they shouldn't be ableto proceed with a leave application on this day. Log in. We haven't been told the features yet, but was still set up whole We can, or look at how we can restrict the access regardless. Also, if the person is not love being and even more so if they're loving, but they're not an administrator, we don't want them to have access or visibility off the management options in the application. So what we're going to do is start off by setting up some authorizations. Or will some filter toe know what is displayed in the menu? And when back in visual studio, if we're going to be modifying the menu than we have to modify our layout page because that is where our menu is defined or enough bar on? Then you see here that we have the Dave Well, we start off with the tug nav bar and we have our button, and then we have our links. So this is the 1st 1 which is home. The 2nd 1 which is apply for leave on then this section where we're seeing that only an admin should ever see this in their menu. So toe contextualized this we can probably reference over Le Guin partial page on it kind of gives us an idea of what is possible. So when we're not authenticated, when somebody's not loved into the application, they will only see a link that says Register and a link that is a cones when they are registered or lobbying. Sorry. Then they're seeing the sea in the same section One link that is saying hello. You're using him on another link for law, goat. The fact is that this, if statement is, is handling what they see when so the condition is is somebody signed in? If there are then displayed the hello message and the logo button otherwise display logging and register so we can adopt that kind off logic on use it to determine in our application what the person will see on the nav bar when they get there. So the first thing that we want to do is reuse this If statements I'm just going toe, copy this and paste it so it seeing if signing manager that is signed in user. And then you see that signing manager has a red line because we need a library for the signing manager to work. But before I do that, I'm going to say that they if the person is signed in, then they need to see this block, which is the drop down list sidedness going to close the if statement. So that statement open. Brace on. We close the brace. So if the person signed in, then we will print this the screen, all right? No, the signing manager once again has a red line. If I go back to log impartial and pay a bit more attention than I realise that above there , including some libraries so ever using Identity Library on were also injecting the signing manager and the user managers. I'm just going to copy all of this from the log in partial, and then I'm going toe paste it over in the layout at the top off the pit. So we're including these libraries in the layup. Its layout actually has access to the objects for signing manager and user manager. And then when I screw alone, we see that the red line is gone because no, the request it libraries are prisons. So this is saying once again is the user signed in, then displayed someone toe go back over to my brother and test that court on. The expectation is that when I refresh that manage should not be displayed because I'm not signed here. All right, so after we refresh, we realize that there is no many option for money, so upon to know there was one. But because of the introduction off or statement, there is no longer one. And then I'm going to go ahead and log in on, then have in love being. We see that many options are no available. So that's all you can, you know, determine what allowed being used or sees on your screen versus I'm not loved in user. No, we did say that we only wanted persons who are off the administrator role to be able to see this. So right now, this user is off the employees role because we set up that rule before on dso that person when even when this person logs in there really shouldn't see the option to manage. So I'm still going tohave toe most of the court a bit. So we check is the person loved being on? Then we're going to have to do another check and see if the user dots is in rule on. Then we're going to specify the rule that we're checking for. So that's a naming convict that's like a of function convention. Right when you want to check on is in something or East something, it just is whatever the action is. So we're checking if the user is in the rule and the rule that we're checking for his ad ministry tour. If the user is an administrator and then we open and those braces and remember that went with the statements, whatever is inside the breezes, whatever is going to get action. So we just did this block on, Put it inside there. So if somebody is love being on, if they are administrator, then we check. Then we print this. So if they're not administrative and clearly that would be printed. So when I save this and go back to the page and refresh, the expectation is that having been loved in as an employee, this manage option will go away in the menu on Douala. So we're still logged in as the employee. But there is no manage option because we're not administrators. Let me just try that again. I'm going to love boats, and then I'm going to go and log in again and this time as administrator. So I'm going to say add mean at smoke. A whole stuff. Come on, the P outside ssw rd one on, then log in. Oh, my But this is not dot com. This is Loca host. I think I might need to change that. I'm probably going to get validation error. Let me try that again. P at sign S S W O R D one. All right. So I'm sorry. I set up my admin user with a bit off mix up. So the user name I'm going to make into an email address. So right now I'm in the SB net users table in the database, and I'm just going to go ahead and say I've been at loca hosts dot com, So in order to change this, so we're going to have to do some configuration because I was somewhat complacent in units , so I'm just seeing that we should have admin at loca host dot com as the user name on then that same user name or email address as the low normalize user near in our capsule on then we know the email addresses. I mean at local host dot com on the normalized email address is local. Host is admits local host dot com So we can just made those changes and submit. Maybe you don't have this problem. I do. So if you followed me to the tea, then I'm just displaying to you on going to try that again. So admin at local host dot com with our password and there were logged deal are. So I'm loving this admin on Dwell. The menu option is not there, and I'm sure that's because I was spelling error somewhere, and that is what I do have. I have had many traitor so Adminis Street or on. Then I'm going to just me that Jian save and then refresh and after a refresh, now we're seeing what we're expecting. So the admin user is seeing the many options that the employee didn't get to see on that loving or not loving user. Even more so didn't get to see no. Restricting the menu is one thing. But then, if you are smart, you know, if you're a smart attacker or somebody who is attacking assistant might be smart on. They might be paying enough attention to realize that whenever they go to leave types, the lynxes, local host or whatever the the link is slash leave types. Now, I'm just going to run an experiment and show you something with this someone to copy this a this link where I know this girl on. I'm going to love boat and while we're restricting the visibility, so this is not love being user on, we're restricting their ability to click on the menu and click on leave types. But then, if they were paying attention and they went directly there, then they would still have access, which is still undesirable. We don't want somebody who is not logged in toe, have access to this screen, even if they type the link indirectly. So there's another level off protection that we can add so we can go back to our project. And this time we're going to add that protection to the controller. So we're going to go to controllers go to leave type controllers on. Then, for the leave time controller, we can add a data annotation that's his authorized. No, let me just put this into perspective. I can see authorized directly over an action, and I'll do that. Authorize. All right on. Then I'll include the missing library on. Then this will actually say that if somebody tries to Bro's to this action or get the view associated with this option, they will need to log in before they get there. Someone to meet that change, save and then go back to our page and then remember that when we just a slash leave types are really loading the index. So when I refresh this, then you're going to start seeing the log in screen and then the return you are a link is going to start making sense where it's actually storing. What the return you are is what the point is. When I try to Bro's directly to leave types, it brought me to the log in screen, so that's what the authorized talk does for you. It says that if you said this stuff over any view or any action inside the controller when that view is requested, then the person used to log in in order to continue. Now that the injury is that when you set it over the action, you're going to have to sit over every action inside the controller if that's desired, because if they shouldn't be able to view the index, then they really shouldn't be able to view any details. Are our create anything on, by the way that we if we're being attention once again we would know that if we said slash on here is an example such that it slash one that Oh, well, I don't have anything with I d one do. I may be too. OK, there we go then. I can still get access to that without being authenticated at all. So on. Easier way to set up authentication for the entire controller because everything that is leave types associated should not be accessible by somebody who is not an admin. Someone to take this authorized tug and I'm winter instead. Put it at the top off the class creation for leave types controller. So you have the line. That's his public class. Whatever the controller name is. Andi, you're going to put that authorize data annotation above that. What this does is say that this entire controller and all of its contents and all that it was collapse it by pressing that minus Sign all of the contents off this controller. Every single action has to be what you have to be authorized in order to get access to any off these actions. So when I make that change and save and then go and refresh, I notice where I'm just refreshing the edit screen, still not authenticated. Then I'm getting that log in screen. And even if I try any other, 1 may be sorry that that's in my clipboard. If I try, let me try and remove this and say slash leave types on guy tried to do something like create so I can go slash create. It's still going to request that I log in before I can move forward. No, let me log in on Just see. And just just to prove that this will work. So I'm logging in as an employee, be outside ssw rd one and then I'm logging in on their No, I have access to the create screen on this is still wrong, So I mean, we're building up to it. So this is still wrong because as an employee, I really should not be able to access the create for leave types. I shouldn't be able to access anything for leave types or anything that is administrative. So no, we need toe put something else on our authorized out to specify who it who is authorized to get access and the who in this case means the rule. So I can just open races on the word authorize. And we see that in tennis, in sustaining us that we have three options to add. We have policy authentication schemes and we have rules in this situation. We want rules, someone to say rules equal on. Then the rule. And I disclosed the breach. Settle for you to do it later on the rule that we're authorizing to interact with anything inside. This this controller is add ministry tour, someone to me, that adjustment and Seve And then I'm going to go back being logged in as the employees, and I'm going to refresh and then you're going to see that we get along in screen. Wow. Even better yet, we didn't even get the access. We got an access denied. We didn't even get the lolly in screen because it's saying that you're not going to have to get the opportunity to log in. You're just not a load toe. Access this resource, All right? So if I was acting as employees on, I wanted to do this, but I was at all I'm access tonight. They're not after law Goats on, then log in again. And then this time as admin. So remember that were to change admin at local host dot com on our pastor. This be assigned a bit sarpy outside assessed of the org one, and then I'm logged in. Then I'm seeing my many options, and then I can bro's freely to my administrative options. All right, so that's it. So we can go our own, you know, global restricting access to certain parts of their application for certain persons. So just to recap, the first thing we did was look at whole from the view perspective from the HTML or the Razer pH perspective, we can restrict what somebody sees. So even if it's a case where you wanted the delete button to show for a certain rule, but not for another role you know an employee can view, but they can't edit and delete. But then an administrator can really and truly only need our statements on. I'm actually just going to open the index view for Leave type. Since that's one we have on, I'm going to show you we have the ankle. It'll showing the edit button, one for the details and one for the delete. I just need an if statement, just like the one that we used in Leo for the menu on. I say, If the user is love being, if the user is in the role, then they can do this, then print that else. Print whatever else, all right, so that means I could say OK, print the details, but regardless, But if the person is at mean, then display the edit Onda delete. So that's how we can control what each row sees from the view. No, for the controller, you know, restricting just based on what they can view on Click is not enough, because if somebody is being attention to the girls, they can probably still attempt to Bro's directly to the page that they're interested in Andi, maybe by Alicia. So in order to block the moat, we would just make sure that we authorize if if the person before just restricting it to log being persons and we just say authorize. So for context, when you try to go on something on Facebook and ate a little again, that's all they really have. They just have something that is authorized access. So this meet the person have to log in on then if you maybe you're with a friend and you saw that they had them admin access toe something. I paid attention to the earl, and then you will home and you try with your log in, you can get access. Then maybe you're not in the rule that your friend is in. So the fact is that you can restrict it based on the rule by saying authorized open brace, defining the rule or rules so you can always say comma on at as many rules as you know you may have. So in this case, I really only want the administrator role to have access to this Controller Andi, as we've been, loads are predict their other controllers that only the administrator should have access to , and they're going to be other controllers that well when I went to restrict, but only somebody who is love being should we have access to. So that's it for learning how to restrict user access to certain parts off your application and contextualizing what each user rule sees.
28. Review and Add Changes to GitHub: Hey, guys, welcome back in this video, we're just going to review all the changes that we have made in our project up to this point on the check in our changes to get up. No, just a reminder. If we look in our it's Explorer or solution expert, we'll see that we have some files with blue padlocks. That means that since the last time they were checked into the source control, they have not changed our they have not been modified. And then we have some with close signs, which means that they were added, They're completely new files on, they're not in the source control. And then we have some with some red ticks. And those really mean that they have a version in the source control on these would heretic means that the changes to these files are not yet committed to source control. So that's what we're going to be doing on this is going to be a really simple process. We just right click on our solution. We click commit, we then give a commit message to remember that we want our message to be clean and, you know, simple as possible. So that somebody who comes along can understand. So I wrote a little missus. You're just saying that I set up user off default Rose and admin on modified the registration process. So that's my comic message. And then after making that message, I just don't the arrow and say Commit all and sink And then that will. Updating my local repository here on the machine on also pushed the changes to get hope. And once again, if you're working in a team, then it will Don't load the latest, um, project that's there that you might not have. All right, on. Once that process is finished, you can always just go to get hopped up. Come on, verify that the chicken was done successfully. So on the Greep. Oh, I see that Leave management on the latest committees there on if I go in. Then it was. Show me what was, you know, changed as a result of that commits or any folder, any file that was checked in with that committee will have that commit message beside it on . That's it. So in the next morn you will actually start building on the employee management module, and we'll see how that goes. So that's it. We've checked in our changes and nowhere ready for the next challenge.
29. Leave Allocation Module Overview: Hey, guys, we're going to be starting a new model off or application, and that will be for the leave. Allocation for this model will be enabling a new section tore application. So we have our managed top, which is only accessible by the admin users on for the leave. Allocations will be listing all off the leaf types, which we already have an interface to create. So we have all off the leaf types here that we can create. But then, for each one that is created, we're going toe, have them listed in the leave allocations on. Then we'll have dedicated buttons that will set up all off the number off days that each employee has for each leave type. Now the trick is that we're going to have to make some database changes. We're going to have to modify the leaf types table because I want to be able to set a default number off these per leave type. Like, for instance, it is standard that you get 10 days sick leave every year. It's also standard that you get 15 days vacation every year, etcetera. So when the leaf type is created, we need to allow the user to put that default number off days for that leaf type on. Then for the allocation, we're going to have to make adjustments to our existing data table. Also, because you want to set that leave type allocation for a period on appeared would be for the calendar year. So we're going to be adding two new few store database tables, one for the leaf types toe set, the default number off days on another one for the period for leave allocations so that when we assign that leave type Onda allocations the users, it will say that it is for the period off the year that it is being set in, and we're going to automate the setting off that pier. So without further, I do, um, in the next video, we'll start working on the database changes that were going to be doing on. We'll build up this model gradually
30. Leave Allocation Module - Database Changes: Hey, guys, welcome back in this video will start making adjustments to our data classes and then we'll migrate. Those changes to the databases should be a short video. It's really just to show that as we develop an application, we mean, you know, change the way off thinking Gene's way. We want to implement something which has implications on the underlying database structure on DSO using court. First, it's really easy toe modify our database as we go forward on. Just keep it as opted eight as possible with our objectives at the time. So our objective for this particular lesson is toe add to other fields. Will I feel her table? So I have to tell somebody find I feel to put in each in the leaf type table. We're going to be adding a new field, and that's for a default number off days. So I'm just going to say public on, then I'm going to see in on then I'm goingto say default days. All right, so this is going to be the number off these when we're creating a leave it up. When the administrator creates a leave type the default, these will be the number off days. That is standard for any one person. That's a base value. Um, when you're allocating the leave, no, you can do it on a case by case basis. To say that you know, business rules would dictate that people who are in the organization for more than five years probably get additional five days to water. The base value is you know, you cannot just like that, but that is why I'm putting in this base value. Are this be for these field to say that, you know, at time of creation off a leaf type? This is the number off these that is standard for this leaf type. So we're going to add that to the data T the data class and the data class once again is in the data folder on we find the particulate one which is leave, type on. We add the property on, then the next one that we're adjusting is leave allocation. So for leave allocation, we already have the number off days. Andi, it's not redundant. I'm setting the number of days in the allocation also, because remember, this might be a calculated value on a case by case basis. Also, we want this number toe be modified or at least reflect. When somebody is applying for leave Will need this number toe do some master, Show them how many days they really have versus they doing tough, right, But the or leave allocation to be storing the number off days that AARP articular employee has on a particular leaf type on. Then what I'm going to add to this is a period on that period once again will indicate that Well, I'm I'm calling a period. I'm period really is going to be an end that represents the year. So this is being recorded in the year 2020. So that's a very first period that will be input into the system. So the period of 2020 when I locate leave, everybody's went to get that articulately for the Pier 2020. When it's 2021 the system will be set up in a way that I mean we can automate it later. But the way I'm building it know is that when they click, allocate, leave type that it should check is there on allocation for an employee for a particular period which is appeared wherein. No, If there is, then don't do it again. If there isn't, then apply. So if we do it one time for 2020 that employees should never get another allocation Inter for the period of 2020. However, if we do it in 2021 then that employee who had it for 2020 will know will get a new allocation for 2021 on. Everything will be recalculated on. Once again, business rules can determine can be used to determine the actual number off these relative to the base value. So I went through a whole bunch of explanation, but I'm just showing the justification for the modifications that I'm making this. I don't want this to be another court along. I want us to understand exactly what's happening on why I am making the changes so you may see it a different way. You mean, you know, have a different way of thinking if you do feel free to share that with me. But for no, I'm adding those two feels for those particular reasons. So know that I've added these fees. I have a number of adjustments to me. Otherwise, firstly, I need to update the actual database. Remember that we would have already had the database generated. If I go to the SQL Object Explorer once again, if you don't see this over panels are anywhere on your screen. You can always go to view on find it. SQL server object Explorer on. Then if I drill down into the database, which is leave management, then you will see that I already have these tables and leave types is well, it does not have the default these column that I just added. All right, so it has a three feels arm, and it's less default. So obviously I need to update this database so that it no has d for these. So in order to do that, we goto our package. Consul Package manager console. Sorry on. If you don't see this in the base menu, you can goto tools on you. See, you get package manager, and then you can say package manager console. So that's what you get toe that tool on. Then here you can add a migration. So each time you make an adjustment to your database, you mean the file? You know, you made adjustments of the data classes and you have to add a migration. Onda. I've been through this. What I do do it again. Each time you add a migration, you get a new file. That kind off depicts the changes. So when you're adding the migration, you want to put a little message. Their toe kind of depict the changes that you've made. No. If somebody comes after maybe 56 months off your migrations on, they get this project fresh, maybe even from ghetto bar. From what to a source bunch of engine. They can easily run a command that will look at all of the migration first and build the database to the last or latest standard. So it's a good way to track the changes that you're doing, and you can always remove migrations. You can always repeal changes that you've made, but it's a good way to track all the changes you're making to your database. So add migration and then I'll say, added e fault days. Onda here are all right, so I'm seeing added default. These and peer of those are the two things have added a press enter. It does some magic where it builds the project on Once that is completed, we'll see the message build succeeded and that we can remove the migration by its name. But more importantly, if you look in that migration for, do you see that there's a new migration file that reflects that last night? Great. So we just added Right on, then that's step one. Step two or well, that will be Step two. Step one will be making a modification. Step two is adding the migration on toe finally, albeit the database security update on Dash database, and you can actually just for stop the auto complete statement and then you press enter on . Then he will once again build the project on def. All is well, then you'll see success messages on. Then the ultimate show of success is going back to the database, refreshing the data objects on, then looking and verifying that the new fields have been added to the respective tables. So I'm going into tables going into leave types, drilling down into columns on. Then you see default days that has been a bit successfully on just the same way for leave allocations. You will see that there is a new field called period. Also, the court file for the migration may have opened for you where they're showing all off the modifications that terrible to me. So you mean you can spend time toe, you know, appreciate this, but it's usually generated for you on If it's error free, then you really have no problem. So I can delete that the next the next few changes I want to make, um, are surrounding the view models. So remember that view models are literally modeling the data class. We can add and remove feels as we see fit. But for the leaf type V. M. Right? No, I need to make sure that I have representation for default days, and I have to also make sure that it is required someone to say required I'm going to put in the property on I just wrote proper and press stopped twice into default days. Remember that year you need to match the case on much the name so that automobile maps cleanly on. I'm also going to put in some other validations like I'm going to set another data annotation on, and I'm going to call it range. So range is basically allowing me to validate a numeric field, and it takes ah many moment of maximum. So the minimum is one, but it doesn't make sense. The other leave type with zero D's on the maximum is maybe Oh, no. There's should be no leave type that exceeds 25 days. All right, so I mean, you can put that in. You can use that with a grain of salt based on the business rules and whatever, um, guidelines you've been given by the business off course. You have to manage it accordingly on. Then I'm going to set on air a message meaning so the error message no will be what is displayed when this ranges violated. So the error message is Please enter. Ah, valued number. All right, So when that ranges, you know, violated that those rules, then you will see the message. Please enter a valid number. So that's the leaf type VM and then just the same way for the leave allocation off. Also, I want to put a proper display name surround notices, default days as a camera case thing. So I'm going to put in a display on the name on then the text that I want displayed is default number off these. So default number off. These is seeing what is You know what? This is just the label that will be printed on the form that leave type Veum is used on on the leave allocation. VM already have a few things here. Um, someone to be modifying this. Leave allocation v m. I would have created it with a particular thing in mind, but I'm going to be modifying it. But in light of what we're doing, I'm going to make the following mods first before number off days I am going toe. All right, well, I'll get back to that. So I'm going to remove the required tug Onda. I'm also going to add ah, property four period I Once again, P road represents that calendar year. That's the allocation is valid. Four. All right, so we've made some minor march. I can build this project and then we'll see if that we have any issues with the modifications that we've made so far on based on the old put message and see that it succeeded. So I have no errors. And so we're finished with any database updates, at least for no. So in the next video will start designing the view
31. Leave Allocation Module - Create View: Hey guys, in this video, we're going to be creating on setting up the functionality that is required to support or leave allocation. However, before I get into all of that, I'm just going to make a few modifications to some existing code, namely the views that are there supporting the crowd operations for leave types. No, if you recall, we just put in a new field in the leave types, and that was for the default number off days on. What I want to do is is reflect this new value. So I updated the view model, updated the data class and the database and everything. But we need to actually show this value toe the user. So if I go back to the existing views on this is you know, you can do this in two ways, you can either try to regenerate all of the views, which to me is kind off, you know, tedious. Every time you make a change, it after region eri the view or you can just learn to modify it. So if you have an appreciation for whole, the court is an interview that he can just modify because you modified your view model. You have new data need to display of data you want to remove. If you just know how to change the visual component, which is the view, then you can, you know, flex a bit more easily. So with all that said, I'm starting with the index speed. So I want on the list. Are unaware Alicia in the name on the dates that the leaf type was created. Personally, I think we can do without the date created. I user who goes to view the list off. Leave taxes? No, when doesn't need to know when the lead type was created, however, the default number of this could be useful. So what I'll do is replace that field with default is all right. So then we're going to get the display name for name, which we didn't put any better notation for that. So it's just going to see name on. They will get the display name for default. These and I just go back on double, check the view model and make sure that I'm spilling red. Gets default name before this Sorry camel cased that's correct on. Then we'll have the display for on instead of displaying the big create that I will display the default days on everything else can remain the same. So are our data table for leaf types. Just goingto have the name on the default number off days for that leave type? No. In the same way, I need to show it on the edit because right now are it is it's keeping the date created and the the idea. It's hiding them, Sure, but I need a way that they can actually make a change, right? Especially since this is after the fact. Because we just added this. So that means thankfully, we have only created three. We can go back and just edit the three on Put in the new feel that is there, that's is required. So I'm just going to if copy this section that gives us the text box on, understand to paste it on, they don't want to say it's before the four days instead. All right, on, then, everything that said name. I'm just going to make it see before this. All right, so now we have two text boxes. One for the name, one for the default days. Everything Iskander me in the same. I'll go over to details on for the details. I can retain the date created cause I mean, those that would be a detail. So I'm just going to copy all off the big created bit paste. It's on duplicating that. But I'm going to change one off them out to default days. So you see, making modifications is relatively easy. I mean, you have the framework, you know, the value want to display. You have the access to the model on the model, gives you access to everything that was inside off the view model class that you would have defined. So I'm going to see of that. And then the final modification I'm going to make is on the create on this modification is very similar to the edit. So I already did it on the edit at the edits and create actually are identical. So I'm just going to copy that on, pieced it in the create on dso when we're creating a leaf type, we have the name on the default is that we need to provide and we need to provide both because both are tugged as required. All right, so with those modifications made have gone into the application. And no, I'm looking at my inexperience. I'm seeing everybody is at zero. Well, it's going to be here because when the database was updated, Andi annul value. It was not a load. Then we had to put in. It's hard to put in a default value, which is zero. So once again, we already said that zero isn't an acceptable value in practicality. So from the user side, we would have added the validation the range to see 1 to 25. But from the database, you know, that's that's a client side or that's the user interface side of validation. What happens in the database can be a different story. Anyhow. We would have added the functionality toe edit someone to just click middle Bun. The edit for these tool for vacation, even sick leave test is irrelevant. Someone to actually test right? No press delete. Click OK on, then that will do its thing. But I'm going to go over to edit for number of days and notice because the number I'm getting that number picker I would actually coat. It's telling me I need to enter a valid number so it's really validating that the number has to make sense. So we did say 10 was, Ah, good enough value for sick leaves. Save changes on dime went to go over to the other. Edit on vacation leave Let's say that the standard number off days in this organization is 15. So by making it model it like this, you know, every organization can go and set their own default days according to their business rules . It's understand toe close the excess windows. And then there we go. So let me just refresh this one more time to reflect actual values away of 10 and were 15. And then when we go to create new, we get name and before there. So I'm going to call this on maternity leave on the default number off this for maternity leave is what did we set as the marks 25. So let's say 25. That's about five weeks. It might be more than that so he can see no, that my validation may need to be adjusted because if it's 50 days in an organization and this clearly can't be 25 and based on my validation, 50 is not a valid number. So you know, you would have to feel their application according to whatever business rules you're using or you're adhering to someone to create this new leave type on DNO. We have three leafed types were maternity leave. We have sick leave on. We have vacation leave, All right, so not that we're don't making modifications. Toe are leaf types. Let's work with that's focus. Sorry on creating the view for the allocation. So the first thing I'm going to do is create the controller for the leave allocation someone toe under stopping this because I do want to retire. It's I'm going to crack controllers Goto add controller. We're going to create that NBC controls reader at Action Slick ad when to call its leave allocation controller and we click add Once we have the controller, then I'm going to just do my regular dependency injection by including our mop er on gone over our leaf type people as well as our leave allocation report. So just the expedite, its understand to go over to leave types on. Then I'm going to borrow. So firstly, I'm with the bar this authorized because, well, that's actually standard, So we should have. The author is above the controller. Remember that we're authorizing on the administrators to interact with anything in this controller on. Then I'm restaurant to take these references on. Then I'm going to add them at the top of the controller on then just using my control dot Add any missing references. So have the leave type repository and I'll call the swan. Ive re pull on going to duplicate that on going to call this one. I leave allocation, some referencing the I leave allocation repository on this one is leave I location report. So I'm really just showing you the fact that you can have multiple repositories inside one controller. It's not necessarily that if the controller is called for a certain thing, then you can only use do operations for that because I'm going to get leave types involved and I'm going to be making changes on the leave allocation table also. And so any both repositories. So I'm just, you know, setting up the controller on the constructor here on dis changing all the objects. So I have representation off the leaf type repository on the leave allocation repository. So I mean, I'm not talking through these changes. I'm trying to do them sold enough that you can see what is happening, and they're fairly straightforward. It's really just copy and paste. And I'm literally just adding one line toe the repositories that were already reference from belief types on. If I had the one line in the in the declaration here, then I'm adding that one land to the to the constructor on then off course out to make representation for it in the body. So I'm not fixing the red lines. It I'm just changing out the quarter references first. So on the score leave report is going to be equal to leave. Report. Here we have on the score. Leave allocation, re pull being equal to leave allocation. Ripple on DMA. Per is happy camper. We don't have to change anything about my upper. All right, um, you go. So it's underscore coming from the reference from the declaration must be equal toe the one without underscore coming from the con instructor. And then I went to change the constructor name. Of course, Toe actually say leave allocation controller. So that's our constructor. I just drove it out into different lines instead of having one long line running on on. Then I'm just going to use my control docked on reference anything that is missing. So we need to reference my upper on no order is restored our universe. So we have all of four. Dependence is, at least for no. All right on then, for the index page, the index pages really just going to load all the leaf types like I said. But I'm going to put a little twist to it on the view side. All right, so I'm literally just going to copy this school because that's what I want on. Understand the pieced it. All right, so and then, Obviously it's not report, so it's leave report that we're going to call to find all the leaf types on. Then I'm going to make reference to the leaf. The better class using control dot on also leave the View model control dot include those references. I can remove this line about returning the view, so I'm getting all the leaf types and then I'm storing them in the model, having mapped them on. Then I'm going to create the view someone toe rightly you click at view, find the template which is list because I really wanted to be a list on. I'm going to use the leaf type V m. So I just find the leaf that VM had want this data context class. I'm clearing that out, not referencing script libraries on DA Just think ad. So what we're going to do is modify this template, right? So I'm going to take out this create because I really don't need this. I'm going to take out the I. D column as well as the the default days and it created. I really don't need those. So this is I did allude to the fact that we can have multiple view models used for different things. They see if we had built a view model specifically for this than this modification would be necessary because I could have generated this view based on that field bottle without the addition off years. But it is what it is, Andi. I mean, it's it's really six of 1/2 dozen off the other. We could have done the view model and put in the world. There are were just put in the work here so we're just removing all off the facts. So what I really want is just the same table listing each leaf type on. Then I'm goingto leave one action buttons I'm taking on all of these on. I'm just going to leave one on the purpose off. This Barton is toe. I'm going to put the text. So this is Ah Reza on html tag helper here. Right, So it's giving us an action link. This is the text I'm going to say Allocate toe employees. Andi, I want to say set leave as action I wanted to call on then the parameter to be passed in will be on I'll take all the comments. It will be an i d on the i d to be passed in will be I TEM that i d. So I tend that ideas coming from model on. Remember that our model is based on a list off leave type VM. So for each leaf type, we're going toe bind that I d to this button. So when we click this button, it's going to see Call it saying this. This is what is sprinting to the screen. What is going toe call that Controller Andi, It's going to pass in that value called idee Onda. We do what we need to do inside off the controller or really, the actions. It's calling that action. Sorry. So back in our leave allocation controller Ah, we can actually create a model, uh, custom auction. Right? So we generated one with a bunch of options, right? All of these, the Kurd ones are generated, but I can actually just create one second literally just right public because I want an action that, you know, it has a specific name, and it probably does something specific that the others don't do. Some calling it sit, leave. All right on then. Set leave is designed to take on int parameter called I d. All right. So I'm actually just going to paint a picture for you on then I'm going to show you why I'm going to create another view model and why it's always a good idea. So I actually want a view model that is going to say the number off records that would have been updated after this operation runs. It would be nice if I just load up that view model returned the same view as well as the value. So I went to go back on. Then I'm going to go to leave allocation v M Onda. I'm going to call this one, so I'm going to create a new public class on. I'm going to call it create. Leave our location VM on. Then this one is going toe. Have ah property broke off. Time in on is going to say number updated on then this. It's also going tohave. Ah, list off leaf type V EMS. Right. So it's going to say public leave VM on. This is going to be list off leaf type VM. So now we're going to make some modifications otherwise So. Ah, what we're going to do Know that we have that knew what? This This is the view model that is going to be used. What I'm going to do is modify the existing controller court. So here we got the leaf time v ems, and then I said the model is equal toe this. Understand? To say, uh, mapped leave types is equal toe the list off leaf type to leave that vehemence. Remember that we're loading the model to be the least off Lyft IBM school from the database . No, I'm just making it another variable on. Then I'm going to declare the real model to be equal to Onda. I'm going to set this mother to be equal to a new object. Off type, Create leave allocation VM All right, on, then. Leave allocation. Veum has two properties. One is leave type on. I should call it leave types because it's a list. So it's relief type, So All right, I like I like to be very clear with my labels, and the variables are in, so leave types is equal to mopped leaf tax. All right, Several belief types is a list off leaf type VM. So we're getting the leaf Times from the database were mapping them from the data class to the View model class, which is what is being referenced instead of inside off the view model we just created. And then what I'm doing is passing that view model are creating on instance of this you model, giving it the default value off what's coming from the database. Onda, I'm going to set number updated to be equal to zero. All right, on that takes no cynical answer that cynical incomes after the breeze on, then I'm going to return view with model. So my view was already generated to be a list on its inheriting the type Lyft I V. M. And it's all the stuff that so I'm going to have to make some modifications. Otherwise, they're going to be data mismatches. So firstly, model can't be on innumerable off type leave type VM. It has to be one instance off creates leave allocation. So I'm just going to remove the innumerable keyword as well as angle brackets. On. I Want to Change is to leave type, so I create Leave allocation VM once I don't. Once I do that, you're going to see a bunch off errors. So, no, I'm goingto have to modify where it's looking for this list because it's looking at the model. So this time since the model is create leave allocation VM, the list needs to come from the property, someone to say that leave types. So once again, I created a new view view model called Create Leave Allocation Veum, which contains the list off view types as well as another property and as many other properties as we medium necessary, but that's what it has on. Then it's going to be the the it's going to be the model for our index page. But then, for our listing were using that list inside off that model. So inside off model, I'm actually what I'm going to do. Just remove this. I don't need to list the name off the view. Leave types understand to read the static text leave types. So leave types is not really the focal point it. So I'm just listing leave taps. I just have a table with a column that's his leave types on another column that's is maybe as action here and then inside off the actual rose. I'm going to have the name off the leaf type as well as the action button, which is the Allocate Toe Employees on its calling. The action set leave passing in the entire middle off I d. So back in the controller we can start building or what or set leave. Former Sun is really going to do so when are certainly function comes first, then we need to find the leaf type. That was quick. So we're passing in the I D off the leaf types. I'm going to save our leave type is equal to And then I'll call my leave report, which is called a lift as a really should call it leave type report. But I'm going to find by i d. And then I passed in that I devalue. So no, I have the leaf type. My next objective is to set the number off disassociated with this leave type toe each employee that is in the system, someone to save ire employees equal on. Then I'm know, going to see that I need another dependence because to get the employees which are really users, there is, ah, library or function built into identity. Call the user manager, right. I would have looked at the user manager when we were looking at seeding the date, and I just go about their quickly and we see here that we have user manager, so I'm actually just going toe quickly. Copy this on then. I'm goingto eat injected as a dependency in this project. So on Anethe mapper astride private read only. So I'm just showing it as you go along, you're going to realize all I need this or any this operation. And this is how you really go ahead on Put in the functionality because you can plan. But you'll never really assess every single scenario from the get go, so I'll just include that on. I'll do the same dependency injection putter, and we're I'm going to make reference to it. Our declare it and then I'm going to call the instance inside off the controller Some this copying and pasting to expedite this process. Andi, you don't copy on peace really helps you see if time when, As long as you understand what you're doing, you don't have to spend much time reworking right. So now have user manager. I know I have the dependency. So I can know. Call the user manager object and say dot on then we have two times off users. We have those in the employee roll on. We have those in the ad minerals. I really just want employees, right? So I'm going to say user manager dot on then I can say get users in role so you see, get users in roll on, then inside off this function Call. It expects the role name as a string soc employees because that's the rule that I want on. Then I say dot on results. So after said Not result, actually get the list of employees and then this is returning and I list, which is just another type off lease. It's a collection off employees in the system. No, what I'm going to do, Know that have the leaf time that is in question and have the employees in question. I am no going to iterate through all the employees and set up the allocation accordingly. So for each employee that is here, I'm going to create on entry into the leave allocation on if you recall what our leave allocation object. Our data. Yeah, well, what it needs to look like is that this is also generated. We put in the number off days, which is coming from the leave type we put in the date created, which we determine from the controller. We referenced the employees by i d, which we're getting because we know of the collection off the employees, we have the leaf type I D on. We will determine the period, which is, if it's if the button is clicked to know the year it is clicked in is the period right? So what I'm going to do is see for each service road for each and pressed up twice, and it generated that. And then I can just say m in employees. So this is me no going through. I don't know how many employees are there, so I, for each is a nice quick lube to just go through from the first to the last without needing to know the number Right on. Then I'm going to see something like var. Location is equal to new, and I remember we don't want to use our data classes too often or at least at this stage, we use our view model and then we map somewhere to say new leave I location VM on, then use my curly braces to do the initialization. I'll just put the cynical under from no on on Then for the first object or first property I need. There's no particular artery After said these properties, you can do it in any quarter. So did created is going to be dead time not know comma next property employee I d Sowden set employees what I would say the I d right. So employee i d to be stored in the database will be empty dot on MPs coming from this object. So it's saying for each off this object in this collection off objects. So that means each time it runs, you can access that iterations data through that property, just in case you're not familiar with for each loops, so emp dot And then I can get the i d. All right, so I got that employees I d on then the leave type i d in question is equal toe I d. Because you know it coming in from the parameter. That's idea that we're dealing with. All right on then we go ahead and we see comma again. Number off days will be equal toe the default disassociated with the leaf type So we say leave type. That was earlier retrieved dots on. We say default is alright on. Then we c comma on which other property do we need to set? We also need to set period and then period would be the year so I can see something idea time I don't know. But then I only want the years I said not again and just retrieved the year value, which is indeed and in fact, an integer. Alright, no off course. If I press come again, you'll see that there are other properties. But the fact is these properties don't appear in the database. I don't have to set them. Even if I do set them, we're going to have to mop back to the data class and so they would get ignored anyway, So I leave those alone. So what this is doing once again is it is retrieving the leave type for which were sitting allocations. It is going to retrieve all the employees on. Then it's going to say for each employee, create an allocation. No, I'm already seeing a kind off gap in this logic because then if I click sickly five times, it's going to create five different sets off allocations for the same set off employees every time. So what I would want to do is kind of set on if statement, like a little control to say, OK, I got an employee or I have the collection on then for this employee, is there an allocation for this leave type for this period already if there is, then don't do anything otherwise continues. I can sit upon s statement inside off this and say something like, if and then here we can get creative. I can either go back into the leave allocation repository and set up Ah, full report function for that which I think would be preferred. So I'm I'm going to leave the if statement if statement is needed. But I was going to write you told here. But I think that the sea for we would be to just create the repository function Someone to go over to leave a location repository will First, I'm going to find the contract on leave, reports the allocation repository on. Then I'm going to see something like check. I look your son and then check allocation is going to take a perimeter off units, Leave type I D. Andi. It's also going to take an employee I d. And that would be as a string. So string employ e i d. Oh, and this return, that would be bullion. So it will be bullion. Check a location on then off course. If I do that in the interferes, then after implemented in the actual repository class, so I'll just implement interferes on. Then If I'm checking allocation, I need something to do with employees, which means I need to retrieve that employee. Well, I don't need use a manager. Actually, I really don't, so Oh, and I'm also going to pass in the period, so I'm going to see Well, no, I can't determine that on the fly. I can determine that on the fly. I'm sorry. There's so many ways to do this thing that hit. I'm thinking out loud. So here's what I'm going to do. So for this function on, I'm taking on interns relieve type I D and a string employee I d. All right, so inside here, I'm going to save our period is equal toe the time Don't know Doc's year. So as the function is called, I know what Pierre and we're working with. Then I'm going to see return on, then I can call one function that is already here, which is maybe find also find all is already going to run the quarry to get all the leave allocations in the system dots on. Then I can see we're someone to create a lambda expressions. So this find all function is returning a collection or wherever you're returning a collection with its A list on Mary, you can use Lambda Expressions to filter it somewhere to see where q docked on going to check if the employee I d. Is equal to the one that's coming in. So if the employee idea in that record is equal to the incoming employee, I d. All right on, then I can create multiple conditions on board. So where this employee I d in the record is equal to the incoming one. Andi, the leaf type from the records Acuna leave type I D. Is equal to the leaf type I d coming in from our perimeter Onda. Once again the period you dot period is equalled toe the period that we just set above this line right on my left off unequal side here some seeing find all. So I'm getting all the leave allocations, but I want all of them were These conditions are met that the employee idea exists with that leaf type I d in that period. And then the red line is there because this is returning a collection that meets those criteria are that criterion. So my function is expecting a bull. So then I can just say dot any so that any is just going to say, Is there anything in this collection? Yes or no? That's all I really want. So filter of the collection, and then tell me if you got any records. So then we just returned yes or no for that operation. All right. So there, there will, could ever in this in multiple lines. But I'm just showing you the po off lambda expressions and I'll desperate the land that each full stop so you can see it, you know, kind of more defined. All right, so with the were we can have as many aunts on, just like all your readiness team with Anson. Or you can do that with that. Were statement there. So then we're chicken. The allocation someone to see this and then go back to our controller somewhere to close anything that is not absolutely necessary. So back in the control and went to see if on that I want to say leave allocation report docked. Check allocation on then, for the Cheka location. I'm passing in the leaf type I d which is coming in through the parameters I d on then I'm also going to pass in imp dot i d as user or the employees I d on. Then I'm seeing if this is true, then I want to break. That is inaccurate, actually want to continue so brief would terminate the loop. What continue would just say Skip this iteration. So if there is an allocation for this leave I d on this employee on were pre determining that this operation is only going to be run during a particular period. Then we're just going toe skip that iteration. If it comes back on this condition is not met, then it will go ahead on and create the leave allocation object. Then we need toe muppet someone to save our leave. A location is equal to, and then we call our mapper dots mop on. Then we can actually just mop and see the destination object. So we're mapping to the destination object off. Leave a location. The data class on the object that were mapping in that direction is a location. All right, so I mean way have done quite a few things here this can be. I hope you've been paying attention. If you have any difficulty along the way, feel free to reach out to me, help you. But, you know, this is kind of what goes into when you're building. These enterprise systems have toe called for these different scenarios on you have to be flexible because anything can change in the business of criminal can change on relentlessly business requirements and business rules are literally just a bunch of four loops and a bunch off. If statements at the right places, that's what you get. The results you need on even after that year court may still not be as perfect as you need it to be. All right, So once again, um um, Iterating through all the employees checking if they already have an allocation for the period on if they don't stand, we build an object off the view model type. Then we map the object to the data class on. Then we save. No, we don't say sorry, we add. So I say, leave a location report, create on. Then I am going toe pass the leave allocation object in some creating that leave allocation all right, and then, after all of those creations are doing so, it's going to create for each employee. It's creating those allocations. Ultimately, all this needs is a direction to go in, whether it's going to return a view or it's just going to redirect to index some actually just ventilated Redirected Index. And I'll borrow the court from our leave types controller. We see that you can to say, Redirect the option on you can give it a name. Someone toe. Copy this on. I'm going to see Redirect to index. Now, What I didn't do was update the number updated, and I'm going to actually challenge you to do that. So I'm going to do it on. I'll provide the source code. But I'm challenging you toe do that where you're going to take a tally off home many times this Lupron pretty much on then added to the model. And then when you redirect, you passed in that model object in index on. Then you display that number on the index speech, so that sounds like a mouthful. But I think we did the bulk off the hard work in this video. Once again, we added a bunch off business logic to the actual off. Ah, location. There is more logic that we could add where we could on a case by case basis, determined whole along This employee has been with the organization. Um, because we do have a joint object inside off our employees object, which on that would actually require a bit more modification. But I don't want overwhelmed with too much. One time this has been quiet and activity. So in this activity we looked at using more than one repositories. Our dependence is inside off. Articular controller, we looked at creating a custom view model on. We looked at modifying a page to do exactly what we want. So as a final act, we're just going to go into de boat moored on the test Our new feature. Someone said a quick, ah, break point this the action and then we're going to test our application. Someone's going to leave allocations. Oh, I need to set up and you just set the links all and I'm going to set the link inside of the Lord someone to get out off debug moored. Go back to the solution, find the shared view. The layout on for that linked to leave allocations, understand to copy on existing one on, then paste it here on. Then this controller is Leave a low key Sean. Leave allocation, not leave allocations. Software seeming to be very careful with this spring. So let's go back into debug mode and Australia. All right, StarLink work. So you see that we can do some refinement, right? We've been adding, you know, some bootstraps style starling so could add some styles and take off that bar that pipe. But I leave that for later. I leave you to beautify your page, but more importantly, when you're over over the link you see in the bottom left hand corner, it's calling set leave or set cars that leave with the leave type I D. As a parameter, right? So then, for sick leave, um, with a click, Allocator employees, and then resisted is lighting up because it hit the break point on. Then it's getting the idea. Someone toe skip ahead to Lyon 54 at which point it begins the for each loop aan den. It's getting all the employees. I'm just went over over the employees objects. They see that we are three employees. So these are the three users that are in the employee role in the database. All right, on, it's already got the leave type on all the details and needs for that leaf type, which would be the default. Is etcetera, etcetera on dime, actually, just going toe. Put a break point at the part where it's about to create the leaf type. So I'm just going to remove the first break point and press five so that it continues on. Then the 1st 1 that would get a Did you see here the leave allocation object was created on it has the employee i D. It has the leaf type i d. The number off days and the period of 2020 on also the date created. Once again, they're going to be no values because the data class itself has the employee object as well as the leaf type object There on. Later on, you see the purpose off them before No. In the database, there's no employees, and there's no leaf that what we do have the ideas returned, database someone to press F five and he's going to run through again, and then it went through that cycle once more and it did its check on. It's going to build the other one. So since I only have three, I'm going to move that break point and set it to the return press F five. And so it's about to return on. Let it do that on. Then it returns to the index. So obviously we need some visual cue to say, Oh, this operation was completed successfully. We can probably make it into a nice Ajax call where it, you know, it shows up a nice message afterwards. But I'm not getting into the all of that in this lesson. What I want to do is verify that these records were actually created on. So when I go to the Esco server objects on, then right click my leave allocation stable and few data. The expectation is that I'm going to see leave allocation records showing up for these employees. So you see here everybody got 10 days for leave. I'd be type two for the period of 2020. Now, remember that we set up some logic to say that this should never repeat meaning If I click toe allocate, leave, type I d for leaf type two again. If they already exist in the table for 2020 then they shouldn't appear again or they shouldn't get at it again. So I'm going to just test that and I'm going to click that and you see, it went it called the control and everything. But I'm going toe skip the break point and let it re load index on. Then the proof that it didn't do it is in the database. If I refresh and rear on that select quarry, there should be no duplications. And there we go. All right, on then, if I do that for another leaf type, which is vacation Allocator employees. When I go back and refresh know we'll see, the employees know, got their vacation days for the period of 2020. All right, so that's a nice we off, you know, mixing matching and manipulating the court and whatever framework your given to your purpose. Once again, I don't want my videos or my lessons to be mindless court along court along videos. I want you to have an appreciation for why we're doing what we're doing on as we build this application together that you will grow from strength to strength and from knowledge knowledge. So stay tuned for the next lesson where we'll be setting up a view where the admin user can click on an employee. Onda change the value. So let's say, for instance, some employees shouldn't have gotten 15 days. Or they should have one fewer than 15 days, even though everything was set to 15 for vacation Lee for that period, or for the period of 2020 that they should really only have 10 days, right? So we'll be setting up a view where the administrator can go on dsi the allocation, change the value and meet at a bit.
32. Leave Allocation Module - Employee Listing: Hey, guys, in this lesson, we will be continuing our leave allocation model on what we'll be doing is setting up the override views or the over add functionality, meaning we should allow the admin user to view the employee, view the allocations and edit the allocation on a you know, an individual basis when needed. So we're going to put in some work our own putting in that functionality. But before I continue with that, I just want toe bring present to you the modifications that I mean to the screen. The last time we did this leave allocation screen, all that was there was just the link toe. The lee, the Allocator employees will no. You can see that it's a green button. At least it becomes green when I hover. So what I did was added the bootstrap class, and I also added the five icon or the front Awesome. Sorry I couldn't toe the button for that pencil. I'm just sharing the court modifications that I mean, the original cord would have been an each day emailing our helper. So we have the estimate helpers, and then we can off have the ability to write more native HTML with a few, you know, tug helpers along the way. So I'm going to just comparison so you can see exactly what either one was able to accomplish. No for the action link we would have already had upto this much. What I did was Atacama on DSI new again on then start up a new section in that action link block off court and add a class notice. The at sign classes equal toe and then I was able to add the bull shop class. This would have given the green button, and that's fine. But then I wanted the pencil in it and there would have been some limitations using the action link that was generated for us. So I just change. It ought to the corresponding anchor tag looking court where we have the same Well, it's an uncle attack that's giving us a link. We put in the same classes, the Bt in, but the summer use Bt and dash outlined dash success. So that's why it's you know it's white until you hover over it. It becomes green, right? So that's Bt and dash outlined, dash successful. So for each of the buttons with this success The injured primary you have on Oland Alternative. So if you don't want to decide colic and use the old line and then I have the SP action which is set leave notice that would have corresponded with what we had in the action section off for the action link on then have SP dash Road Dash i D, which is the roading value that needs to be passed into the set Leave action for it to compute track on that would have been depicted here where we said new andan in section ideas equal to act him That s so It's really the same court. Except I was able to insert that I tug for that icon passing in the fund awesome classes that are needed for that pencil. So this is a side by side comparison off. What either cold would have yielded one would have yielded the solid green and the solid green would be the action. Lincoln notice it has no pencil I'm granted. I could have gotten it to look at the online if I wanted to, but the fact is, I couldn't get that fund Awesome icon in there and then This is what I did to get that fund . Awesome icon. All right, so I mean, I'm just showing you in case you wanted to try it yourself. No. Like I said for this morning, what we're going to be doing is sitting up view for the employees a list off employees in the company on. Then they'll be able to view the allocations that that particular employee has on then and it if Mrs or even delete. Now for this morning. I'm going back to my leave allocation controller Onda, continue on the same vein. We're not just going to use the default actions that were generated, but we're going to be creating a lot off our own actions that accomplished what we want. So the next action would be toe set up a view for the list off employees. Right? So I'm going to create a new action on, then I'm going to see action. Well, I'm going to create action by seeing public action results on. Then I'm going to call this one list employees and then list employees is literally going to do that. List the employees, right? So to get the employees, I'm going to save our employees is equal to Andi to get the employees in the system. I'm just going to reuse this court appears I can literally to state this line because I'm going to be using it again. All right, so you see that a lot of court gets repeated along the way, But then, based on the way you write that you can modify it one or a few times based on your architecture. So using the repository pattern he sees just was for us to maintain the underlying code and just repeat the references to the cord, making modifications and maintenance easier along the way. So we have our employees equal to the user manager, returning all the users in the employee rule on. Then what we want to do is mop these someone to save our model is equal to, and then we're going to see him Oper docked and mop on. Then I can just say I want to mop toe this model types. I can see a list on, then open up the list tag were put in the type and the type here is employees the M. So we made the view model just for the employees on. Then I'm going to be passing in the value employees. So once again, I'm worrying for all the employees in that rule on. Then I'm just mopping them to my view model class on. Then I'm going to return the view with model being passed in and then close that. So when this action is called, it's going to bring up all what is going to choir for all the employees on dmat them to the view model. So I'm with generate of, you know, called list employees, and I spelt employees wrongly here so that employees All right, so I right Click view goto ad view on going to choose the model. The template list. The model class is going to be employees VM on then. Typically, when we're using view models, we really don't need the data context class so we can clear that out on. Then I'll click add. So in our views created, we can make minor adjustments. We can put the space for list employees at this stage. I don't want anybody to be able to create an employee, someone to remove reference toe that link on that I can just refine the headers for the table, so I don't want i d I don't want Well, for our context are the So far I have been using user name and email as the same thing. They have the same value, so I don't need both, but you can retain both, but I don't need both. So what I really wonder at least is the email. I don't need a full number to be listed in the list. Maybe I can beat an employee's details, but I do on first name and last name and actually want that before I see the emails, I'm just rearranging my headers for the table as I see fit. Right. Um and I don't need to see the tax I d the date of birth and I can leave the date joined. Well, I can leave it. I can dig it off. I'm going to take it off, actually. So I'm really just expecting to see the first name, last name and email address off the employees. So, of course, if I rarely is the headers, then I really need to rearrange the hero or the columns in the rules that are being generated on the fly, so they need to line up for it to make sense. So I'm removing what is not relevant to be I d. User name Took off one too many lines. Of course, There on, we want first name and last name above the email address a move those there on then everything underneath email address up until the action column is deemed surplus. So then, for the action links the actions of time permitting at this right now involved viewing maybe the details off this employee. So I'm going to kind off bolster. No. So when they click on the details link, they are going to see all of the information for that. Employees. You know all of those additional balm, bits off information that we just took out about employees. They're all going to be listed there, as well as all off the leave allocations for that employees. So I don't want them to be able to edit someone to take that oath. And I don't want anybody to delete for sure on. I'll just move that bar on. Then, like I said, So I want to meet. My details wouldn't look similar. Toe the Allocator employees button that I showed you at the start of the video. So all I'm going to do is go over to that page on, copy that chord and come back, paste it so I can just remove this, or I can commit to tote and control holding down control and person. Casey, that's a quickly to comment court. So I'm just going to modify this where the action this time is going to be. Details. Onda wrote, i d remains the same, which is the item that I d So remember that this is a four ritual going through each item in the model and model is a collection off employees based on the view model, um, theatre type red. So for each item, I'm just binding that particular I d with each employee toe this string. All right, I'm going to change this. So it is view. Details are can just be details. All right, on the pen. So I don't want a pencil. Instead, I would probably go with the search button. So the artist search icon rather So search. Alright, so f a that search. No, I don't I didn't memorize these. Whenever I need something, I just go back to the the documentation and find one that fits what I want. So that matter that's going to give us, like a little magnifying glass button. So the next thing I'm going to do is I'm going to bind in the layer. PH I have, ah link here for employees so manage and employees. I'm going to set up that controller on day action when to set up those attributes. I'm just going to remove each F on. Then the controller would be leave allocation on the action this time would be list employees. So when I click employees, it's let's go to list employees. I'm doing this right. No, later on, we can refine it. But I'm doing that right now because I already have that many are item and I'm basically creating that functionality here. All right, on then. I'm also going to just meet this into a data table on to make it into a data table. I just look back at what I did with leave types. Some want to go over there, made the i d. T. B of the data. So I'm just copying this. So you see, when you do it one time. If you remember that you did it. You just need to go in a reference the court that you've already worked on Andi just you know, um, it's already there. Say, just make use of it. So Oh, yes, I already included that script that changes anything with the i d. T. B O data into a data table. So literally, that's all I needed to do because of whole effort in the court just at the I d equals tibia data. Now that I have done all of this, I'm going to execute or just go into my browser link, launch the browser on, then we're going to assess our changes so far. All right, so if you got an arrow Pidge, it's very because you already had Broza Link open serialize. It only supports one instance, so if you already have it open, then the second time it tries, it's going to feel. But either way, I have it open here already, so there's little manage employees on. Then we're going to get a little error, so that's just assess the era. And then I'll tell you exactly what's happening here. So first lied, saying that There's a mapping error between employees to employees. VM Andi There is some. So it's letting us know that there are configurations for employees and employees. Veum. Alright, But then, no, they're seeing later. Don't that there is so miss much between SB dot net core identity user. Andi Leave management up money Is that the M that employees VM More specifically, it's telling us that there is an issue mapping from the list off employees VM on door model employees. So let's go back to the court on Look at exactly what we missed. So if we go back to our list employees action on, we take a close look at the data types being returned, then we realize that bar employees, which is getting all the employees, is actually getting, ah, data time called Identity User. And if you recall Identity User is that based data type that dot net core has given us to represent any user in the system, right, So we're getting back identity user, but we're mapping toe employees VM and if we go back to our map ings, so I'm going to mopping solder and maps, and then we see here that we're not accounting for the employees VM mapping toe identity user But we're on the mapping to employees know a number of things that play. And I'm just going to explain this because we're going to make some modifications and I'll explain everything as we go along with employees. Recall that the Data Class employees and I'm just holding on control and clicking, so it's going to jump to the class it is inheriting from identity user. So then you're probably seeing okay, So if it's inheriting from identity user on, we used it interchangeably in the plot in the past. Why is it such an issue? No. Well, when we initialized over identity functionality in our application, we would have initialized it with identity user and not employees. So if we look very closely at the data that comes back when we do on operation, like just go back to the controller like getting all the employees are all the users in the rule on its returning on the identity user, it means it's returning everything except the first name on the last name, and the date joined on the tax i D, which are all things that we subsequently added by adding or employee data class. So in other words, when used data when use, use a manager, right? No, because it was initialized to be used with identity user. None off these fields will come back, which is a problem for our list employees, because we are trying to list the first name, the last name and email. And it's a bigger problem because we're not accounting for mapping identity user to any view model employee VM. So this is going to spark a bit of refractory in our cord on its only natural, because you would start off with the default. But then you want more on. You need to understand and appreciate the changes that you need to make toe facilitate the more so in smaller words upon to know, using just identity user was perfectly fine onto we realize that we needed toe see the additional data, which is in the employee class. So what we need to do is initialize over identity functionality from, or start up Nazi s file. Using our employee data class on it will completely accepted, because employees, as a data class, is already embodying everything that is inside identity user on then some. All right on what we're interested in right now is that and then some because we have everything identities there already. So I'm going to take a step by step. It's still what changes need to happen, so I'm firstly going to disrupt the status school on I'm going to change identity User. So in services that add default identity, I'm changing identity user toe employees on then for every other instance off. Some initialization are some allusion toe identity user. I needed to see employees, some just copying this on then below. Remember that we had user manager and roll manager will use their manager more specifically . User manager. No need sto use employees in the sea Data We're going to get an era because it knows about identity users understand toe hold on control. Click on that function. Jump over to that on then, everywhere that identity user waas I'm just going to start replacing with employees all right, fending off course if it's not already included, which it wouldn't be, I'm just going to use control docked on allow it to include the reference No, we could do this one by one, but it's going to get very tedious on. Okay, So, as as I replaced employees here than to other lands appeared because it's expecting employees. But I'm adding Vier new identity users. I need to add vier new employees on by seeing employees. This opens me up the ad all off the other fields that I mean not have been able to add, because I was only using evidence to user. Remember when we're modifying our destruction Page were adding on employee class. I'm not the identity user class because we wanted the additional fields or first name. Last name is etcetera. So no, I need to be sure that everywhere in my project that had user manager are are signing manager referencing Identity user No references, employees. And the reason for that massive change across the application is that we're initializing it with employees, so there can't be a miss much if we're referencing something with identity on. We're not using identity relative to the employee class. So an example of where that maybe phoned, is the log in fire show where we're using identity. Sure, but then you know, to signing manager and user manager there still referencing identity user, so those need to be changed. Employee employees I think I just did a control build. All right, Good. So employees again. And then the red line means that I need to add the at sign using Leave management. So that's a project name dot data. So that's the name speaks, right? That's the library or the folder. In this project. They can go toe to see where that class is. So for everywhere that is using Identity User, I needed to see employees pretty much so. A good way to do that is holding the uncontrolled pressing F which brings up the control find that's a fine option I can expand this on. Then what I'm going to search for is identity user on. Then I can see replace with the word employees. No, this is not going to fix everything, because then we still have to go through and fix the references. But I'm still going to do it because it makes it much quicker. At was where I'm sure we don't remember every single place, especially like oh, we would have scuffled at a bunch off views for the identity stuff on all of the marches and the default identity use. Or so by doing it this way, it will go through the entire project rent. Or is this current document I can expand that under current project on then? I mean, if you want to be very prudent, you can replace next so you can do them one by one. So obviously would replace this one. Because employee needs the this. If there's one place identity user needs to be referenced, it is their right. So I can skip that one just they find next. And then it was search on. Then it will land inside the leave a location controller where we had initialized user manager with Identity user. So I can just go ahead Onda replace. So I'm just going to replace one by one just so you can see and then it goes right back. So I'm just going to do I replace all to expedite this, but there's going to be some damage control that we're going to have to do some Justin toe See, replace all Andi. This is saying that if you if you do this if you take this box, then you'll be ableto under the changes in the individual off as if it was undesirable. I'm not going to take it on. I want to just say yes. It will just go through the entire project on replace every incense off identity user with employees, including the war very one that we're trying to avoid. But we're already there, some just into identity User. All right, so that one is restored. But then when I do a build, we're going to find that they're going to be a bunch of errors because, no, there's a new class named employees in a bunch of files on there is no real reference. And we have 71 errors. So we're not to fret about the 71 because a lot of these errors are in the sea and file. So I'm going to just double click each error. It goes directly to the error on Dhere. I can just tell you that we just need to add the at sign using leave management, not data line. All right, so we do that and I'm actually just going to copy this line because I can guarantee you that that line is going to be necessary in a bunch of other files. So I did one on No, we're don't from 71 eras toe over so lets him to one errors. So I just double click on Then I just go through each one. So if it's ah class filed, then I can use the same using statement. I just don't need the at sign right under semi Colon. Andi, I'm just going to somewhere do this someone to do a few more, but I want you to do it on your own. I don't want to worry to death with this video sake and pause the video on. Continue to do it on your own. You already have to do is go to the era list and you see where commando Nice. They were at 65. So this is quoting this is you have about a bit of free work and a bit off re factoring that goes into courting sometimes on that's why I'm here. I'm here to show you the ugly side of coatings as well as a beautiful side of courting. So if it's a class file, we just based it and remove the at sign, put the semi colon on, then everybody is happy knowing that, Okay, Employees being accounted for. So you just keep on going back to that era realistic and even. I mean, it's so that it doesn't auto hide on. They just double click one by one each file and go through someone to pause. I'm going to do it myself on. You can pause a video and finish it up on your side. All right, so I got mine. Don't tow three errors, and that's in the manage now file. So, like I said, yes, would be number was big, but a lot of them were in the same file because they had multiple references on each reference that was not being accounted for was an aerosol and went to do inside. Managed enough is at the top of the fire. Put in the using statement with the at sign on, then that parables away Onda. When I control shift in here again, I know get a successful build. So now that we've done that major major exercise, let us dragon. So I'm just going toe open up the Broza link once again because after you build pretty much Brazilian gets disabled, that's what they realize. So we just view in bro's er. All right, so I got this error on. Did I believe that this might be some issue with my DITA on not necessarily the project. So I'm in debug mode on what it's saying is that they can't inserts to off the same users. Apparently, I made some adjustments of those factoring in everything I did seem them. So what I want to do is stop and I just show you because you may have been counted it. If not, then you're fine. But I'm just going to quickly go into my SB Net user stable view data on Once again. This is very it has very little to nothing to do with what we just did. But it is saying that it can't have toe add mean users. For some reason, it is. It's a lot of the creation of two. So I'm going to take everything that's has the word at mean. So all three of those I'm just deleting those from my data. Sorry. All right. And then I went toe execute once again some way into debug mode, which the sea data should go ahead and create. And you admin user for me anyway. All right, So Or application loaded. Understand? To add blogging quickly, as the ad mean that's admin at local host. Be at Santa s s w o R d one. That's my password that I used. All right, So after fuel feel, let them serialized I'm a bit number. So I said I'd mean that local host. I did not put on the dot com, so I'm going to go through that again. But this time I won't. I won't waste your time with it, But just in case you're experiencing the same issue I am, I'm removing this admin user from the database once again on I'm still in keyboard. Most underscoring toe restarts. The application in debug mode on that should solve that log in problem. All right, so let's try that again. Andi. I am loved being excellence, and I'm going to go over to my employees view. Andi, I'm getting an error in visual studio, and the arrow is that the input string was not in a current format. Andi, I think I know exactly why. So what's happening here is a mapping exception where it is seeing that it sees two elements that look like they should be mapped. But there is some tight miss much, and it's studying or string, so I can tell you exactly what happened. I'm so I'm just going toe Stop! Get out off the boat mode. If you're not in countering this than accident, if you are, then that's that's fine. I'm going to walk you through what's happening. But remember that the employees I D is a string coming from the database. But then, in employee VM, hold on control and click. We have it defined as an int. So Autumn Oper through an exception because it seeing what I see that ideas in both classes But oneness String one is in. Something is wrong there, right? So I'm going to do that again, just going back into debug mode. Andi, we'll see what happens. All right, so I just went straight to the list employees speech on DNO. I'm seeing a page listing the employees so all of that hard work so we can finally get the full information on our users from our database, right? So once again, what we just went through was changing all over identity user references in our application . Um well, identity user reference the default class that came with the project. But we built a custom class to extend that default class on this custom plus had data points that we probably wanted to display on DSO. I brought those forward. All right, So what we did was to change all the references, the identity user to use employees instead. All right, on dso anywhere that we have the user manager or signing manager, we need to use the employee classes it off identity user on that will extend our capability toe toe access. The other data points in the user's table that I was part one off the modifications that we're making the part two. We're going to actually create that detailed view where we click on an employee. So we already have the view listing the employees and we have the search. We turned it into a data table. So as many employees are as an organization, we can search by name Andi. In a real life scenario, maybe every employee would have a unique i. D number relative to the company. So whatever it is, they would be able to search here on filter the tables on. Then they will be able to click details which will show us the details, the full profile off that employees as well as their leave allocations. So that is what we'll be working in in on in part two off this activity.
33. Leave Allocation Module - View Leave Allocation Per Employee: Hey, guys, welcome back in this. Listen, we're continuing on this is part two off or leave. Allocation on the matters will say slash employee management model build out. So in the previous lesson, we would have gone through making some adjustments so that we can get our list off employees in the system showing first name last name E mail on din. This lesson will be extending that capability. Noto actually activate the details page where we'll see the full employee profile as well as their allocations for the period that is in question. So I'm going to dive right into the court because we're not going to spend much time. We already have a good grasp of what we need to accomplish. Everything to make a few modifications and experience. I go along. So we're starting off with the leave A location VM So in our view model or in our models folder, we have the view leave allocation. The M class file on guy can leave everything as is, but I will remove the select lists. All right, so you know, sometimes you're fireman's change or the way you want to implement something changes. So your view models are where you go and make those quick changes to reflect our toe. You know, complement what it is you want to see on screen based on your current thought process. So I don't need a select list anymore, because the strategy I had when I created this view modern initially has changed. All right, so that's the leave allocation view model. But I'm also going to create another view model and I'm going to call it leave. Well, I'm going to call it view Allocations VM. So I'm going to create another class and I'm calling it view allocations VM on. Then this class is going toe have, ah, public entity off type employee VM. It's also just goingto have the employee I d in it, Onda. Finally, I'm going toe have a list off the leave allocations and then this list is going to be off type leave allocation vmc. Remember that we really don't want to use the data classes on our views that all we want to create view mothers. That's why they're there. They're literally models for the view. All right, so our data classes are models for database and view models are models for the view. So any of you that you are going to be creating our view model you want to make sure that you're referencing other view models if you if you need to. You don't reference employees directly. I know that I have this view, my view allocations VM I'm going to go back to my view. Leave allocation controller On this time, I'm going to be using one off the already generated actions on I'm going to be using details, right. So first them went to change. The apartments are from into string because remember that the expectation is that when they click the details for the employees faster the employee i d which we know is really a string and not an integer. So I'm just changing the data type for details from into to string on. Then we're going to start retrieving data. So the first thing I'm going to do is save our employees, is equal to on. Then I can use my user manager and see dots find by i d on its fine by i d a sink, bypassing the i D. Which is the employee I d coming through the parameter that much is that on? Because it's a think. I need the dot results. All right, so there to waste 100 racing functions you could either, you know, leave it as a sink without the doctor result. But then that would require me to change the entire action results into an easing. So we'll do that later on. We'll explore that boat for no, I'll just say that results. So I know that I'm getting back just on. Employees were getting back employees and not identity user once again because we changed all the default references from Identity user to employees in the previous lesson. So of our employees. So we have the employees on that. I'm going to teach our shark. Let's remember that we're really mopping. So whenever we get the data, we need to mop it to the view model, right? So I can actually do all of that in one line where I can just see I'll just put into space and say on the score, my upper not mop on. Then the function form up asks for a destination. So the destination for them up would be employees the M right on. Then the object that needs to be mopped toe employees. VM is the actual result off this off this query so I can do all of that in one line. So no, when I get back employees, when it's going to choir for employees, get employees, then do the mapping. And then my final object is off type employee VM already mopped with all the data I need. So I did all of that in one night and you don't is that we could've broken you talked into two lines like we've been doing upon to know Well, this is it in one line, reality is that there are many ways to write Accord and many ways to be efficient on still have in court. So know that I have employees. The next thing I want to do is create Well, it's retrieve all off the leave allocations for this employee in this period. So I'm just going to save our period once again on the Via Pier. It is going to be equal toe. We know it's the time that no, not a year. All right, so then I went to save our locations are equal to on day I went to run a query on the score . I think it's leave allocation. Ripple, there it is, docked on. I'm just going to find all so I can find all leave allocations I can find. I can probably go back into the repository and create a function to find all allocations by employees. As a matter of fact, I'm going to do it like that. So instead of calling, find all and then tryingto run a quarry on it at this level, what I'll do is just go back to the report, sister. And as I said, this is so your court evolves over time because sometimes you just think off what is something that I may need to do again, and they need us. Implement it. So I'm just going to implement a function that is going to return an eye collection, off type, leave a location and then I'm going to call this one, get the get allocations, get leave allocations by employees, all right on then by employees were getting the employee ideas of parameter. So once I put that inside off the contractor instead of the inter fees, I need to go back to my repository on then I'm going to implement the interferes, so give it a few seconds. You're going to get that era we go. So we over over that error on we just do a control dot andan implement interferes on. Then I just searched for that function that I want which is gets leave allocation by employees. So then in this file, inside the repository, I do the heavy lift. So I write the complex school right here. So then I can see return, and I'm just interacted all in one line. So I'm not want to go ahead and do a query based on db dot something cause already have find off. And I did something like this already. When we're checking for the allocations, I'm going to say Find all some getting all off the leave allocations on going to see a dot on I'm just going to break the lines. I can actually Brick Lane Or if we're at the dot on top of it, so you can see so docked were and I'll say, cure to start up the Lambda q equals on greater than sign que dot employee i d is equal. So the i d that is coming in through the perimeter on Ben. I will just do a dot to list so that we don't have any problems with the collection type on . Then we use our semi colon. So no, this is going to just bring back all of allocations for this employee. What? I did specify that we wanted toe know the period. So we're going to actually mimic something like what we did when we were checking the allocations. I'm just going toe copy the pirates where I defined the period on I'm going to place that there. And then I'm also into copy the part where I compare the period itself. So I mean, once again, you're right. The court already have it there. You just copy in peace. You know, if you want to practice and rewrite it, that's perfectly fine. But I'm just showing you efficiency. So know that I did all of that. Let me explain one more time. What we're doing is we're getting the allocations by employees. So for any period when you view on employees record, it should look in the allocation stable on find out all the allocations were the employee I d. Much is on. We're in that particle appeared. So if you're if it's 2021 no allocations have been set, then you really shouldn't be bringing back anything on Def. It's 2020 so I don't want to show it 2020 allocations in 2021 right? So and then I don't have that. We do the to list. So back in the controller? No, my function call looks more like leave allocation report dots, I just or controlled space on. Then I can just say get leave allocations by employees on. Then I will just pass in. I d on The expectation is that this will return at least off the allocations. Now that I have the list off allocations on the pier Adande, the employees. Andi, I really didn't even need the period here because the period would have helped me to filter out getting them back. So there I am re factoring court already. What I'm going to do is create a new model somewhere to save. Our model is equal to view a lucky son, VM on then, view allocations V m is going toe have as its first parameter. Alcide Mr the new keyword so new class typed on. Then the first property is going to be employees and employees just going to be equal toe over employee objects that we already phoned the record and mopped. All right, so it's a perfect fit. And then the next thing is that we want the list off leave allocations, and that really should be a list off type. Ah, that should be a list off leave. I leave allocation VM Sorry. So I didn't do that here, so I got to leave allocations from the database by Didn't Muppets understand too quickly moppet here. So underscore my purse. I'm just doing it in one line, just like I did earlier on. Then The destination for this map is toe a list off type I look to your son Or is it leave allocation, Veum Right. So volatile that directly maps the our data class. All right, on then we open will have to close the greater than saying again or goes integrated and sign. So this angle bracket much is with this uncle bracket on this one. Much is with this. And then we define the object by opening the breeze, calling our object from our data bees on. Then I'm closing the brace. All right, so these two lines look fairly identical, except one is mopping one incense off the object toe. One instance being returned where this one is expecting a list coming from this function. Call on its mapping back toe A list off the view type off the view model. Sorry. So then the expectant list in our model can be assigned a location. Since allocations is no only stuff leave allegation VM on It was defined as such in our view, allocations view model. So know that we've built or model. When we return the view, we expect to return the view with that data that is coming back on fitting this model. So I'm going to generate this view when to right click on view click, add view. I'm generating a template off details on. Then the model class is going to be view allocation. So Well, actually, here's what I'm going to do. I'm going to generate, uh, least are details template based on employee VM. All right, I'm going to explain why. So the thing is when when you generate a view based on a view model I'm sure you realize, but I know it tries a peacoat. The simple data types, simple data times meaning into string, those that are built in, not the classes that were creating. So because over our view, allocations view model is really built to accommodate two classes, which is which are employees VM as well as leave allocation. Veum. If we were to generated details Page based on those two classes, then it would not come out as cleanly so the most. Most of the information is going from the employee VM anyway, so I'm going to generate the temporary based on employee Veum, which already has, ah, lot off simple data types in it so we can display those easily, and then we can manipulate that page more easily to display the additional information. So that's why sometimes I'm not using the exact view model that is being passed into the view as the model class for the generation for the scaffolding. So this is how you can leverage previous work into making future work easier. If you have an appreciation for whole view more this really work, you can choose the best view model to get the best out off the order generated court at any point and then make modifications as you see the need. All right, so once again, I'm using the model class employees VM on. Then I'll just like ad, all right, And then our template is generated. So I mean appointed. No, I haven't been paying much attention to the Burbage on the pages. I'm really trying to teach you the flow and the back end coding, but I want to pay some attention this time. Um, so, firstly, I need to change the model because the model that's being person is not really employees. The M it's really believe well, you leave is that view Leave allocations V. M. Once I do that, then you're going to start seeing some errors popping up band. That's because the model is static on. It doesn't have a field called user name the model. It's of the samba field call using him because a class view allocations. William does not have a few called using him. However, the model does. Sorry, it does come with a class called employees on Employee does have a field called use any. So once again, I generated a based on employee VM. But then I go, Well, employee via really doesn't have, um, using him. And I can always go back to it on the check, but I don't believe it has email. Oh, it does have using him. There were. All right, so you just to go out to renders model docked employees that using him. So for any subclass that is being brought back inside the data, you can use it on just reference the property accordingly. So our model has two classic as employees. It has a list off leave allocations. So what we're going to do is go through and include model dot employees. I'm just copying this on I'm distant. Inject it after each reference to the word model. All right? And, yes, it may seem tedious, but at the end of the day, this modification is much easier than if we had attempted to generate the class with the original view model. Right? So I'm just going to go through on then you're going to see that eventually everything will fall in police. All right, so some of them still have some red lines. Eventually they'll go away. And if they don't aren't they all did. So that's our detail, speed. So this is pretty much a profile off any employees. We can beautify it, you know, we can make it into a whole profile page. We'll do that later. But right now I want to focus on show in the leave our locations. So I'm going to remove this action page relieve back to list. I leave Backed a list, but I'm removing the edits because I don't want anybody to be editing the employees from this page Boats underneath here I'm with at a horizontal rule on. Then I'm going to say each tool Onda se leave our locations and then inside leave allocations, I'm know going to generate. There's that Kontinen data on details off each Leave allocation in the system. So I'm going toe enter in tow. Turgeon off. Um, off reason cold where I use my gut sign open. And those brace on then inside off that I went to see for each on the double top. The tab gives me that generated for each block on. Then the collection is coming from models so I can just see model with a capital M and then say docked and then we say, leave our locations. A model darts leave allocations. So that's our collection. Right on. Then we have each item inside off the leave allocation. So item gives us access to all the details inside off a leave allocation on if we trapped back the IV allocation Itzler from or model, which is after I've you allocations. The M on it is off type. Each one is off type leave allocation the M And if I district that we see that it contains the number off days, the period, the employees on the leaf type details. So what I want to display no is just the leaf type beaters I want to say, Well, the number off these are the employees got as well as maybe the name off the leaf type. So back in details, I'm going toe. Just generate some issue McCord here and I call it a div on then, inside off this Dave fact, I'm going to reference bootstrap to see what kind of tools they have. All kind of visual elements that have that I could probably usedto enhance representation off this data. All right, so, looking through the documentation, I went on the cards, sectioning components. Andi, I see here that they have list list groups. All right, so I think this is nice. So let's just imagine each one of these being the leaf type Onda, a section that shows the number aan den the button over in another section. So this is what it would look like. You will have give cars, cards and then basically each or entry would be an ally element. So what I'm going to do is take the 1st 2 on the last two lines. So I'm going to take the 1st 2 lines first on go back into my cord on. Then I went to put those outside off the four each. So put that Dave on the, um class outside off the four each. And then I go back on the netted these two. So this is just showing you how you can, you know, manipulates the are the existing HTML elements to your full and desire. So obviously, if I insert too much issue between the at sign on the cord, it's kind of nullifies the effect. So what I'll do is remove these and put the at sign directly on the four each. I know it remembers that. OK, it's C sharp court, right? So that's a good way to recognize when it loses its context when it's no longer highlighted . So this is setting the premise for the list group on. Then for each leave allocation that is in the system, I'm going to be Gellar generating on l. I tug on this l I tug is going toe have the class list dash group dash item, but its contents will be on that Just break on, Then I'm going to put in All right, So I'm going to take bootstrap again to see what useful Styler element I can put here on day I landed on a page with budgets, so I'm going to take the example off the heading with the But so the heading is going to have the leave type on the budget's going tohave the number. So once again, this is just me trying to be creative. Um, booster makes it very easy for me to add these reserve elements. You may have other ideas, but I just want to try the concept that you have your html but you can always insert whatever text you want by seeing at sign on. Then in this case, you want item item represents the leave A location on that I'm going to go down to leave. Type on, then. This is an object that represents leave type on both of that object. I really want the name off that leave type. So I want to print sick leave, right? I don't wanted to just say I d one. I wanted to print the word sick. Leave andan inside off the badge, which can pretty much be anything. Seconds a budge dash, Sikander bunch dust, Primary budge Dutch success, etcetera. But inside off the content off that budge, I'm going to remove the sample texts and replace it with item docked on then right here. I wanted to print the number off. It is all right. The number off these is the name off the field that shows the number off these that correspond with the leaf type. That allocation is so once again, all of this this ally topped with all of this data is going to be printed inside off before each. So, for each allocation that this employee has, there will be, um, some representation off it now Outside off that I am also going to print and I just use a bar on. I want a button on door. Well, I'm going to use an ankle tag, actually, so I want an uncle tug on. Then we want this un Qatar to look like a bottle. So I will say Class equals Bt and and Bt and dash on. I'm going to say warning, cause this is going to be an edit. Some would say outline, dash, warning. And then inside this uncle talks. I'm just going to put this in the new line on inside this Uncle Tug. I want the icon with a class. Someone's used my fund. Awesome Effie on then if a dash pencil. But it's going to be on edit button on. Besides that icon I wanted to see she or it are any time, just say it's complicated, much more than it. All right? So no, with all of those modifications, when I'm going to put the backed A list tag underneath everything so back to this to go back to our inexperience can refined that later for want, but I'm going to know going to debug mode on, then we're going to see exactly how much our work has paid off. All right, so I executed the application. I'm here at the list off employees, and they were going to check on. We're going to click for details. Speech onda. That leads to an error. So the arrow saying that object reference not said toe some object and it's referencing or leased off. Leave types are so that means or will not leave ties but leave allocations. So what I'm going to do is going to debunk more than than we can see exactly what is happening to cause that. So I'm going to the controller on. Then I'm going to click on the line where returns the view. All right, on. Then I went to reload the page so that it does all of that operation again, and then we'll assess what data comes over the when it hits our break point. No, we can hover over model and we can. Or we can just use the section normal here on day expand model. So we see that employees came back on. We have the employee's details, so you know, the day joined. We know everything about the employees. But then we go down to leave allocations. We see that we have to leave allocations in the list and I expand one on. Then we're going to see that it does contain the employee data once again. All right, that's fine. But then the leave type object itself is empty. So leaf type I d has the leaf type I d. But we don't have the leave type object itself. So that in itself is ah, little issue. No, because then we're referencing details inside off this object that are not available. Based on what? We're returning to the views. I'm going to stop this now. What off debug mode? We're going to go back to our repository file for leave allocation on. I'm going to make one minor adjustment to the court and I'll explain why this adjustment is very, very important. So we're using the final option to get all records, and in the final function, we have a line off court that says BB leave allocations, which is our table to list. Now what I'm going to do is add another function, another Lunda function to this on that is going to include on entity, so I'm just going to type it and I'll explain exactly what is happening. So recall that or leave allocation when it got loaded up with all the data believe type um , section off. It was empty. And so that's how I got that no reference exception, because seeing you're trying to reference data, that is just not there. So we need to say, when were retrieving the records for leave allocation. We need to retrieve the corresponding data for the leave type for that particular leave allocation record. So the relationship right? If you were doing regular database, you'd have to do something like an inner join to the leave type table on. Then you'd be able to see the leaf type details because the idea is acting as a foreign key , so they want to do here is say, db dot leave. Allocations dot include open and close breeze and include as a capita I cerebral. That's let me just retired up quickly include open and close braces on. Then it's going to tell me that I need to include a library. Ciders include that library. No problem on then, inside off the braces. I'm going to put in a Lambda Expressions as a cue and I'll just say arrow dot on in, Say sorry Q docked on. Then it's going to say, What exactly do you intend to include? So we can include any entity that is related to Remember when we created our data class and others go back to the later class? Quickly, we created ah foreign key entity called employee I D. But we also mirror representation for the entire class, object off employees with the same thing for a leave type. So in some situations you may need to include in some situations it may come over automatic aliso, for instance, The employee entities already there would have to include that boat. We realize that the leave type entity was empty. So I'm going toe in the repository class, say that I want to include all the corresponding data for the leave type on. This is like an implicit inner join. So when it does, that quarry is going to bring over all the possible details for anything that we include on for each record will get all the details that we need and remember that we need those details because in our view, in our details view, yes, we are bringing back, like, the leaf type dot name I were bringing about the number off days Associate ID with that allocation. Well, really into its leave type dot name. That was the issue. So know that I did that. Include, I went to run in debug mode again on the three point is still in the controller. And then when he gets the break point, we see what happens. All right, So we click details, which is going to fire. The exceptions are fired the break point, and then we're going to assess our model objects and I drill down into model on. Then I look at leave allocations. I'm getting the to leave allocations for that. Employees drilling toe, at least one off leave allocations that I'm seeing. The leaf type is no longer seeing No. So when I drill in tow, the leaf type object. Now I'm seeing the details off this leaf type object, including the very name that we need printed. So I'm going toe. Just remove this break point on press. Continue on, then we will see that. Okay? We did some blind designing So this is what was generated by default, and we're bringing about all the details that are available for that employees. So this employee, the user name the email, they didn't have full number, so that's blank. They didn't have the tax i. D. Date of birth and notice. All of these are kind of joint up on not being printed, you know, as cleanly as possible on Do you can just remember that we can just go back to our leave, um, employees, our employees, VM right employees VM and set up or display data annotations above each for the printing to be better. So at the end of the day, where some are finding to do with how are leave allocations, sexual look, so looks. So we have the leave allocations start being printed well on. Then we can see that they have deal of leave allocations for sick leave, and that's 10 days and therefore vacation leave. That's 15 days, but then the edits the that's going in a different line, so we can probably just go back to the view and refined that a bit, and it's probably doing that because I brought the line so What I'm going to do is just remove that brake line and print everything in one line on that theoretically will solve that brake line. So I'm going to do that on the just restart debug mode. Let's see what that feels, and that did not change. And I think I know why. I think it didn't change because we're using an ah header tag for the sickly section and I'll just inspect and confirm. So the header tag comes with its own partying, so it's only going to take up one line. So that's really wife. So what I could do is include the ankle inside the header tug. So I'm waiting. I'm going to come out off de boat mood quickly on. Then I'll just expand this entire header tag to include that anchor tag on. Then we see where I'm not getting the pencil, and that's because I messed up the class. That's f A not feed. All right, on, then, this time since I'm really just using you, I understand to do the bro's or link on view in Bro's er Onda bro's over to the page and know that looks a bit easier on the eyes off course once again, you know, we can mix and match. We can put in our own flair, but for no, that is what this looks like. So the next objective behind finishing up this model will be toe put in an edit option where this admin user will be able to manually go on change that sick leave allocation value. So my last act for this video is just to take this I saw out of the peace, and I just see just removed the words employees vm from the details speech. So I go back to my view removed that, um on. Then I'm going to say details for Andi. I can say dash and remember that everything is in the model. So if I wanted to print the employee's name, I can say model dots. Sorry, I have to use the at sign model darts on DSI employees not, And I'm going to do it like last name comma, arthroscopy. All of this instead of retyping it from scratch on change Last name, toe first name. So when the view loads is going to say details for on this would be well, we have very generic users in our system, so whatever user names you'd have used, you see there were affected. So I'm just refreshing the browser on. That's what is going to use the details for for last name, comma first name. So as much detail as much off anything as you want on your page, You can always, you know, use a pure elements. Be dynamic and generate as you go along. So, as I said in the next lesson, we'll do the work on the anything screen for the details off the user.
34. Leave Allocation Module - Edit Leave Allocation Per Employee: Hey guys, in this video, we're going to set up that edit screen that allows us to change the allocation for a particular employee. Onda particulate leave type. So I'm just going to get straight into the action. In the previous lesson, we would have set up our details speech on our details Page features a section listing the leave allocations for up articular employees. We see the leaf type by name. The number off these and then we have on edit button that allows us to bro's to the edits are At least that's the objective. So notice that we have the ankle tag, but ankle tag really leads nowhere. So what we're going to do is at an SP dash route on this route is going to be at it. Onda. We're going to also add an S P dash route. That's only that would be dash data. Sorry, that's thus idee my, but something I get my wires crossed. So that's that's true. Dash I d on then. The idea that we're passing in is at sign itim dot on the value would be idea. So item that I D on Remember, item is when to represent one object in the collection Off. Leave a location. So we're anything that particle. Leave our location record. Which is why we're referencing the i d for that ive allocation. So, um, by not specifying an SP dash controller, it's going to assume that you are using the and it inside the same controller that this particle of you, which is details, is in on our details. You is inside the leave allocation control. So that means when we click and it is going to infer that we mean the edit action insider leave allocation controller No, we already have actions for it. It's whoever get action aware of the post action. So we should have an appreciation fortify that one renders the view with the data on one processes the corresponding action after it has been carried out. So we're just going to get into the action. I don't have to. I shouldn't have to do much much explaining here because we have done this a few times before. So for our edit, we're getting on integer idea And this idea, remember, is or leave allocation I d. So we need to find the leave allegations. I'm going to save I relieve a location is equal to underscore allocation or leave allocation re for docked I we're going to find by i d that particular leave allocation record passing the idea reference on then remember that weekend this mop right off the bat . So I'm just going to I mean, sometimes it depends on whole clean you want to call it to be so I'm personally not a fun off just mapping in one line with the call. I like to break it off, but that's just me, right? So whichever one you prefer as on as you can get it to work, then you can do it that way. Ondas as you can, ready clean enough that your team can't understand. So that's on the score, ma per dots, Mop on. Then we're mopping full. I leave our location on VM data type. There we go. On the object that were mapping to that direction is leave allocation that is being stored in that terrible on. Then we air passing or model into the view. No, we generate the views. So Iraq view click, add view. We're going to be choosing the template off it on. Then the model class that this edit form should be generated off off is going to be leave allocation VM on, then. I mean, sometimes you really don't need the data context class once again if you're using the view model. But I'm just going to leave it alone and I'm just going to go ahead and click, add, So no, I have my head. It's so take all this I sword that is saying leave allocation vm Onda have my edit where I have the inputs being hidden, the number off days visible, I'm going to make the deed created also hidden. So the thing is, if I created an and its view model for this, I could have left out some off the elements. So like they created, I really wouldn't need be created on the edit form on. I would eliminate the need for me to have to make these kinds off. Edits. But I already went down this path. So I'm just going to meet these minor adjustments and say type is going to be equal toe hidden. All right, so every team they created and we had to do that earlier with data types, I'm sure you appreciate why that is being done, Period. We really don't need to return periods. They see all of these things are coming back. Employee, I d leave that. You really don't need these elements inside off for it form. So what I'm going to do is remove this edit form, and then we're going to do it over. So I'm just going to go over to leave allocation, delete this edit on Instead, I'm going to create on a view model specifically for editing leave allocations. I have the data class, but leave allocation VM file. I have created a have you? So I'm just going to go ahead on and Well, I'm going to just copy the create that it already has some of the visa want. I'm with the peace. I'm taking out the list off leave types. All right, Andi. Instead, I'm going to put a solid object off type leaf type. Along with what? I don't even need the i d. So I'm just putting in that solid object because maybe I want to print Oh, the type. It is the number, um, the number off days, someone to reference the number off these. All right, let me change the name. So this is going to be edit. Leave allocation view model, right? What else? What? I definitely need for that form. Real. Eventually I just need the employees, the leave type and, well, I need to retain the I d so that it can be hidden and transition, you know, So that edit edit screen is really just going to have the hidden feel for the i. D to track which record is being edited. It's going to probably have the some details for the employees. Maybe I want to print something for the employees. I'm including that object. It has a number of days which is subject to change on. Then we have the leave type details, which, which I mean I mean want to display details on once again. So I know that I have that view model. I made that change I saved. Now I can go back to my comptroller and I can do this again. So instead off mapping to view leave, I look, it's on VM. I went to my upto edit leave allocation VM on. What that's going to do is take the pertinent feels from the database Let's remember this is attorney an entire object with all of the details on is going to mop only the pertinent ones needed based on what we defined in the view model someone toe generate the view again . Select the edit template on the model class is going to be And it it's leave allegation VM and I can click. Add are it's a notes. No, we ended up with our at it form Onda. Uh, all we have are feels for the idea which is hidden on. We have the text input for our number off days. So, like I said in a previous listen, if we and I'll just find it quickly If we have class types, the complex types can't be scuffled it, so they usually ignore it. Understeer with the simple types which are in string, etcetera, etcetera. It already knows that I d much is the the key value in the original data table. So that's why when it generated it on, we chose the data on the data context class. It knew that, Okay, this much is the idea coming from urge nothing. So I'll just make it hidden. So I mean, it's it's inferring a lot off things on. Based on the way we write our code, we can limit the amount off editing if we just set up the standard right from the one. So the standard here is that we create a view model purview on. Then we use our view model to in, you know, inform what was on that beach. All right, so I am going to put tag appear so the title of this speech is going to say something like anything. And then I can say at model, not leave type dot name. Right. So when we retrieve the record for this allocation that we're modifying, we should know the leaf type And remember that we already included the leaf type entity in anything that is leave allocations. So we have access to all of the details. So I'm saying anything This leave type our location for On that I can put the employee's name at Sion Model dots, employees dots on. Then I'm going to see first name on. Just copy this one's again. So of course, based on how you want to know whether I already have the standard off last name comma, first name So let me see. Last name, Comma, First name. All right. On If when we get to this point we get another exception because maybe employee is showing up blank. Then we can always just go back to our repository on at another. Include for employees. Well, let's test it out first. Understand? Use browser link on view in browser. All right, so let's test drive our edit button Someone to click edit. But oh ah, It's still rotating back to details. I must have made a mistake in my Ah, this should be SB action. And that s P roots. So my bad. That should be sp Action me that changed Save on then reload our page. All right, so making those edits No, I see that the link issuing or properly I click at it on DNO We're getting some error. A boat? Ah OK, so I'm getting an error about it. It's leave allocation VM on. That's not on autumn. Oper supported mopping right Onda We would have gone through some autumn upper configurations were in our mopping. We need to make sure that we're upping whatever it is that we're referencing. So I need to create amount between leave allocation onder that particulate ones understand to duplicate this land for leave our allocation on. Then I'm going to say I want a mapping between the IV allocation on the edit leave allocation VM. So if you get that arrow, all you have to do, just update your mopping configuration on, then once you've done that, you should be able to press forward. All right, I know that we fix that mapping is you know, we're seeing that other issue a boat, that object reference not settle, for instance, so that Sir Peter off a previous issue with leave types were where to put in that includes our include function. So I'm just going to go right back on, you know, after a while these errors, you see them and then you be like, Oh, yeah, that's what I need to do. And that's why I'm going through this exercise or these exercises like these so that we can see the common errors on learn how to fix them. Um, you know, quickly. So I included leave type. I can add. Another include O R, I can say, Then include on then I'm going to put in another Lambda Expressions. So include leave type, then include que dots over. No, Sorry. That then include is when you are Daisy chaining. So if there was something inside off leave that that I wanted to include also then I would use that that include someone toe also include so include, leave type on, then include employees on. Then I'm going to try and load the page once again. So I'm going to refresh. All right, so that modification didn't serve it. And that is because I'm sorry. I mean the modification to the wrong function. So in that particle pollution were using find by, I d not find out. So I need to basically tell that when I'm finding by I d I find that particular object So understands Brick Lane on. Then I run the include lines. So are Well, maybe I would do that before the find. So let me see. That's include that include right. And then I find so all right. So we're going to have to reflect it. It's called a bit because I said I want the leave allocations and I want to include these entities and then we're realizing that are find function is no saying that it can't be used , so that's no issue. That's no problem. Instead of using find, I'm going to use another one called first or default. So I'm just going to remove find and I'm going to say first not first or default on then first or default takes a lumber expression so far of the Lambda by seeing Q putting in my arrow, which is equal sign on the bracket, have been sake you dot So then this allows me to say I want the first element or no, If you can't find it, give me No, But I want the first element that much is this condition and the condition that I want The first element on is that the i D in the record much is the i d coming in. All right, so on one hand, we could use find, But then we see that does limitations because I wanted to include missing data or other elements. Are the bits off data from other tables? Onda Fine, stop working. So I just used an alternative. So link is very powerful, very flexible on it has a lot of options that you can use to accomplish a particular task, someone to refresh and see if that solves my issue. All right, A nowhere in business. So I'm seeing that. It's telling me I'm editing sick leave. So that's leave type coming from the record on the allocation of four test user or user test. Right? Last name, comma, first name. So that's what this edit screen looks like on. Then I can make an adjustment to the number off these. So if I feel that they should have more or fewer D's, I noticed the elements that are the label is number off these off course. We have to change that. Give it a proper display name in the view model. So I already showed you how to do that. I'm not going to emphasize that every single video as you go along you do that to make sure that your interferes is clean. I'm really focusing on functionality. But then my final source scored will generally have all of those little adjustments as we go along. So no, I'm going to fire aboard, string up the Post edit actions that when I click, save it actually commits the changes to the database someone to go back to leave management , go back to our controller, and then we'll start modifying the post on this should be quick. So I'm going to say, instead of taking an idea and caught form collection, I'm accepting the edit. Leave allocation VM on. I'm calling it model. All right, So when we posed, I'm getting back some bit off data with with this some object called model off this type with some amount of data on. Then what I'm going to do is first, they save our location is equal to a mapping off on our calm upper, not mop on. I went, um, up from edit. Sorry. I'm going to mop to leave. Allocation the data class, so leave allocation on the object I'm mapping to leave. Allocation data type is model. All right, so this is edits leave allocation. I'm just mapping it back to the original data class on. Then I'm going to Well, actually, I'm skipping a few steps here, so to be completely should actually say if on open that and then see the model state that is valid. So if it's our let me say if it is not valid, so if not, model state is valid, meaning that it's not varied. Then we want to return view on we're passing back model Onda. Well, it will take care of whatever Eros are there. So we did all off this already in the leaf type controller. So we can That's wrong file. We can actually go on a reference, um, off the logic that will put in So in the leaf time controller in our editor did something very similar. We said if it is not valid in return view, otherwise start doing all of our wonderful operations. So if you just if you forgot, hold to do it or what to do. You can always go back and reference what we did with the leaf types controller. But I'm going to press ahead. So we're returning or view which would have our era's already. Um otherwise, the press along for where we get the mop version off the model back to the data class that I'm going to call the leave allocation report dots off the it on. Then it is expecting a data type off leave allocation which we have in our allocation model that we just created and do you recall that this is calling a bullion so I can save our is . Success is equal to that on. Then we can check and see if not so if open breeze if not, is success. So that means it was not a successful for it. Then we can add model ST dot so we can add a roast in a model state at model error. And then I went to open that up and there is no key, but then the message is going to be error while saving. All right on Then we once again returned this view. If that and that's all, if it's not success, right, if none of this gets executed and we want to return to somewhere, so I don't want to redirect index this time instead, I'm going to redirect to the very details speech on going to passing in that I d. So ah, little challenge here know is that I don't know the idee off the employees because I didn't have gone for it in the edit leave allocation. VM someone to just make a quick edit Already have the the employee vm Some just goingto add the employee. I d All right, So by adding it to the view model, No, I can access are cheap. This idea our own during my head, it's operations are going back to the edit page on our they have a hidden before they leave allocation ideas. So I'm just going to create another hidden. And this time it's going to be for the employees I d. So that when we submit the form, we're still keeping the original I d on the I d value coming from our page. So back in or control or no, which is handling or business logic, I'm going to see that I want to redirect the option called details. All right, so we're redirecting tore details, action on or details action once again requires on employee i d. So I'm going to have to say comma on. Then I want to say something like new, and instead of a new object on going to call this object while the property of the object is going to be I d on it is going to take model dots employee I d. So let me just review that quickly. So remember that we're redirecting toe in action. We have seen this already where it's completed operation and it's going to redirect on by default is going to redirect index, which was fine because Index did not require ah parameter. So let me just scroll up to index quickly. Index DOESn't REQUIRE APARTMENT OVER AFTER you finish editing for one employee, I don't want you to go back to index toe the entire list. Off employees are the entirely stuff. Leave types to then go through the same process. I just wanted to go back to my record in case you wanted to edit another one. If you don't, then you can go back to the list afterwards. What after you've edited, I wanted to redirect to the details off my record with my leaf allocations. So instead, off going to index mindless there by default, I can determine where I wanted toe redirect to which action. I wanted to redirect toe on the action that I wanted to redirect, too. And I'm just going back to my idiot. Action I wanted to redirect to is details, not index this time, but details on then details requires a perimeter off string called I D. So I have to then make Ah cone for that. And I just say comma new on then the name off the permitted expected his ideas, so I have to call it I d on. Then I give it a value. And the value that it's supposed to be getting is the employee i d. Which I are storing inside off the model which is coming over as a value from the edit form . Alright, so know that all of those adjustments have been made on I can do control shift and s deceive changes across off as every file. That doesn't mean serious to control shift and s, I'm know, going to test this out. So I'm going to change this from 10 toe. Let's say six six should be a clearing of value to see the difference. Click save. All right, so we're getting another era. Andi, I can tell you that. Well, if you're getting this error is because it is not, it is trying to reload the view without the data. So let us just say there is something amiss with our cord. Andi, I can tell you that it is probably reloading the view because it's either hitting the model stay not being valued or this not being successful or it's trying the operation and encountering some error on DSO. It's returning the view, and I suspect that it's probably the fact that it is catching the error on return in the view. So what I'm going to do is we went to modify this it this update it a bit on what I'm going to do is actually build out the entity a bit better. So what is happening is that it's catching an exception when it's trying to commit the change, and that's because some off the data is not lining up with what it expects. So I'm going to modify this in the sense that I am going to find the original someone to say, Get record is going to be equal to on the score, Leave allocation people dot and I'm going to find the record that is about to be edited. Find it by its I D, which is modelled that I d right, and then having phoned it, I can go ahead on assign the values directly so they're turns on the map in doesn't necessarily work as as cleanly as we would like so, you know, case by case basis. You see where it works perfectly. We see where it might not work as well. So this is one of those situations where may not work as well. And so I'm going to get a big creative on a bit dirty in the way I'm going toe I low it to edit. So no, I know that I'm a lowing and edit off. Only really one field coming from the edit leave allocation is really one feel that I'm changing based on the form and that is the number off days. So what I'm going to do is having retrieved the original record to be edited, and I'm calling it record. I'm then going to remove this part where I do the mopping on. Then I'm going to see a record ducts field that I know I'm updating. Or if it's more than one feels so that in this case, the feel that I'm updating is number off days. I'm going to say number of days is no equal to model that number off days, so whatever value was passed over from the form I am no assigning. It's to that database record but remember that nothing really happens at this stage until we call our off the it function. So then I'm going to call the update function on I'm passing in the object off record instead off the original allocation objects which we just removed on. Then little known we did fail to put in model. So you told your stirring exceptions, Andi. So I'm going to try this again, someone to save control shift and s on. Then use the browser link, relaunch our application and then try the operation again. So back at the screen, I'm going to change this store six and then click Save Onda. We're back on. We have reloaded are details page on do notice that we're reflecting the new value. So this had a bunch of exercise that we did. We created a new model view model We tried and field at certain operations, but we found a solution and that's what programming is really all a boat. There many ways to accomplish what you need to accomplish. You just need to be or fear with the different techniques that will get you there on make sure that you're making the best decisions as you go along. So with this operation, don't wear pretty much finished with our leave allocation model where we alot for one the automated sitting off the allocations per type. You can add more business logic for me with my attorney to leave cause obviously, your meal employees should not get maternity. Leave these so that would require two modifications. You have to add a gender to the user profile and then you add the business of logic to see if the gender is a certain type then doing at maternity leave. But we've done that. We've also gotten hot tomorrow where identity user class, so that we could get more details on our users. We added the details where we see their profile as well as water relieve allocations there are on then, finally, for this lesson, we would have put in the edit functionality to be able to change the allocation for that, particulate employees. So in the next video, we're just going to do a few finishing touches on. Then we will be checking in our updated application to our source control
35. Review and Add Changes to GitHub: Hey, guys, in this video, we're just going to be looking at some changes that we've made and some changes that I made maybe off screen on. Then we'll be checking in or CO to get up. So just to review, we just put in our leave allocation model where we allow the admin users toe. You know, attributes. Leave these vacation. They're secretive days. Whatever leave type is those days. Get attributed toe employees on. Then once they're attributed than the admin user, can either of you or modify if needs be. So you know, when we go to manage, we go to leave allocations on. Then that brings up a screen showing us all the different types and then the function, allowing us to actually begin the allocations for the management. Off the allocations we got to employees where we'll see all the employees in the system. Right now, we only have two on that will allow us to view the details off this employee. So when I click details that will load up like a little bit of speech for on, I put on the user's name. So you know exactly which record you're looking at using in the email address. Full number. Some of these are blank, but what? One of the adjustments and made off camera was at the daytime notation for the model that is being used to load this speech so that our labels look a bit better because there would have been camel cased, you know, there would have been no space and so on. So I enter find them by adding those data annotations to the view model. Andi, that's in the data look a bit keener. I also would have modified at the went for the box that each leave type gets generated in or leave type allocation. Onda also changed how the buttons look beside the wording. I also changed the battle list button. So this battle this button brings us back toe the index speech on. Then if we click edit, we go to our edit page where we see number off. This also modified the label for this form on. We get to change the value we click, save, we go back on, def. We get back to details. We just reload the the details page so we can, you know, navigate our own more easily and above all we have are top now. So having made all these changes, I'm going to check in this court. If you need to reference that you can always go on reference that version off the court. But we just do it the simple way where we go to visual studio Onda remember everything with a heretic means that it was modified since the last version. And then you have a lot of heretics because off the must updates we had to do regarding the identity update from the changing from identity user to employees class type. But that really has no bearing on the ultimate goal, which is just right click or solution, go to commit and then well or comment message is going to be a little lengthy If we're going to try Annacone for all off the changes that we made someone to say implemented, leave a location module Onda changed. I dont t user toe employees. All right, so that is what we did on DA. I'm just going toe, get the correct here and then say commit all and sink and so mean the local commit on, then synchronized with our remote get hope repository and that's it for this model. When we come back, we will be setting up the leave the leave application model where we are Low employees toe apply for leave based on their allocations. Andi Khomeni bees, They have left out off that allocation on. Then we'll be sitting up the admin panel to actually approve our deny these leave requests . So stay tuned, more fun to come.
36. Employee Leave Requests Module Overview: you guys, welcome back. We are going to be starting a new model today and that will be for the leave. Applications for this model will be setting up the functionality that will alot our employees to be able to apply for vacation or whatever kind off leave it is, Andi, we'll be setting off the functionality that the admin user has to approve. So when the person means the application request, it goes into, ah, status off pending on then it is either approved or rejected by the admin user Onda. When either action occurs, of course, we log it and we change the flag and we also adjust the number off days that the person know has available. So all of that functionality is going to be going into this model on on screen here. I really just have that leave history class, um, the data class associated with leave history. So I'm going to bring up the interferes quickly, and this is our interferes right now. And under manage, the admin user will be able to view the leave applications. However, somebody who is not an admin user should not be able to see manage, but they will be able to apply for leave. Granted, you have to be are ready, stirred member off the website of the playfully So we'll be setting up authorizations on the leave application function on will be setting up the functionality for approval. Andi Rejection So there there will be slight changes on database changes along the way. But in this model, we're going to be implementing some nice controls like our calendar control, so that the person can select the start date and the finish date. We're putting in intelligence to make sure that you know they can put in a start date. That is further in the day in the future than the end bit, you know, will be customizing the solution and putting in some nice controls on. I think we're going to have a lot of fun in this model, so stick around on. It's only going to get more and more fun
37. Employee Leave Requests Module - Database Changes and ViewModels: Hey, guys, Welcome back in this first video, I'm just going to make a slight modification to my data table on It's really just to change the name. Um, so I have it here is leave history. But, you know, when I was looking at it again, as I leave history that sounds on personal, maybe it's better as leave applications or leave requests. Someone to call it leave requests. All right. On any factions, a class name, then I need to make sure to refracted the court throat re factor. All references to this class throat my coat. So regions to do makes that easy for me to just rename it everywhere else. It might be referenced, including in the repositories and elsewhere on I can just do that. Rename on the Net effect is that the repository would have had it modified. If I go into application BB context, it would have needed toe modify it. Andi, I'm seeing some DB sets here. That really shouldn't be there somewhere. Toe remove thes. Sorry. Uh, if you see that in your code, you can feel free to remove them also, I'm going to have to investigate why they were there, but it should be no harm done to remove them. All right, so then the be set leave requests is no. And then off course. If we change the class name, I have to change the actual name. The table gets Sanderson to change. That requests Onda. The final thing is that you always want to make sure that your name off your file much is the name of your class. So I just renamed that also from the history to leave whether request seem off the file on really enter the class should be request not he's not requests someone to do another renames Terrible that So that's just me trying toe. Make sure that on here they're saying that there's some trucking future that I can Anybody is anybody. It's no harm done. So remember the class name should be kind off singular. But then the table name, when it's being referenced, can be plural. Right? So leave request on. We have the table leave requests. So that's change. Number one to the database. Um, Andi. Yet that's pretty much the only change I want to make right now, as we below the model maybe needs will change. Maybe something else will come up. We should be familiar by no with which ever change. We need to make make it to the data class so that we're adding a table. We create a new data class, make sure it's represented in the DB set references, or we just make whatever modifications started two classes and then perform or migrations. However, the next thing that I want to do in this particular video is just set up a view model. So I'm going to go to the view to the Models folder at a class on that I'm going to call it leave, request VM and then leave request V. M being the based view model class. I'm just going to take all off the properties from the original class and place in this area. All right, so have so I like to create, like, a base. And then, ofcourse, the beast doesn't need the actual data annotations that I necessary for the data class so you can just remove those and then we change the references to the corresponding view models or its employees VM leaf type VM on employee vm again. So at least we're sure that we have direct representation. So that's why I always have that beast view Waddle because it's a direct mapping between the data class Onda view model on. Then as we build the other interfaces, then we can start having the variations thereafter. No, The next thing I want to do is make sure that I have the mopping. Andi, if you notice I don't have a mapping for that one. Well, I did had leave requests, some changing leave request on Then I have what I have. Leave history Veum already. So you see, that's why naming if as important cause I already have it as leave history VM. But I just the time out to changed over to the request VM so I can just remove leaf history vm this entity that one note on. If you compare the two files, you will see differences. But as we go along, I'm going to be putting back certain things that are probably going to be missing from the New Wonder decorated on. That's fine. I just don't want toe complicate the simple things just yet. So the next thing I want to do is make sure that the mapping has the car to mapping for leave requests, table on leave, request VM and then we can perform a build holding on control shift and pressing B and then just to make sure that we have no errors and I do have some errors. So it's always good to do a build and then you notice that you have the era. So the air Amiri's that I didn't change the reference from leave request requests. So that's one of the don't size, reflecting a 40 after me. Sure, you change the cord in all spaces. It can always just control shift and be on. Then it will tell you that it field visual studio lost to tell you that you know where you feel so that they can keep you honest. But then I can just control F in this file, find leave requests and replace it with lead requests on this Replace are all know psy that's current project. I want to make sure it's seeing for a document that you have to be careful with doing it across the product so the Koran documents replace off Onda. Then we have to change all the reference of the teal because they call it, leave his trees. But no, it's leave requests, All right, Someone to do the same thing. I'm just going to find leave histories in this document on Just do our place. Changed all of them out off appearances have been fixed. I can always go back to my era list on, then use easier errors. But then I'm going to build just to make sure, all right? And then this time the build was successful. So no, I know I have zero arrows on my quarter. Factoring, factoring has worked. Oh, well, so, no, I'm just going to do a migration on update my database. So I bring up the package manager council, which once again, if you don't see it in the lower panel, you can always just go to tools what's new, get package manager and select that consul option. But here I'm going to say, add dust, my Grayson, and then the migration I'm adding has changed. Leave histories, team. I mean, you could also say change, leave histories, someone to see it that way. She and she's Lee histories to leave requests. All right, so it's more explicit exactly what to exchange So this percenter let it add that migration . Oh, this is an important North. Sometimes when they're making some changes to tables that may be changing the name or changing certain data types associated with it during the migration, there might be, ah, loss off data. So you have to be very careful with that when doing these migrations. That's why seeding the databases usually recommended because then you have more control. Over the static are the basic data that goes in on this is during development. So it's always easier to lose data during developments than it is in production. Right? So you have to be. I mean, if you get the hang of it from in developments, then you'll be better able to gauge. It's in production, and there are controls in place for doing migrations in production. But I'm just bringing you prison to this, um, condition that some changes will result in the loss off later. Right now, we don't have much to lose anyway, so I understand to press ahead with this migration on. Then I just say opiate dash database press enter on. Then it is It's done. So we're going to just verify by going to our object Explorer drilling down in toward local DB in Tora databases looking in, leave management, looking at the tables on There we go. So leave histories is no called leave requests. All right, so that migration was completely successful on we see that it retained all the columns as we said it should. So no, we've performed RD Toby exchanges and our view model creation. So next up, we're going to start building in the controller and the different actions on. We'll just be having some fun with this. So next up will be setting up the screen for an employee to be able to apply for of some form off leave.
38. Employee Leave Requests Module - Setup Controlledrs: Hey, guys, welcome back in this lesson. We're going to be setting up the controller actions and all the dependence is that at least we think we need right now to support our leave requests model. So in visual studio, I'm just going to jump right into it readjustment to go straight to controllers. Click, add at a new controller. And then, as usual, we choose the NBC control. Always read right actions. So select that. Click add. We're calling this one leave request on troller on. Then we click. Add once that's generated, then we want to start adding our dependency. So we start off with our private read only referenced over repository for leave requests. So that would be on. I'm just going to check on DSI that I really didn't change the name. So it should be I leave request. I'm not. I leave history, so I'm just going to go into the contract on I went to me that update so in the contracts file on where to find it first, then went to rename it on. The thing is, when I rename the file itself is your studio will be the suggestion for me, Tool just rename everything. So that's leave request repository ana press enter. Then they will suggest that I perform a renames. I'll just say yes so that you will be the court file automatically on. Then I will do the same thing for the report stirs. I did that for the contract that interferes on, so I'll do the same for the repository where I just renamed this one quickly so that it reflects my new disposition, which is leave request on. Then I'll say yes to the problems to rename across the application. Alright, so that's another factor. So, like I said, you make one change. You have to be kind off thorough on consistent cause It'll wants something named leave history and something named leave request elsewhere. And then you get confused. So in the leave request controller, the middle slows anything that's not absolutely necessary. Then I need to make her friends toe. I leave request repository on. I'm calling this one ive request report, all right, and then off course after include any references and get my spelling right. So that's private. Redoing the on then include the reference or the name space for the I leave request repository. I just use my lifeboat here. Include that reference on, then there we go. All other dependence is that we may want would will definitely be the mop er on. Maybe one for the user manager. So instead, off writing the motor already have them nicely done inside the leave a location controller on. So, you see, when you start building a big project and you have fires all over the place and fires are open, you know, I like to keep my full disclosed so that I can go there, find the file on, Do you know, retreat with quickly instead of picking our own until I stumble upon it like I was doing the snow. So in controllers and I have those toe being made reference to second this copy those pieced as dependence is on then off course. Do the necessary inclusion off the for the folders or the name species. And then I wouldn't know creates Michael instructor. So see, See, thar So all of this we've done multiple times. None of this should be foreign to you, so I'm just going to hurry up and do this so that I'm not spending too much time building this part out, and there's are completed constructors. So if you were able to do it yourself, then that's good defense, often looking lettuce. And that's good. If not taking the spot video on, Just try and replicate that cold iron so pressing ahead. Um, we can just do the index view from no. So the index you This one is going to be kind of tricky. So our index view is going to be primarily to show the administrator or the you know the leave requests are. Should it because then there to index use that we can to have the index view, which is the view that the user will see when they want to see all of their leave requests that they have submitted on. Then there's also the index view for the administrator, or where they're going to be seeing all off the pending lists. So the Concept off index really is the landing page. However, you don't always have to call it index by default. Everything will land on the index paid, sure, but then we already know that we can control the floor we can control who sees what by creating custom actions that we bind to certain links that certain people can see. So I'm going to set one big authorized talk over this entire controller. So that means nobody should be able to get anything inside off this leave application controller without being a registered member off this application. Alright, but then there certain actions that I'm going to authorize for administrator role only on then, there certain ones that well, anybody will be able to get into our we can probably at authorization for just the employee role. Also, someone to use this opportunity to set up this index speech. As administrate oars, index, view hearts, I'm first going to sit upon authorize on top of this one on. Then I'm going to specify the role. Rose aren't equal, sir. Equal opens string on, then. This is administrate tour. So only the administrator should be able to get to this index option inside off the leaf request Controller, however, were already authorizing everything. So only a general or generally registered person would be able to access something that is not specifically for the administrator. All right, so you can mix and match. Do you could have done the authorize over each action, which would have been busy work. We can just author as the entire control. So you have to be loved being are authenticated firstly, but then specific ones for particular rules, we can just put this one right above it. Turn. So then, for this view, I actually have a vision where when the administrator goes to see all the leave request, they're going to see maybe a total count off leave requests for the period. They're going to see the total number off pending requests on. Then they're going to see the total number off. You know, rejected requests on may be approved requests. So they're going to be seeing three different figures when they land on this page on. That is in addition to the actual list off requests that need to be action. So to get a customized view like that, with all of those statistics and so on, I'm going to be creating a view model that is geared towards specifically towards viewing that kind of data. So that's another case for why we have you models because I want to go into the models. I'm going to bring up my leave request VL file on, then remember, I'm just using one file and in this one file have many classes. That's my pattern. Other people me create a different file purview, Mother, that's fine. But I'm just keeping it consistent on I'm going to say public class on, Let's say admin view or I mean leave request view, view VM Alright on. I'm making this explicit because then I may have on admin leave, request edit via more detail vm different from the regular via so I mean, I'm just making the class name explicit so that I don't make a mistake when, when crossing the lines, um, I'm going to just use this opportunity once again to the set up the map ings. Remember, if we have a view model and the view mother needs toe mop to a data class than we have to make sure that we're representation. But I really don't think we need that mapping right? No. So I'm going to build it out and let's let's see if we need that mapping. All right, so this is going to be showing statistics. So this would be the first property for me is an integer showing total request. So this will be the totally off the requests in the system. And I just duplicate that because I want for integer values have total requests. I have approved requests I have pending requests on then I have rejected requests. All right, so then these are four values that I want to be printed to ST some just sitting or properties to mop for each one. But then, in addition to seeing these properties, I also want the list off. Believe requests in the system. So, like we've done in the past, I just create a list off type leave, request VM on this would believe requests. All right. And then we can see Get sit accidentally duplicates of that line there. Right. So we have a list. I we're calling it leave requests. Oh, I forgot to meet this public. So our public least lead requests a year ago. So it was agreed. Or just know those overseeing its not public, any hole? No. I have my view model. I can no start doing some gymnastics and some creative things inside off our my action before I load up the model and send it off to the view. So I'm going toe Firstly do Ah, quarry where I'm getting requests, or let me be explicit on this. They leave requests, and that's going to be equal. Toe underscore. I saw on a square leave request three pull, not find. All. So norm retreating all off the leave requests in the system. Now that I have all off the leave requests in the system, I can query to find how many have been pending home and have been this home. Any have been that because already made one call to the database. And no, I have all the objects I can run the math on the objects. They had two options. He could either go to the report and set off form shown cause for every single one, so you can get coned off approved ConEd off rejected on. But then each time you write online, that says the request report dot find all which is going to make a database called that would have been four database cause to get four numbers. Sometimes you want to reduce in, um of database, cause So instead of doing that, I'm just getting all the leave requests, and then I'm going to use this object having done one day, Toby, start to do my mouth so I can say something like on. Well, before I move forward, I'm with the Muppets. Someone to say Vier leave requests, models. I would be equal toe mah per on then mop er is mopping toe a type off list. Leave requests the m All right, so we're mapping 12. The stuff leave. Request the M and what we're mapping to that is the leaf requests that we just retrieved from the database. All right, And then I just add the missing references. Yeah, so home or red lines. So know, whatever I'm going to be doing, I'm going to be doing with the model. So here's what I can do. I can say something at Vire Model is going to be equal toe add mean view. So we just created the admin view, sir, it's good to be goto a new instance off this class. And then I opened my curly braces which alos Muto line by line, declare each property. The first property I want would be Let's say total requests is going to be equal to, and then it's supposed to be equal toe all off the record that I just retreat. So the total requests would be all off the record. I just retrieved, um, so I'm going to see leave requests. But then remember that I have the models. I don't want to be interacting with this object anymore. This one was just to get the data. Now it's mopped to my view model, So I'm going to be doing everything else with the view model. So leave requests model dot and then I can just say count because the total number of requests would be the total number of records I just retrieved. All right on, then. The next one I can see would be approved. Requests I can see approve requests is equal toe leave. Leave requests. The mom reliever quests, model dots. On day, I am going to put on a condition I went to see where you with my arrow. So start of my loved X person on my condition would be approved is equal to true, so it, through approved, is equal to true. That means that it's approved right on. Then it is seeing something that I cannot implicitly convert type off innumerable meaning this is still going to get a collection? Because, no, it's if there were 10 here and there were five approved in this is returning the list off. The five approved, not the number five. I needed the number fire. So after filtering all what I want on this list, I can see that Count Andi on this time. Sorry. It has to be Brie, apparently. See, So in this situation is doing a count against the direct collection. Right in this situation is doing account against, uh, slightly modified set. So this were claws and any other lambda expression that you might add. So filter wrote or modify the list. Before you do account, it's going to change which one you say going to have to use the phone function instead off the cones as as a property. All right, so you can be mindful off that. So if you do a dark continents a red line, it's more than likely seen that you need the function. As a matter of fact, you could actually just say cones and use the lumber expression. All right, so this would actually look in the collection on and you're seeing I want. Account off all the records that meet this This, um, condition. So you see that there so many ways that you can do this, that it's very, very flexible. Second, I've done the where clause and then phoned account after the fact. Or I could just use the cones set up my Lunda on that those the condition Andi filters don't and into value telling me how many records met that condition. Alright, someone to press forward with this variation off the cone. So I'm going to do that on then pending requests would look very similar someone to copy this again. But then this time the condition would be pending. Would be that approved is no so remember that when we created the data class for leave request or I can just look in the VM approved is on no level. So when we put the question mark against the bull, that means it's notable, which means he can be true. It couldn't be falls, and it could also not have value. So technically, when you apply for a vacation or whatever, it would not have a value in the approval of slot because it hasn't been approved not being approved. Means has been rejected, but it hasn't been approved, which means it's not true. So it's in another state. It's waiting. So I'm just going to use that middle grown for the yes or no, which is the null to say that. Okay, nobody has put any option on it, so it is still pending, all right, And then the final one would be rejected. Requests someone to see rejected requests are equal toe on. Then it's literally just approved requests backwards. So it would be where they are false. So once again, if it's approved, that means that is approved is equal to true. If it's spending, that means nobody has puts the approve stating that through our falls on, then if it's rejected, that means somebody has put it in a far state on. Then the final thing for this view model would be leave requests. So actually that appeared because I just pressed control and space. So it just filled in the line because he knew that the only other thing that could go there so that visual student makes it so easy to be efficient. So leave requests, is waiting on the list off type leave request VM on. That's for the leave requests coming from the database, which we just did. I'm upping for here. So for leave requests, I just need to pass in the actual DR Collection that we'd mopped earlier on. That is our model. So the view modern made it easy for us to just inject our own custom, um, properties that we want Onda, whatever actual data we want on, then we're going to just return it to the view. No, in previous exercises, when we're about to generate the view who are very picky when choosing which, um, view model to use the model, they are to scuffled the template for the view. So in this situation, I'm going to use leave requests on. Then we'll modify it toe except the admin leave Request VM on. We'll go through it step by step seal, understand what's up. So I'm right clicking view on them, adding the view on then I'm choosing the list template because I wanted to generate the table form. Yet I don't want the busywork off trying to do the table. So the table for me is the harder part. So I'm just going to do a list on the list is going to be off type leave request VM satisfying leave request VM on. Then I had and no we have or templates. So I'm going to I want to leave the create because I want to give the administrator their ability to submit a leave request on behalf. Often employees, I think that would be a cool feature. So I'm going to leave the create button, but I'm going to modify this. T not have a model off the type I innumerable leave Request VM. I don't want a collection. I just want one instance off the create leave request VM. So I'm just going to change that old admin leave Request view VM Sorry, Onda, that is or model. So if this is our model, that means we have access to everything inside of it, which means no, we have access to the collection off leave requests, which means that our for each loop needs to be looping through model that leave requests this is already generating called that knows about leave requests so that we don't need to make many modifications there after all. Right. Another thing that I'm going to want to include notice that it's saying, requesting employees that I D. I don't want the i d off the employees. What I would want, though, is employees. Uh, well, it looks like I need to go and modify my few model because I'm not making representation off the employees on. I'm not making represent where I do have the leaf type. So I need to make representation off the employees object. So that means I need to go back to my view model, which is leave request to be AM Onda. I do. Oh, it's requesting employer. Sorry. So the property, the property was, um, misleading me. So it's requesting I Okay, so it's already there. How my body. So it's requesting employees dot Andi, I want the first name. Andi. I can actually just put the full name in this entire. So it's requesting I employ you. So in this column, it's display the requesting. I am requesting employees first name Onda. Last name. All right. But I remember in a previous exercise, we would have needed to go to the data class and made the includes. So, you know, as I said, your court evolves and then you see something. And then as you gain more experience, you see that something is going to happen before it even happens. Because I just foresee this giving me the null era that we would have encountered before. So I'm just going to go back to my repository class and find the function that is getting all the leave requests on. Then I'm just going to tell it to include some distance of brake line on. Then I'm going to see dot include, which is then going to prompt me toe at a library for a darknet into different word core on . Then I want to include que duct employees or will requesting employee as an object also want to include? They approved. Krul's approved by right approved by was another employee object that I had on. I also want to include leave type. All right, so then when it retrieves this data, it's making sure to include all the details associated with any other with any foreign key required that is there. So I'm just going to take these three include files on. I'm also just going to put in the find function on. I'm going to change this function from find to first or default. So we did all of this in a previous activity, so it shouldn't be foreign. If it is, that's fine. You can review that previous activity where went in depth in explaining what it is that we're doing here. But once again, we're just making sure that when we retrieve our records were treating all the attending details off the foreign key record, smaller from all the tables are requesting Employee that did this time from the employee table approved by is also coming from the employee table. So we know who is requesting we can get their details. Who is approving just in case. It's not just the admin user, because we could have other users in an admin role who cannot prove they want to know who approved the vacation are projected it on. We have the leave type. All right. So back to our index. Um, and eso just going through and cleaning up. So we have the start date, the end it we have the leaf type name, so then they will know which leave type name, and once again that would have probably given us that no exception. If we didn't meet those adjustments, the date it was requested, the date it was action on DSO. I don't want maybe these details listed out in the table. So I'm going to take all the date it was Action and action means that it was either rejected or approved on. I'm going to remove the approved by. I don't need to see who approved it on the I'm going to get a bit fancy with my display for the approved section. So I'm just going to change all the labels. So you notice that because it changed the view the view model from our the model that's this is using from the leave requests data type toe this admin leave request, which has the leave requests in it. Obviously, these properties will have some difficulty being much because they're generally maps directly to the model. So if you get those red lines, that's fine. You can actually just clear the moat on writing your text. All right, so for the first hitter, I want this to see employees name. That's the name of the person making the request. I'm going to see start so actually can just take out some off the cord on just put in the static text. So start it and it leave. Type the day it's requested. And I leave the reports that because sometimes it can inform hole on that vacation request Has been there waiting to be optioned. Article the date option header on article the accrued by hitter. So we have 123456 columns on Go on a near this. See approval status instead. Off approved. So this is going to say approval status. All right, on then we have 123456 Good. And then to make it a data table, I just put in our i d tbl data. So I'm going to make one more adjustment on this screen. Andi, that is tool based on the value off the approved status. Whether it is, um, you know, it's approved, pending or rejected. I want to print, like a little card or a little pill that will say, Okay, this is it. State and the color coding would kind of suggest what it is, Right? So bootstrap has what we call badges, and I think we used budges in our previous models. So I'm going to just show you how the budget looks on how we can use O. R. If statements and Ari's Accord toe know which badge to print went. So I'm going to remove this line, and then I'm going to see that sign. If starting up on your statement on then I'm going to see if I attempt dots and then say approved is equal to true. Now the thing with bullion, you could always not have to see the true. We could just say if item that approved but in this Mirani into our problem because, um and then their visual studio sitting that that's illegal because it has the no state. So you have to be very explicit when you're dealing with a notable bull. They have to see if I turned out a prude is definitely true. Then I want. And then this is the court for a budge. So I'm seeing spun class budge on Budge Dash success, which gives us, ah green budge with the word approved that I'm going to say else if sorry as if and then the new condition is that I turned that approved is equal in tow falls. Or maybe I could have just said, if not, But I'm just being very explicit on. Then I'm going to see instead off approved, I went to see rejected. And then this one is going to be danger because I wanted to be a red batch on. Then I'm going to say something like else. So else it's spending. So if it's not true, it's not farce, then it must be no on if it's no than its spending. So I'm going to set that one as a warning to say, Hey, you know, give this some attention, So I'm going to say pending approval, All right. So as it stands, I don't have any and he leave requests in the system. I mean, we haven't set up the creation are anything as yet, so I'm just going to go insert one inside my database manual is I'm just going to go over to the table. Right. Click view data on that. I'm going to insert one using the data I have here. You don't have to do this. I just want to do this so that I can give a visual representation off other word that we just did on. Then in the next video, we'll start building boats, more creative things. All right, so I just put in a rule. I'm just showing you. As I said, you don't really have to do this step. But I just put in a role with one off the user ID's that I have put in some fictitious start and indeed, one of the leaf types. Andi, I just feel that also date action is not knowable. So we probably want to change that because, well, the until it is approved or rejected, then there's no date action, right? So I'm going to be making that adjustment to the database also. But right now I just want to stop some visual off. What we just put in on this is only part one. So we only spend all that time sitting on the view model on setting off the index, the printout for the index speech. We have not put on the budges on the part where we're showing the numbers. We haven't put on that part as yet, so that's going to be in part two off this activity. However, like I said, I want the visual, so I'm going to go to views. Find my Leo Haute on. Make sure that my link that says leave applications points toe the cards place. Understand the copy one off the existing from paths on. Then this is going to be to leave requests. All right, so just do my bro's earning And then it was assessed our work. All right, so now we're going to go to manage and click Leave applications on. There we go. That's our admin listing for leave applications. However, employee name started Indeed, the leaf type being requested the date it was requested on the approval status, which is pending. So let's just test this also, if I go back to my data table and I'm going to just meet the money watchin so right no, it's is approved is no. So if I change this store, I can just see one, which really is true in database. I'm going to go back on day refresh. So reloads the later from the database. And no, it seemed true. It's giving me approved on just the same way. If I said zero instead, which is the same US falls on. It made that updating the database it's not going to see rejected art. So that's a nice, um, niceties in tow. How hole we can contextually print or a little bizarre elements in the next X in the next part. Off this exercise, we're going to be pushing down this view a bit, So this greedy is going toe up here, lower down on the page. But at the top, we're going to have four cards or four sections that will print the numbers for each off the leave request numbers that we would have calculated and put in R V M. So stick our own on this is to be continued.
39. Employee Leave Requests Module - Setup Admin Index View : Hey, guys. So we're back, and we're ready to diving in this lesson. We're continuing our activity or setting off the admin view for them to view all off the leave requests currently in the system. So the next thing I'm going to be doing is setting up some visual representation. Zoff. Just some statistics to show them. You know, I tackle on so many leave requests are pending. How many are in their system at all on? We'll just set that up as we go along. So back in visual studio, we're going to be using bootstraps cards. So this is my visual representation off choice. Um, So if you go on the bootstrap, not calm, documentation is get bootstrap dot com, go to components and look for cards. Then you'll see that they have this card looking, um, representation so much, you're going to take this. But what I really want is the number printed in one section on the type or a tug legal printed in another section for it. Right. So I'm just into minimized. Look, I'm going to borrow this scored, All right? So that's the core that generates discard on off course, I'm going to modify it a bit. But then here's the thing. I want four cards printed side by side going from left to right. So I'm going to use bootstrap screed, lay old system and it's pretty easy. So I'm not going to go to the documentation. I just walking through it as I do it. So I created give. I give it the class role. All right, so actually allow you to kind of create tables in using just dips. So this represents literally a role left to right. Continue. No. And then inside off this rule, I want that give on. Then I'm going to give this div a class off call Dash MD Dash three. So I would have made mention already that the call MB on the number that's really seeing. I want a column for medium size screen off size three on three here presents three off. Ah, potential 12. So from left to right on any bootstrap screen are in a bootstrap. Continue have 12 species that you can fill on. Then this is the width off the space. In other words, after 12 this one live most take up three. Andi, I want four so 34 swells. So if I have 43 spaced gives representing columns, then I can fit four gives our for bits of content side by side going across the screen. Right. So a little math there. Nothing too complicated. But inside off anyone off these columns. I want my cards. I'm going to take this card cord that I just copied on pieces inside off the column. Now I can start modifying this card. So first, they don't want that image. Someone to take all that emits section on, then in the body on I'll just bring back the documentation. So this would be the title. This will be the text on. Then they give us ah, sample book. So their notion that you can put almost anything inside it attack the card. So I'm going to instead make this and each one tug which is going toe have the number on then this is going to be the label seeing what that number represents. So in visual studio, I'm changing this from H five to each one on, then instead offerings in the words car title. So notice it's still going to be inside a gerontocracy at sign model dot on in the first tally. I want to show would be total requests the total number of requests on then for the text and then mistaking a while to save. There we go. So then inside off the text, I'm going to change this some content, something something, something on I'm going to say at model. Well, no, that's that's inaccurate, actually. Should be doing the display for or display name for so I can say at this play. Sorry. I'm sorry at html displaying the enforcer. Me this copy, That's I don't mean that mistake again. So I'm using that HTML talk helper that would print the name tag. Given in the view model, some would have to go back to review model and up the that. But this plane name for on then inside of this, I'm just going to set up a lambda Expressions. So model on then, eh? Put the iro and then I say model dot on the element that I want. The discipline in four is total requests. All right, so that means no. In the view model, we have to make sure we have the display name for total requests. And then I can just remove this button as almost all factor went to me. This an H five instead, off R P tax. I'm going to say h five instead of p. I wanted that bit bigger than just ah p tug. What? We'll see what it looks like. So this is going to give us one card on. Then let's preview what the old puts off that really is. So I'm just going toe, refresh the page, all right? And that's what that will use. So we're seeing the number one being printed and then we're seeing the total requests. So I'm going to me toward restaurants before we we look back at it. So the first adjustment is that I'm going to copy this column. So this entire div from the column mmd three. I'm going to copy it, and I'm going to paste it four more times inside off the if that is the role. Or three more times Rather. So now I have four cards, one for the total requests. 14 approved requests. So I'm just going to change the molds. All right. 14 tending. Or maybe I should actually see pending first right. So you see that proved you see the pending. Sorry. Then you see the approved on, then you see, they rejected. So I mean, you can let out whole. You think, Um, it would be best for you. So then Rejected. All right, so we have four cards printing old, the various, um, statistics for our leave requests in the system thus far. Andi, Then you would also notice that there is very little space between the cards on the data table. Sergeants put to be our talks to put some daylight between them. Ah. Now, I can, um, set up a section here where I'm wins a print. Um, each are so put on, each of which is a horizontal rule. That's just a line on. I went to see each one. Um, leave, request log. All right, so that's a log off all the leave requests. Currently, you know past prisons and will not future, but so I'm just sectional izing the pizza. It looks a bit more palatable. I'm also going toe put in like some, um, some things to make the text bigger. Better looking. So, like the number. I don't want it still be left. I don't want the text to be to fire to the left. So for the dif class, that is, um, Cardiff class card body. I'm just going to put in another bootstrap class as his text dash center. So I think even do it that that deliver than everything inside off the div that is text based will just be center line. If not, then we'll have to put it in the individual elements. But let's try it for no on dime. Also, for each one going to put in visual number, put in colors that kind of visualize What's the status? So, like, for instance, pending, I'm going to make it on orange buttons. I'm going to see on orange number. Sorry. So text dash warning. So give are in sticks. Um, approved requests that one. I'm going to see text. Thus this one is approved. So this is success. That's green. Text on. Then for projected, you could see text dash for danger fixed. All right, um, so I know that we could have style. This story is probably used alerts instead, off using a card feature, you could have used the alert feature from Bootstrap Andi put your content in saddle. Are there so many ways to do this thing? I'm just showing you one option and letting you know you have other options. Use your creativity to yield what you want. So the next, um objective? No. Before we refresh answer, your work is to make sure that we have proper display names for each property. In our view models, I'm going to go back to this view model just holding on control and clicking on. Then I'm going to set up these annotations. So this would say this play Onda name equals on. Then this is torta. Number off requests, all right. And then display is going to require some data library inclusion. So what I'm going to do, just go through and do these off camera? Um, and you can pause of you here and continue for yourself. Are some done with my annotations? And so I'm just going to go back to the browser and reload the page and see what it looks like Art. And there we go. So now we have for like, a nice table table section showing us the number of requests pending, approved and rejected on once again. These are the display names that I would have set up in the view model. So you know they're printing or it's nice and cleanly. Everything in Central and everything looks a bit more uniform. The colors are kind of guiding, or Sesto, you know, the state on everything on I mean, this is not the best. It's not perfect. It has room for improvement. But of course, you have your own flurry of your own style. I'm sure you are coming up with another design that probably makes this one. But but the concept that you would have um gained from this lesson would allow you to be more creative than I am being right now. Off course, this can be cleaned up a bit more because then you can meet this this link look a bit more attractive on you can take all the word in that. So I'm going to do those things. But I'm going to do them off camera. I want you to get the practice off doing it yourself, knowing what I just and as always, if you run into difficulty feel free toe, you know, drama line, contact me and I'll be ready to help you
40. Employee Leave Requests Module - Create Leave Request Part 1: Hey, guys, welcome back in this video. We're going to be setting up the leave application request form for our employees. So in other words, when an employee gets to the system and they click apply for leave, they should be seeing on application form, where they will be able to specify the type off the that they would like on the period during which they wanted by specifying the end date and start date. Now, if you quick adjustments that I would have made off camera on, I'm just showing them to you so that you can replicate them. So at each interval you can pause the video and replicate them. But I don't want to spend too much time in the video doing them because they're basic things. But for one, I set up the apply for leave link to point to the controller off leave. Request on the action, called Creates, will be configuring inside of the leave request controller the action for create, which was what will render the form for the application for the employees. So that's one change that I have made so you can pause the video on, go ahead and replicate that but moving on. I also meet our leave Request view model. So for the leave request view model that was there before I set off some data annotations are set up. Some display names on some validations are over the dates. But I also created a view model specifically for or create form this create leave. Request view model will have validations for the start date validations for the end date. A list off select list item called leaf types. Andi individual value for a leaf type ideas. So the validations for the dates would include Well, one, we have the display. So it's is start it, um, us two distinct words on, then we have it as required. And then we're specifying that we want the data type off date. So that means in the form renders, um, the input today that I will be date by default, right? Just because we're specifying that it is the data type that we want. So that's therefore both this starts and indeed on then the public. Sorry, The list. The innumerable off selected list item called leaf types will hold all off the leave types coming from our database, and we will use it to populate or drop down list. So the context is that whatever leave type is in the system is stored in the database, and if it's stored in the database, then we need a way to dynamically display them to the user, cause we don't want to display to one there five or display one when there more than one right? So if they're five, we should display fire if their stand with the dispiriting. So when the person lords the form to create a leave application request, I leave requests. The drop down list should always represent what's in the database. Andi, The drop down list is also called a select list literally. The talk for a drop down list is select on DSO for each item that appears in that list, we call it a select this item, so that's where we have that there on, then The I. D is really what you select. So you select you read text and you click the text that you can read but in the back. And what is really doing is mapping it back to the corresponding I D in the table that it's coming from on. That's what's really getting stored when we create a leave request. All right. I didn't include all the other fields that are in the view model like, um, the requested a date action because we will be sitting those in the back in won't be requiring the user to set. Those are So I created this view model just specifically for the leave request form on notice. It only has the fields that are relevant to the employee who will be making application. So once again, you can pause right here. Copy that off on. Did you can get up to speed with? I'm going to continue on and by no, this should be very easy to understand and replicate. So back in our control, we're going to start sitting up or create action. No, it's easy enough to just right click the view and generate the view with a create template for the creative you model and it will generate view. However, we did specify that we need a selectively star drop down list which will have items stolen from the database, which means we need to create this view with some amount off data andare technical term upon to know for doing that would be to load it up with our model toe, get a model loaded up with data and that create the view with our model in mind. So the the data that I really require would be the leaf types someone to save ire leave types is equal toe on the score Leave type report so off course, if I'm getting leave types and any leave type people So if you haven't already done so, then you can pause right here on do this also. But we need to make representation for our leave type repository. Some including the dependency I'm, although the dependence is that would have included already some including leave type repository. I'm getting it into the controller and then I'm initializing so you can pause right here on . Make sure that your coat looks just like this. All right. On you can challenge yourself on pause a video and try to do it to yourself without looking at my court. And then you just compare afterwards. This measure under at track. That's a good way for ET to improve. But pressing ahead. We save ire. Leave types leave type rifle dot on. I want all off the leaf types currently in the database. All right, on, then we can see var, and I'm going to call this one leave type I terms leave type items, so leave type five times. No is going to represent the select list corresponding version off the values coming from the database. So I'm going to explain this slowly. We already know that this is coming from the database and if we're over over the the variable, we see that we're getting a collection off time leave type. However, our model requires on innumerable, which is just another collection. So you see that a lot of collections or collection types in C sharp eye, newer bike wearable collection, I at least a century, such are. But the point is that it requires some collection off type, select list item. But we know as the programmers that the select this item should represent the leaf type. So we need to do some form of conversion from ah list off leave type toe our list off select list item so and nice quick way to do that using link or, in the end, to different work extensions which work on collections, By the way, we can say equals. Then I get my collection, which is leave types that I want to say that Select Open up my braces, start a Lambda Expressions. I'm using Q as my Lundell variable. And then I can see that I want to select each item out off this collection in tow. A new select list item data type. All right, on. You may need to include a library right there. Second pause. Make sure include a library before you press ahead. But what I'm saying here is that I want to interrogate this list that I district you from the database on for each item in there. I want to select the data into a new select this item or represent the data's and you select this item on. Then I'm going to go ahead and assign the values to the properties off the select list item . So a select list item on I just break in line so we can see exactly what's happening. Is control space on then? There. I see that you have text I am following. Those are the two. More important, once the text is what use is going to see in the drop down list on the value is what the system will be tracking on making sure to store are so text that's you're going to see in the drop down list would be cute dot on Remember Lambda Variably excuse O que now gives us access to the different data that is coming from the objects are represented values in the database. So the text that I want displayed is the name because I want when I quit the job only something the name off the leaf type for a selection. However, the value that we're tracking is going to be cute dot i d which is the I devalue off that corresponding name. No notice. I I'm getting a red line and that's because Valionis bear string i d is an integer so I can to save docked to string, which is a function that can quickly convert. Um, you know, it's quick, it it just changes the indigent toe a string. He works nine out of 10 times. Sometimes you have to get more fancy, but that works nine out of 10 times. So no, I have a list off and if I just over over my new variable, I see that it's an innumerable off type. Select this items on this looks exactly like what I declared inside my view model. So no, I need to create the view model are creates an object off the view model seconds. A fire model is equal to a new instance off create leave requests the m on. Then I'm going to declare this or initialized this object tohave the values for leave types being equal toe the leaf type items that I just created. Then I use my semicolons and oh, my model is created. It's off type leave request VM on It has the data that it needs at least a load the form and so I can pass it into the form afterwards. So no, that I've done all off that I can go ahead and create my form. So Iraq view I've you on, then I'm adding I create, So it's elects the template create. I'm using the creates leave request the m on. I'm going to remove the data class object. So the data class data context class I would have used for sometimes and I would have removed it for other times. The thing is, it works best when the values are The data as being passed are usedto generate. The template has some mapping relationship with the data table. So this create leave request doesn't really have that mapping. I didn't call to the database and then find something to mark directly to it on dso I would spare myself some air about has no key if I just remove it. So if you fail to remove it and you click add, you get a has no key air or something off that start you can just go back on you can just remove it and then you can go ahead and press ad, which then gives us our form. So we have a form, um under me, we can go ahead and remove the eyesores and you know, to eat this form a bit, but I'm going to focus on what is being a rendered. So we have ah, text box for our start date or some input for our start date or some input for indeed it on . There were some input for the leave type I d. All right? No. Remember that the contextually based on the field that is being prompted for the type off. The input control will be different on this type. Might be determined by the data type that we specified. So in other words, when this form is created on, we have an input for started. The input type when it's rendered, is going to be off type date. All right, so we'll see the behavior off that in a few. But I'm just going to make a few changes here where I'm going to cheat. Take this form group that's has, um, far the leaf type I d. I'm going to take it, and I'm going to put it at the top. That's so this is the first section off the form that I want rendered. Um, I want the calendar controls. Sorry. I want the dates to be side by side. Alright. Someone to create a live ongoing Teoh, give this Dave the class role, and then I want to give it to other dudes. Andi each live is going to have the class called MD so called dash. Andy and I wanted to be six. I want each column to Philip half off the space off the roll, right? Remember that. We have up to 12 on by saying six. It means I want six off the 12. And so I want to take up six after 12. So I just didn't want duplicated it. And then I'm going to take started it and put in the 1st 1 on, then indeed it and put in the 2nd 1 So the expectation is that when this form renders, I want to have this input on. Then I'm going tohave side by side two text boxes waiting for input all before our create button. All right, on then. This is called MD four. So you notice this is taking on four spaces off, 12 on, then off the four species of the 12. I want this one to take up half and this one to take up half. So I'm just going to expand this to maybe, uh, this was That was four. I'm going to put it to it. So the form takes up more space. All right, on then, Before we even look at the work we're doing or have done so far, I want to make an adjustment here. So this input is just on input for leaf type I D. Which is not really what we want. What we want is a select list are drop down list Now there are multiple ways to get a drop down list. Um, don't of chosen path off little resistance on DSO. We're going to do some modifications here to get our select list. Look, um, to show up instead, off this input so you can pause here, take a look at what is rendered on. Then you can come back and then we'll change whatever is rendered by this, which I guess just a text box with some input for a number. I'm going to change this to look like a drop down list. So step number one is removed all off that in fortitude court. So we have the labels. Sure. Art and ofcourse believably sprinting out whatever display Ning were put. So for leaf type I d. I said that I want to print the label leave type. All right, that's fine. But then instead, off that input, what I'm going to use is an html helper. So I have that sign HTML and I say dots drop stone list four and then open breeze on, drop down list for and most other. Um, you know something, Force. They have textbooks for your radio box. For you have all of those, um hmm. Helpers that give you control a form control four, Right. All of them take alumna expression inside years. Um, as I've been doing from day one, I use my cue. Was my London verbal on and I say q dot on then I specify which element from the more model should mark back to this drop down list. So the elemental mapping is for the IV type i d. Now that I'm mapping the element, I need to tell it where it should bring the list off values from so whatever it should displayed to the user. All off the, you know, the things that we just dynamically loaded and eat a pointed in the right direction, somewhere to say. New select list. So we saw that we have select list item, but we also have a control called select list or a data type brother, our class type called Select lis. And then this select list is taking a list off. Select list items are a list off attempts. So the list off I terms that I'm passing into the select listo populate. The drop down is coming from my more model right's capita and model, and I say dots on. Then it is the list off leave types that I literally just loaded up in my action before passing over to the view. So leave types inside. The more model should have the list off. Select list items on in the select list items has two properties text on values. So we need to tell or select this. Which one off these two properties should be the text and which one should be the value. And I think it's clear cut at this point that takes this for text and values for value, right? So it makes it kind off uniform and you, Andi clean when we use the selected list items, so I'm going to say comma value for value. So so the value tracking should take in talk on the value data property from anyone off these objects in the lists that I'm using, making reference toe on the text property should be coming from the takes property from anyone off these values that I am alluding toe. No. After doing all of that, I'm going to say comma again. So but just make sure I'm closing on my braces. I think I'm missing are brace here. So that is. Oh, I think of an extra brace here. All right, good, sir, about that. So we have new select this item on, then we're passing in. We'll have open brace that we have the collection comma the value property on the text property on. Then after we close that brace, we have comma that I'm going to set up a default message. So my default message is select leave type. So when the former unders, that's the first thing that's going to be in the drop down list telling them to select from here on, then I want to see a new on open up ah, section here where I'm going to defend some HTML attributes. So the attribute that I want for this job don't list would be that it has the class remember classes and attributes that this is an html tug on. This is an HTML attributes in that tug. So I'm saying I want at san class, which is when to represent this very attributes and I say equals Andi. I wanted to have the same class that every other form control has, which is formed Dash control, which is our bootstrap class. To make sure that it looks like a bootstrap form, um, elements on then for my button, understand to me at this bt and dash block. All right, so bt and dash block, maybe for the action. I don't need backed a list, so I'm going to sit. I'm going to leave that therefore. No. As we work out our, um, application a bit more because this back to list would try to roll back to the index function inside off our entire application, which is really reserved for administrators anyway. So when we were kowtow, we're going to show the employees his own index page, meaning he goes and sees all she's leave our applications and then can make a request if he wants. When we work on that view, then we can change that lead. So until then, let's leave it as it is on, understand, to save all the changes or control shift and s on, Then I'm just going to load up my browser link on. Then let's see what this looks like. All right, so now that we've loaded it up, the first thing I'm going to do is stick apply for leave. And then it's telling us that we need to log in because we did say that everything in this entire controller needs to the authorized so they won't let me through some distant toe. Use my default password for this user, which is be outside W or org one. All right. And they're telling me I cannot be the password. I just do that can cut on time, any hole. This is what the form looks like, right? So we have our leave type on. We have that drop down list, which is exactly what we wanted on. But let me just inspect elements. I can show you what I meant by the text versus value conversation. So we have a select list, right? So over chord that we said each html that drop down list four. It generated a select tug. It has the validation built in all of those things being generated when I dropped on this list. Notice that you have the option. So for each value coming from the database generated the option on then the options have some text that is visible on some value. Each text as a valid option has a value on the text. So that's all seeing when we specify that we wanted this for text on this four value. This is what it was doing, really and truly, right? So if you have experience with select this than decision, I wouldn't before into what you would have learned always hold to generate the drop down list dynamically based on data from other places in your application, which is a useful on very time. Um, saving Neto have. All right, So the next thing that I want to point out to the fact that we have the dates side by side , right, So we did set up the rule on we told them that wanted either text box are either, um, inputs control for the dates to be, you know, to take up half off whatever species the container is. So the cool containers they come eight off possible 12 spaces on, then inside off that eight spaces were taking up six and six. Right? So that's why I can mix and much those called MD's to get nice, clean, green looking. Leal's are nicely olds, however you want them. No. One thing I want to point out is the fact that this already has the beat value kind of implied on. Then when I click in it, it's just asking me. It's prompting me to put in the date on. I get a calendar control, which is good because the last thing you want is somebody coming and actually just typing Freehand on, putting in foolishness for the bit. The don't side, however, toe a lowing the bro's ER to determine their control on I'm just going to jump over toe Internet Explorer is that the date control will look different for each brother. So this is Internet Explorer's version off that date control, whereas Chrome is giving the that calendar looking control now, you don't want that kind of inconsistency. You want to make sure that all of your clients everywhere are seeing one things. So this would be a good point, no to include, like a standard date picker that you know it will render the seam control across all browsers. So this is my goto a picker So this is Jake. Worry you i dot com slash date Picker on. This is my default goto one. When I trick in the text box, he just brings up that control, and that's what it will look like consistently, right? So I'm going to make this calendar control pop up whenever somebody clicks the text box. Now we're going to have to make a few adjustments, and once again, off words explain why, Andi, I hope you understand why we have so many Buchan forts at sometimes when we want our country certain things. But with the date I'm going to have to not let it render the beat a za type for the imports . All right, click in the text box. You don't have to follow me with this sick. And this Watch what I'm doing. Right. Click in the textbooks going to inspect on the start dates text box, notice that the element itself is It's rendered with the type off. Eat, right. So I did say that when we specified the data type in the model it influences the data type that is are the input type that is used in rendering. So if I want to use this day picker. The input type has to be texts. So if I look at view source, I'm going to see here. That import type is equal to text, not date. All right, so let's make a few adjustments and then get our deep occurs in. The first adjustment is to make sure that I have the script files needed for this. Collender. The one off the files would be the CSS files someone to make just in to copy this CSS for us is a bunch of other things. They're not absolutely necessary. They're really sitting for the demo. So this is our part off knowing what you need and what you don't need. So what we need would be the base CSS file here that will actually give our calendar that look and feel that we saw someone to copy that census file, go back to our project on go to overlay or file on. Then add that CSS file here. All right, so we have a new CSS file, a new Cdn link toe orgy. Corey, why next? We want to make sure that we have our script files on the to script files that are made reference to hear our little We need notice that this is a version off Jake worry. We already have Jake worry. But the thing is, sometimes the these controls require functions from a specific version of J. Query on we have at the latest version. Of course, I'm taking this, um, version of Jake Worry on. I'm taking the script file that is associated with Jake or you eyes. I'm taking them both. And then in my early haute, I'm going toe, put them underneath the other Jake worse after the Jake or is loaded up on everything that depends on things from that version of Jake. Worry are loaded. Then I will load my geek where, as a matter of fact, my script file here also has dependence is for that person. Of course I'm going toe. Put it even further below that. All right, so no, these script files are referenced. Um, there for the JIC or you I on then the next thing that they say that we need would be toe initialize the function that caused the deepika controls. I'm just going to take this block off script here. Copy it on then. Inside off our create. I'm going to settle a new section four scripts. So remove that Render section scripts And this section would appear underneath all of the script inclusions by default, right? So I could always just go ahead and say script, open up a script and start doing something there. But when the pages rendered, this script is going to get rendered inside off. Render body Andi. It's going to fire before the requisite scripts are are included. So I'm going to make sure that I render the section Army reference to the section that is here before I put in the scripts, I just say at science section on, then the name of the section is scripts open and close braces on, then inside off these braces. Now I can put my custom JavaScript cord, which, when the pages rendered, yes, it renders a body, and it renders everything here. But then when it gets to the section, you can leaves the laurel until it has finished rendering everything else on. Then it renders the script there, so that so that section, um, cold works. So no, I'm going to make a few adjustments. One I'm going to change the data type from date time, far from dates. I'm removing that DEET validation. So, no, it's just going to see Start date as a regular text box because I'm not enforcing that. It should be at the time. Yes, this data type is the time. But without the data notation, the form will render by defaults. Just a text box of the input will input type will be equal to text. The next thing I want to do is make sure that it points to the right elements or I know is looking for an element with the I. D date picker. And that's based on the demo. However, we have two elements here started it and indeed it's that need the services off the deep pickers. So instead I'm going toe give them both the class deep speaker. So I'm just adding to the class section off. Either input the class date picker on that instead off referencing the elements of the hashtag means an i d on element with the I D off. Whatever comes after Ashdown, I want elements with the class off. Whatever comes after the full stop. So it's a specify ideas. Hash tag to specify the class. Use the full stop. Right? Something full stop date picker. Look for anything that has the class date picker in it, which we just added toe These two controls on then initialize the date picker are the calendar control. So I'm just going to control shift s Make those changes save those changes. Go back to my applications. I can close the Jake where you are on Then I went to refresh and let's see what happens are so on the refresh Nall We can see that the date, the date enforcement, this kindof gone. No, it's looking like at the time it still kind of giving us the control elements that we saw earlier, So he would go to that drop down here and we'll get the calendar. But then if we just click in the body, we're seeing orgy where? So this they're still kind off conflict ing And that's because the data type, which is dead time, is still overriding the type. And it's not rendering the text. It's still rendering some dates type. So our burrows or is trying its best toe facility. It's that type. All right, So if I change this manually to text. They noticed that there would be nothing. But then when I do click J Quarries calendar is the only calendar that is being rendered there. All right, so we can we can look into that. We can probably do something like we can change in the view model the data type from daytime to just string. But in off course, you have toe make sure that when we're doing our operations and our mop things that we're converting whatever value to date time. So that's so sometimes miss much can occur. So, for no, I want to leave it as the time. Andi Yes, we have two competing calendar controls, but I'm going to leave it alone for no. At least we understand what's happening and later on, we can put in more dynamic court to handle the situation. But for no, we have our standard calendar control. If I look at it in Internet Explorer, then we still have that conflict ing thing because Internet Explorer's calling the Control is still trying to come up with Jake or so later on. We can change that, but at least for no, we know what is causing the problem, and whole we can solve it. Another thing I want to do is make sure that my date format is why, Why? Why? Why dash? Mm. Dash DD meaning it's must be year, month on, then. Day. I don't want it to be, um, you know, to cause any confusion as it is. So I'm just going toe inside the date picker function call open up to curly braces on. Then I think they have a property in date picker for date. It said, as did for much colon. On date, four months will have the values. Why y dash? Mm. Dash d d? No, just a little bi query can find it in the documentation. If you go back to the Jake where you are date picker and click on four months, they will show you the different formats. So the two wise will give me the four digit dates. The four digit year. Sorry. All right. And then the months and then the day. So I just wanted to look uniforms. So that's it for the visual elements. Next, I want to fire up the post action. What happens after the employee clicks create our request someone to teens text here from creates to request leave. No, Our quest leave is going to require some intelligence and off course once they click that the natural flow is for to go to the post action for or create. So in the next video, we're going to finish up the post action for the create on. We're going to be putting in some intelligence that we haven't factored in just yet. Some business rules on I mean, you may have a different idea of the business rules than I do on diff, you know, to implement them. Then we're good because then you understand the concept. However, when we get back in the next lesson, we're going to finish this up, and it will be submitting each leave request to the database.
41. Employee Leave Requests Module - Create Leave Request Part 2: Hey, guys, speaking up from where we left off in the previous video and just want to start setting off our post create action for leave requests and I'm just going to dive right in. So we're already in the controller on I'm phoned the the action. So the first modification to make is the data that we know it's going back in the ox at the action, which is off data type creates leave, request VM. I'm going to call it Model Soul. We're going to do a few things here just to make sure that our leave request is valid. First operation is to check if the model state is valid. So I'm going to just remove that comment and then I'm going to say, if not model state sorry, model state that is valued. So if it's not valid, then we know that we want to return the view. Now, here's a little trick that maybe you saw maybe he didn't see, But when we returned the view, we need to return it with some data. I think we had a scenario like that earlier where we returned the view, but we didn't load it with the required data, and so it gave us some no exception. In this case, it will return the view even if we passed about Model Model is not tracking the drop down list and items, so that means if I return it with model is going to return it. Sorry is going to return it with some MT. Data, right? So it's going to returning with an empty dropped on this, which is absolutely necessary. So then I have to make sure that I load off model once again. So I'm just going to copy this. Scored Onda. I'm going toe just load. It's as soon as we hit the post. I'm just going toe run that query because we have multiple places where it's going to return it. So I don't want Oh, put that worry inside the if statement and then have to put it again in the cat's understand one time on. Then I'm going to assign model dots. Leave type. So have model already. Some just putting repopulating leaf types variable with the leaf type items that we just got. So if it has to return at any point inside off the try on, actually, I'll put this inside of the track because that's the point of the track at you Tran operation on. If you have an exception, meaning if there's a database arrow, then he catches. It's right, so we try on, then we get all of the values that we know we need for the drop down on. Then we say, if the value if the model state is not valid and just returned the model and it already has the data that it needs that is clearly missing when it comes over, the poor start. So that's the first thing. So we're checking. If the modern state is valid, then we return the view. If it is not after that, then I want to start getting some data. So at first I want the employees on the employee who is currently lobbying. So I want Employee who is making leave request on a personal was making the leave request has to be the user who is logged in, so I don't need to track that in the form. I don't need you to tell me who you are, because the system already would have an idea of who you are based on your log in the only way our own that is, if I have your pastor than your credentials and I try and love leave requests as you. At which point that is probably your negligence or my trying to defraud a situation, not to get details off the person signed in. I don't need them to identify who their on a farm they would have already loved in. And they, having loved being, would be submitting the leaf request. Which means that I just need to retrieve the person who is loved being at the points that this request is going in someone to retrieve the employees using the user manager, which already included as a dependency on. I'm going to say something like VAR employees is equal to on the score user manager, which is my dependency identifier docked on. Then they have a phone. Chalices gets user a sink, someone to get user easing on. That is expecting some fire amateur off system that security claims claims princip our principles so inside that I'm going to pass our object or a class called user. Well, it's really act objects, so if I hover over the word user, then you see that it is exactly the data type that is required, which is that cleans principle. So I'm getting the user on. Then I'll just say that results to retrieve the actual data as this is an asynchronous function. So no, my employees will have on employees object. So I'm getting back the user who is currently signed in. So that's a nice way to retrieve the current user. You want the user whoever signed in during the session, they have a keyword that's is literally the word user. You may see it a little are a little more complicated because some people actually give it a fully qualified system, that security that claims that clears principle, that user. Sometimes you see that? What? That's fine. You can just say the word user. Eso No, I know the employee who is making the request. The next thing I need to know as to whether or not I need to tell him if this request his value is he's actually hurt his or her actual allocation, right? So I need to find the allocations for this user so I can say something like Bar our locations is equal toe on. Then we see on the score Leave a location on DSO. I actually don't have that dependency. So I'm going to have to go back on. Make sure that I have a dependency for my leave allocation Report someone to do that quickly. I will say I leave. Ah, location repository on this one is going to be leave. I look, I'm just threaded Shorten report on. Then I'll just put in the dependencies. So I'm just using leveraging the court that's already there to meet this process. Foster. So of course, if I'm going too fast, we just, you know, pause video on you just re type on catch up. All right? So no, I have that dependency for the leave locations. So let's try that again. So leave allocation. Underscore. Leave Alec Repo docked on. Then I can say gets leave allocations by employees, which is expecting some string for the employees ideas I can say get by employees. It was already created that function earlier on. Then I'm going to pass in the value employee dots. I d. All right, So I'm passing in the employees i d number. But then there's a danger here. What if this operation feels are if trying to retrieve that employees, Um, it was no so to spare mess if any. Um, errors are so on a I guess that's why you have the cat try. So they catch once he gets any of those arrows you can catch the exception on yet that object that you can just pass over to the view if you want to do a system error or something are imprinted onto the screen, which isn't necessarily the best case. But the point is, that's the point of a try catch. We've done it a few times and I'm just bringing you presento Why we have the track yet. So we try and operation, and then we catch the era. And if there's an error than we do something so I'm just going toe I'd hear model state dots odd at Model Arrow on. Then it's going to be gnocchi. But then something went wrong. I'm just giving ah, heads up that something went wrong with operation. Um not telling them the details necessarily. But for the 1,000,000,000 purposes, we can always observe this object. Any home we retrieve or employees, we retrieve the allocations that this employee has. And then we realized no, that it's all the allocations and it's not necessarily specific to the allocation off the leaf type that is being requested. So that tells me that I did another function in my repository to be even more specific. So I'm just going toe, go back to my repository for starting with Contra. So I, Levi location repository on. Then I'm going to duplicate this on. Then I'm going to see gets a locations by employees Andi type So on the allocations by the employees and the types of went to pass in the string Employee I d as well as an integer leave type idea on then in the repository, I'm going to implement that function, so I just wait until I get the red line here. Then I just over or take the light bulb, use the liable really on implement interferes on. Then this function is going to look very similar toe or get allocations by employees. Remember that we're checking for a period and they were checking the allocations, Understand toe copy. This scored because going to be a very similar bit off course, but this time I'm seeing find all where the employees that I d is is equal to the idea that's coming in on the period is equal to the period on. Then I'm going to say Onda, the Q dots leave I d leave type ideas. Equal toe believe type I d coming in. No, On this occasion, we only want one. So even if one record meets this this condition what's when that happened is that we're always setting up to get a list our collection. So it would be a collection with one. I don't want a collection with one. I just want one object. So to get one object I can change this were so first or default. So first, our default will always only bring back one object as it as it finds something that much is the condition it brings about the first. So even if you brought if we found a collection of things that much the colic, the condition, you will only return the 1st 1 If you didn't find any, then it returns. No, that's what the default means, right? So we're using the same Lambda expressions Were dis changing the function from were the first our default on, so I don't need at the list. So no. When I do this and I'm getting a red line here eso my red line is because Sorry, I'm returning. Once. I just went through the period of half telling that we're expecting one object yet I declared this function to be waiting for collection. So I just need to orbit the data types here, so leave allocation instead off a collection on then that does not much the contract. So I'm going to go back to my contract file or my interferes file and make sure that I am representing it's properly. No. After doing all off that I shouldn't have any problems. So I'm have leave allocation, get leave allocation by employees and type, which is getting one. And we just implemented it in our repository. Alright. So back in our controller, I'm going to change this verbally in from allocations toe allocation. So it's returning one record with the articular allocation that this employee has for that leave type. So Oh, I need to change this function. Right? So I didn't change the functions in the in. The controller needed no knots called that particular function. I was calling, but calling one get allocations by employees and type on them passing an employee i d and also model that leave type I d. Right. So I know the employees making the request and the model is bringing over the leaf time that is being requested on. No, I'm checking the allocation. No. Another check that I need to meet. No, is Are the number off these assigned or currently in the system for that employee? Is it greater than or equal to the number is being requested. So no, we have to do some month. I have to say you requested You know, between this fear than that pier, that's X number of days. Do you have that number off these in your allocation? As a matter of fact, I think I skipped ahead off a very important validation that needs to happen before we can start checking locations. And that's a very simple validation against the deeds because we have a start it. And then, indeed what? We need to make sure that the person is not putting a start date. That is further I had in the future than the end date. So before I even push ahead with all of this. So that just hit me a while ago that I missed that validation. No. The point of this exercise is that whatever logic you put in here, the validations those can make and break the system Those are little things that will cause big headaches. When you have a big corporation and poor validations that allow users to put two garbage into the system on then as the developer or the I t person in charge of the system, you're going to be the one cleaning up the mess. So it's easy. Just think about what can go around at the point off, entry on, then validate against those Onda. Try and eliminate or scenarios, right? So I'm already checking if the valid If the state is valid and I'm returning, I am. I'm I guess I can use this are Well, I'm going to check. Use another. If statement, I'm going to say if on day I'm going to use Ah, the time Compere So date time That object has something called it. Time compere Right on. Then their time compare. It takes two values. Who takes two dates so I can say model that, Andi I see something like started it So it takes the first dates that you want to compare to the second dates. I'm comparing the first day to just start date on. Then I'm comparing it. Toe model dots end, be it? Yeah. So it returns something that is less than zero. If it is earlier than if the date one provided is earlier than the two provided he returns zero. If it's the same date on any return something greater than zero. If it is, you know, bigger than so obviously we want to compare and just check if it is less than zero because nobody should be starting and ending it start is the day that you were wrote on Dwell. It shouldn't be less than it should be greater than zero, actually, because it can be the same date. If you only took one day, then you select the first the start under nd to be the same day that we know it's one d right. However, if it is that the start date is the 16th on the Indy, it is the first. Then we know we have a problem. So I'm just going to compare and say if that comparison use a result that is less than zero , then I want to return. So I understand toe return to the view, right? So we can have as many validations as we see necessary. So the next validation is going to be against the allocation set up. So no, I have the allocation for that leave type on. Then I'm going to see is the number off the is requested greater than or equal to the number off these in the allocation. Or rather, is it? Yeah, is a greater than is a greater than the number of these in the allocation. Then we would have hit another validation point or return. So for this one, let me just add the model state error so that we can print to the screen specifically, that's the started. It cannot be, um, further in the future than the end date. So we're letting the user know the rubbish that they did sorry on DSO were rebuffing and letting them know that that's is your arrow. These fixed that. So seizure makes it very easy to do this, um, calculation for the number off days between the start date and the nd's So the compare really only returns negative one if it is earlier than zero. If it is the same day on, then greater than one if it is if the start it is greeted done. All right, Onda. As I said that, I realized that I have a logic era right here. So we need to compare the date on the time to start date and indeed it on. We need to given Irwin. It is greater than one. Sorry about that. So I said less than zero, meaning if this started, it is earlier than the Indian, then we get less than zero on. That would be OK, but the problem is that we want when we want to detect the problem when the start it is greater than the Indy it on when that happens in this function returns the value off one. All right, so it's really the one that we need to check for on. Then return the error for the for the injury. So about two hour calculation for the number of days I'm going to say something like int is requested is equal to on then a simple way to calculate this would be to say, model dot starts did or other model that ended its since that's a larger value. It it's a model that Andy dot dit minus So have the bigger debts or what we know. So if we get this fire and we know that indeed it is clearly bigger than start it on, then we see my nose model dot start date that deeds on. Then after we do that, then we just outside of the breeze si dot days. So it's going to do. Its calculation is not just sorry. That's total days, so total days will return on into John. We can just look at interest since he returns the value of the current time spun in whole and fractionally. So we really want hold. It returns a double, but I wanted to be in Seoul. It's going to return some fraction, you know, maybe 2.4 days that maybe in a leap here, but we're really putting it into an integer on. So we're getting the red line on underneath this line off court because they don't seem that this is returning a double, but we're saying into an integer someone to implicitly cast it on interview by just opening our brace, writing the word into enclosing a break. So that's how easy it can be to cast between America values. You have double on one side you want into, John makes Eddie just use this technique to cost. So now we're getting but the number off is requested on. Then I'm going to check again to see if the number off the is requested exceeds the corresponding our location. So then I went to see if is requested is greater than a location. That's number off These right? So we're checking off. The days requested exceeds the number off these in that allocation record that we just retrieved from the database for that employees on the leaf type being requested on. Then if that is the case, then if this condition is met, we return the view. So just copy that, Andi, I had ah model state error to see you. Do not I spelled B. It's wrong in this area. When you despite that someone to see you do not have sufficient. These you do not have sufficient is for this request. So we're letting them know that you don't have enough days toe, meet this request, please. Dragging. Right. So these are kind of validations that really happened. When you click, submit and you get an error message based on some data you may have put in that violated the business rules are whatever rules application was built their own literally there just once again, a bunch off if statements, um, just checking for different things that the developer didn't want toe facility it are entertain. So after we do all of these checks, No. If he gets further than this, if statements then we can safely assume that this is a valid leave application. So then we can start the process off, creating a record in the database on doing the necessary deduction. So one I want to deduct the number off days from the actual allocation record on then once that number off, this has been the doctor. Then we inserted into the liver quest so we can do it in reverse order we inserted into leave requests on. Then we do the deduction. Either way, both steps need to happen, So I want to say vier leave. Request is equal to aan den I'll start off with a new leave request. So leave request VM on. Then this object is going to take values for the on Let's start. Start slowly, Let's say the employee who is requesting it's a requesting employee I d. We know this because we have the employees object and we can get the i. D. So the person making the request the person signed it was making the request. I know the requesting employee I d next value. We want to start date. So the start date is going to be equality model that start dates the end. It is going to be equal toe model that and be it. Then the next most important thing would be the approval status, which we know nobody has approved it. It was just submitted, so I'm going to say approved is equal to know. Come on, then. We said it requested. So the debt request that is dead time dots? No, because you just requested it. Just knows. I know when you requested System knows when it was requested on. I don't think anything else is absolutely necessary to be inserted into the database because I d get set once it's created, the detection would be blank. But then I know that there's going to be an arrow because the date action is, um, it's not Snoble. So we have to provide some some date value here. So we have two options. At this point, we can provide a date value tow. Avoid that, no exception. Or we can go back to our database data class. I just find it or data class for leave requests on. Then we change it toe unknowledgeable datum. So if we get this bully unknowable, I would have to change the date action. Also two notable. Right? So we have those two options I want to choose the easier one and the treat Well, for the purpose of getting through this exercise, I'm just going to give date requested or deduction. Rather the same DEET time. No value aren't so. We're providing some value for the date action, but off course, that's prone to change when the approval status changes. Right? So we have created our objects Toby loaded in. So I'm going to call this leave request model instead. Since it's the view model and not the actually request that I want to say Vier leave Request is equal. Toe the mapping, so underscore mapper dots. Muff on. Then I'm mapping to the data type off leave requests, which is our class type on the object to be mopped is leave request model. No, you're probably wondering. Ok, so why did I have to go and reference the other view model before I could put in leave Request model on dso on. So yes, we have creative you model create leave Request view model guiding what was in the form. But then we're building leave request VM So I always keeper view model that is directly mapped to the data class and other scale own versions that actually use under model. So I'm using this view model because it has all of the fields that will directly up to the data class on. Then after doing all of that, we go ahead and save Our is so cess is equal to underscore. Leave Request three. Pull docked. Create on. We're creating the new record, which is leave request. So the request is going from the land above on. Then we know that this is returning a bullion, so then I'm just going to say, If not, is success meaning If the insertion failed, then I'm going to return the view once again with ah on a road. That's is something went wrong with submitting your for court. So you know, these errors are good places to see contact your administrators, stuff like that. But either way, I'm the sticking. If it's not success than do that on, then I'm going to return to the Action Off Index, which I don't necessarily want to do, because I did say earlier that indexed within the context of this control is really going to go to the administrative, um, index file, which I wouldn't really need the user to go back to. Right. So we need to set up our view that shows them their requests and the state off the requests . And that's going to be in the next video. Um, but then, for no, I'm going toe, just redirect them to the index off the home controllers. I can disagree direct action comma on. Then I can specify the controller to be home, right? So then it's real Direct action index in the home controller, which we know is that homepage, which is fairly blank right now. So you know, we're building on the application. We can do everything at once, but little by little. Pieces are going in. So lets us to save all of four changes and then take over application form for a test run. So I'm just going toe, reload this application form and transmit request. So reform is reloaded and our select that I want vacation leave Onda oscillators. I want vacation, Lee from the first of January. I mean that selection. So you see here that it's conflict ing even though we're getting our calendar control, we still need to fix that. So we'll do that in another video. But right now, I just want to focus on getting past this violence selection. So the first of January 2, the fifth of January. All right on then, the deities 2020. So you can see that if we don't mean the application properly, that these things can be very frustrating on make or break the experience for our users. Right? So we'll leave that for our finishing touches where we go through under screen up those little nuances. So I just click request leave, and then it's telling me that I need toe put in something valued. All right. So I guess we can't wait because I'm here trying to put it in and I'm getting a bunch of errors. So let's fix that together and put this to rest. No, I'm going to have to make some adjustments. So our view models on the way that these things are set up. So the first adjustment I'm making is I'm going to the view model for the create, and I'm changing the data type from daytime to a string. So because it's that time, it is still contextually trying to give us a day it input type, which is giving us the calendar control for the browser before it's giving us the G equerry once in the seat up there. Clearly, it's not working, so I'm changing this to string. No, if I change that the stream, that means I have to change how we interpret the value that is coming over from the model, because now it's string, but we're have we have a bunch off date operations doing so I'm going toe at the top off the page. Save our start date is equal to model that start bits, and then I'm going to cost this till date time. And we did one kind of costing earlier where we did the integer costing. So that doesn't always work all that well, not in every situation. So they have a convert class, I can see convert docked on. Then I can see to on day have the time. So convert to date time, and then I'm passing in the value that is in the start dates field in our model. So I'm just duplicating that line and doing the same thing for end date. So end date, converting it And in this model dot and it I know I have variable started an India that I'm going to start using to replace the references to the model variables. Right? So anywhere I had started before, I'm just going to replace all of that with just start being variable on. Then I'm going to repeat that with end date. So take nd It's Ripley's replace model dot and it everywhere. All right? No, let's see him. All those changes on reload our form and see if anything changes for the better. All right? So, no, we are not seeing the presets did values. But when we do click, we get our date picker. So I did say we're testing between January 1 on January five. Well, six. So other little considerations would be that if somebody is requesting vacation leave on that weekend is included or weekend, these are included. They want to exclude those weekend days from the calculations, right? So those are little business rules that you need to put in as you build out this system or for Nolan's, just calculated that everybody works seventies a week. So any number off these that they have requested that is the number off these our calculating against. And then we say, request leave on. We're getting on a row Seeing something went wrong, which means he caught some exception. There's something that is not firing, so when we're encountering these kinds off Eros, it's better. We're going to de boat moored on set break points so we can track over activity. So I'm going to go into debug mode on. I'm going to set a break point at the start off this function on, then we'll step through each line to see exactly where our court is breaking. All right, So I have the form, I feel that authority. So when I click request leave, it should hit our break point in the post on, so we can monitor and see that. Okay, Start their descending over this value so I can step and step through. So start being no, Has a date time off that four months, which I believe is the or it's months the right. So that's the date time that got created for the start date on the end, it is demons here months the or Sorry. So that's the sixth. So the if then we find all the leave type reports, I'm actually just like to skip ahead, because I think we're a fairly good idea of what happens between these lines somewhere to skip ahead to this. If statement on, then its statement is checking. Is it valid? So it is valid. So we know that that is not what is returning to our view. Then we're doing the date. Compare where we're comparing the start dates to the end date on. Then we step ahead on that comparison meets Oh, our requirements. So the next thing is that we try to get our employees. So if I look in the user objects, then I can see that there are some details about them being stored. I know the name Onda some other few things, but then when I do the gets user a sink call, you will get all the required details in the object. I have the employee, the i d. Everything about this employee is no in the system or ready for Austin manipulates. Next. I'm getting their allocation. So I step through that again. Andi. Well, just step, do a few steps, let it go through that process. So this is me using f 11 just to make sure that I'm not skipping ahead off anything that's important arts after a few steps. And I got a little kerosene that the daytime No volume afternoon because off all the stepping, So if you got a Terry could ignore it. If you're doing this with me, if you're not, then that's fine. But we're going through this together. So the allocation is back and we have everything about the allocation that we need. No, I'm going to step ahead again. So I'm going to CF 11 on then it seeing is the number off days requested greater than the number off this allocated on. We know that if I'm requesting two days on the allocation is 15 days, then that validation is Okay. So we stepped through, we build our objects. So let me see if this is where the Eros appear. So when I build that leave, request model object then I'm seeing. Approved on, approved by and approved by I d All know we get our date option be requested and bit all of them are building all the great times as we expect So all of that should be okay, Um so I'm just going to continue, so f n f l ever Sorry on then go to the submission where it adds the entity. So I'm adding the entity off type leave requests which we just constructed go through that Then it is saving the changes. And then, in saving the changes, he caught the exception, right? So, like I always say, that's the point off the track catch. So it's going to try the operation and then it's catching an exception someone to step past this line on. Then I can no examine So by adding this line to the catch, I can see what the exception is on. Then I can drill down and see that it says the insert failed Insert statement conflicted with the foreign key constraint for the leave type I d. All right, so that doesn't exactly what's wrong? I did not in building the model force of mission. I did not put in the leaf type I d. So I'm going to stop, and then I'm going to fix my error on I'm going to say that the leave type. I see. Okay. All right. So I know. I see Why didn't put it in? Because I have the leaf type object, but I don't have the leave type field in my view models. So I did not create my view model correctly. Right? So I'm just going to put in that leaf type ideas. Some distant copies average here already. Put it in tow, the mean object, and they know that I have it in the mean I mean class. Sorry. No, that's how it there I'm went to make representation for leaf type ideas. Equal toe model dots. Leave type I D on then I am very confident that this leave will be submitted this time someone to remove this brake point from the start on. I'm just going to put it down by the success. Yeah, it's it's either successful or not. So if it hits this very point that I know that it was submitted to the database, or at least if it feel, then it would go to the catch right? So let me just go back into debug. More than try that again are so let's try that again. I'm selecting the date the first off January 2020 upon to the fifth of generator into 20 request leave. Then it's telling me that I value here is invalid. I need a proper value. I didn't select from the drop down list. Let me try that again on. Then it hits the brake point. So it didn't bomb vote on this land like it did previously. And when I hover over this, this is his success is true, which tells me that it was submitted to the database without any issues. Someone to remove my break points click continue on, Then it's going to redirect to the homepage. Like I told you. So we told it to do that. No toe validate that it is there. Let's say I submitted the leaf and then I walk over to H R. And then I tell the person who I know approves lease that. Hey, I submitted it. They need to validate if I submitted it. So they log in as the administrator on. Then they're going to go toe manage on, then employees. Oh, that's inaccurate. Manage, leave applications rather, and then they'll see that they have to requests. One is spending one was rejected on. Then they can see that test user made an application request for vacation leave if they want to see them in order off the requested Well, we can always just put in our data table in this section. Uh, just take something quickly, Andi. So I know that a data table was here. I noticed that it has reverted to a regular HTML table on die. Just did inspect elements on went to console and nowhere Looking at an error on this arrow is here because off our stint with RG query us. So we're going to have to spend some time fixing those references because If I'm not mistaken, no data table is loading at this point because off that error, all right, so that's That's another thing that should have been a data team. So we have some work to do. But at least we can feel confident that employees can no request leave on. It will show up in somebody's, um list for approval or not.
42. Employee Leave Requests Module - Admin Leave Request Review: Hey, guys, welcome back in this lesson will be building all the functionality that will allow our admin users toe approve or reject leave requests. You know, our previous lesson we would have built off opportunity that allows an employee to actually submit a leave request. And that would have been through selecting a type on then the start. And indeed it's since that video I made some minor adjustments because we would have left that lesson with, ah, you know, toga war between our Jake or you y calendar control on door data tables know the adjustment that I mean, it was really minor. All I did was removed the reference to the Jake where fire for the calendar. So originally, I would have copied both the J query Js file on the cheek or you I Js files have since removed the second reference. The Jake where files since I already have a reference in my project are in the experiment, and it does work. So they're certain versions off. Jake. Worry that the geek where you y calendar picker does not work with Andi. I mean that assumption. Initially having experienced something like that in the past, No, I actually just removed the second reference. Ajay Query. Andi, I have one references a query and then every other library that has a dependency, including, or Jake. Where you Why? On doing so alos both over data tables to load properly. So that's what our data table should look like. Ah, when there was a conflict, it was just there playing table that we had tried to change. No, it's back toe How it should look. Being a data table on also for our form or calendar is coming up. And against that, the bro's result of completing. But our calendars from so all a forge, a query or javascript beast controls are firing as we I need them to. So that's one way. If you have conflicts with J, a query files or a JavaScript controls and you're getting Arizona console and you're not getting the control as it should look, Then maybe you can try moving your own references. Remember that Order matters, Andi, Off course there can be conflict. So just be careful when doing those things moving along. Our objective for this listen is toe alot for an admin user. Once they're on this interface to be ableto select a leave request on, then be ableto well, go to the details and approve it or rejected. So that means we're going to have to refine the options that they're seeing here, meaning I don't want them to be able to edit at on them to be able to delete it. But I want them to go to a view which I can use the details you. That was so all of the details, you know, other details off the request that me, an official here on then, at the end off the review, be able to click a proof which will then, you know, put it in an approved state or reject, which would then put it in a rejected state. Bear in mind also that once I leave request is approved, then the allocation that that employee has in the system will have to be adjusted to reflect that deduction. So let's get into the fund. The first thing I'm going to do is modify the interferes, and that is the index file in or leave request folder on. What I'm going to do is remove some of the action. So like I said. The only action I really need is details or while I'm actually going toe, make it say reviews. So instead of seeing the word details, the link itself is going to say Review. I'm going to add my Bt in on Bt and Dash primary. I'm going to see old line primary andan Justin to add in a five icon or two. So let me just do that quickly. I'm in front also. Maiken, I don't know why I keep on seeing five icon, but this is what I'm doing. So I added that fund Awesome. Um icon referenced a file on this is what it renders on the screen. So now we have, ah, button that say's review. But off course is going to be pointing to the details action inside the controller. So now we need to implement what this action does. So back in our controller, I'm going to go to my details action which is expecting some integer perimeter off I d. Which we know it's going to be the I d off the leave requests. So I need to retrieve that leave request from the database someone to say Vier request is equal to or let me see. Viral leave requests is equal to on the score. Leave a lock report dots find by I D. And then I'm fasting in that I d for amateur. Having retrieved that, we load off our view model. So we have leave Request view model on me. Just double check and make sure it has enough for me on Do you notice? I still have that. Those data annotations for beat. All right, so I leave those in that view model, so I'm going to lose blood off the model and C var model is equal to on. Then I went to same upper that map and then mapping in the direction off the leave request VM on the object to be mapped is leave request. And then after being off that we just passed in our model I know that we have the model passed and I just right click add view. And then we just scuffled the details speech with the details template final model, which is leave request vm on. Then click at All right. So I'm just making the few minor the usual adjustments I'm going to put in somewhere. Details appear so review. Andi, I see. At san model dot employees are requesting employees that first name last name. So I'm going to say I'm reviewing leave request for this employee on a C apostrophe s leave request. All right, so those are the things you can put on your screen to make it a bit more, you know, personal. I'm not going to modify the Leo toot off. As you can see, it's already mapping. So this is saying this play name for on then it's giving us the I d. So, like that idea I want to print the name on. Not they employees i d. So I replaced that start date ended it the leave time to be requested for that. I'm going to move it up underneath the review sentence. Someone to just put on aged four on dime. Went to see display name for the requested on then dash so that it's up top. When? This day when this leave was requested to begin with. So it's reviewing it for that person, and then the d requested right on Anethe on. Then I can remove it from the overall details, so I don't want those details. I don't want the date action. Um, the admin user already knows it's in an approved state on. Then I'm going toe move on the part that sees or sorry, he already knows it's not. It's not an unapproved state on we're going to move. Oh, they approved by. So those details are not necessary when this admin user is trying to decide whether or not he or she should approve. Leave right. So we want to show relevant beaches we can arrange that pho we want on. Then we can press forward with functionality. So then we want some actions to be available to this user. We want them to be able to approve, reject or go back to list. So I'm going to do it like this now, someone to say a proof, and I'm going to copy this button taking out the pipe on. Then I'm going to see reject Andi. I want to leave backed a list so we have three buttons on. Then I'm just going to spend some time and give them all their classes, so I'll do that off screen. What I'm going to make approve Bt and success coming to make reject Bt and danger on back to this is going to be BT and secondary. So I'm going to pause and do that. You can attempt it on your own. All right? So that success, danger and old line dash secondary. I think I cheated a little. I didn't say Oh, Linus, said Sikander. But that's fine. Whichever one you choose. It's for your own benefit and for your own personal creativity. Art. So I'm also going to add the fund. Awesome icon. Some I'm going to break line so that I can see each uncle attacked by itself. But I'm adding the icons to eat. So for this one, I'm going to give it f e space F eight dash. I think they have teak. Um, I don't know all of them. Sometimes I make an educated guess based on the type of icon that I'm hoping is there, and sometimes I'm wrong. So I still have to end up going back to the documentation anyway. But I'm just going to do that first and then refine Andi. My intelligence is giving me feed this one. I'm going to see. I want something that is like an X ray, so I think they have one that's his removed so that if you remove on then for the backed A list, I want an arrow going back. So I'm going to say f A r o left. So let me just do that quickly on then. This one is F E R O. That's left. So actually, just check the documentation and I saw that it's not tick, but it's check. So that's why I use me like a little check a tick. All right, so once again, you can always go to the website and reference the front also were using version 4.7 points all I don't memorize all off them, but on demand, I go and find what I need and 15 accordingly. So now this is our details. You have some other things I want to change notice off, or at least a proven reject. Both point to the edit action. I don't necessarily want that, but you do have a number of options when it comes to dealing with this situation. So what some people do would be they create a form and they make all of these kind off submit buttons. I need submit button will go to the post action Andi. We'll try to do the submission in the post auction, right? That's on option. You can always create your own actions in the leave request on troller in the controller on . Then you points to the relevant action. So, for instance, I can make one action that just visit approvals. So when this link is correct, it will call approve action. And then we all can surmise that that proof action is going to be approving the transaction . Right. You can also create another situation where you would have won for approval on 14 rejects. You can have multiple options. You can have as many actions as you want. You can create them on demand. You could create one action that takes a parameter. That's maybe a flock to see, you know, true or false. True meaning. True, it is approved, say, do they approve steps on dfars? It is not approved, so you do the rejection steps. So at the end of the day, you know there's a there's individuals that's going to come out in your implementation, and it's up to you. But for this situation or the purpose of this. Listen, I'm going to create one action for approval on one action for eject. So that means the approved button he's going to call there. It's the action. Approve Request on. Then the reject option is going to call the action order. Eject button. Sorry. Is going to call the action reject request on. Then we all know that battle is just goes right back to the index anyway. So with that's done on, both will accept the i D off the lever quest. So we know that in that proof, we're approving the lever quest with this I d. In the reject were rejecting the leave. Requested that I d. So I'm just going to go over to my controller quickly on then. I'm going toe create my action result on this one is going to be called approve request on its taking on int with an I D open and close braces on. Then I can do Skopje all of this Onda make it in tow. Reject requests edibles side by side. Now let's work Or what happens when we hit? Approve what we need to do first These retrieved a leave request that is about to be reproved approved. Sorry. So I'm just going toe. Use this line once again, and I'm just going to build them kind of simultaneous, because in either situation, I need to retreat the leave request that is able to be approved. Right? So I'm retrieving that leave request. I don't need to mop in this situation because there's no operation that as a visual elements, so there's no need for a view model. So I retrieved the data class. Then I modify on. Then I update. So time I'm modifying. When somebody approves the leave request, the elements that need to be changed would be on Anderson to say leave request not on. Then the approval start us on day. I'm forgetting which field it would be on. I'm just know, noticing that I call the entirely wrong report. All right, so if you guys reach this fire, I'm sure you're very disappointed in me, but I call the wrong report. I don't know why I'm so fascinated by the idea. Off leave allocations, but I'm dealing with leave requests. So I have leave Allah creep. Oh, and it's called in the leave allocation, which is why I'm not finding the fields are diffuse that I'm expecting here. So let me just right my wrongs. I'm using the leave Request repose. I hope you guys caught that on Euro. The carting on if you did, then you can just hit me up and let me know that you did it. And then we can form some form of reward for your quick thinking and here debugging skills . But let me just meet those corrections. So I'm getting the leave requests report. So if I debug, um, the the solution earlier than we would have gotten that error because then the mapping would have failed. Right? So the the images country I'm sorry about that. So leave request report. The request reportedly requests report. So in a leave request Now, I'm seeing what I ought to see. I'm going to change approved status so true, I can relieve request again on then. This time I'm changing the approved by I d. To be the user who is locked in right now. I would it something similar were retrieved. Who is love being so? The point is that you can have multiple admin users, and if it's going to be using an organization. They're going to have multiple HR persons who can approve and reject leave or if there is, ah, more complex system where it's a supervisor who can be anybody at any point in time. Um, on firing that more complicated scenario. The fact is that we want to know who is making the approval based on the person with love being and doing the action, just like when we were making the request, right? So I'm just going to retrieve the person using one off the previous bits of code that we wrote on. I have it here in the create, um, auctions. I'm just going to Richard just where this thing off court and then we go back on day. I went to retrieve that. So I'm going to call this user Savar user on. Let me just so everything that we type in for the approve will basically retire for the rejected. So I'm just going to do with approved and then we just copy and modify accordingly. So the user I would be or the approved by idee is user. That's on. Then we get I d for that field. Then we have leave requests the date Action on that is no the time. No meaning. This is the time that there action was taken. Aan den. I'm not sure if there's anything else about the leave request that I need to modify when it is approved or rejected. So we know it's approved. We set, which is approved by the i. D. The date it was action. The requests need to be changed and they leave type. I think that's it. So know that we've me those modifications to our object, um, or toe our record. We need to actually save right. So I'm going to say if or rather sorry, I went to see a virus. Success is equal toe underscore. Leave request reform, not making that mistake again dot on. Then we see update calling that update function on. Then I'm going to be passing in our leave requests, Mama model. And then I say, if is success or if not, is success, then redirect their many ways toe elegantly handle these errors. But I'm just using, you know, a quick and easy pass for us to get up to speed and open running and have an appreciation of what's happening on off course, we need to wrap all of this in a try. Catch someone to see you try and then pressed up twice. And then we get that Try, catch, block. Make sure I'm accounting for the exception on that. I'm going to take all of the operation that we're trying and put inside off the try block on. Then I'm going to do the catch where I just returned. Redirect the index, and then I removed the throw. So the throw actually kills all you know, all off the operation off their application, which you don't necessarily want all the time. So I'm redirecting toe the index speech, if not success. Well, I'm going to redirect either way. All right, So if it is successful, them want to redirect. If it's not successful, I'm redirecting. So I'm taking on that check for if it's successful, and then I'm just saying, Do all off this. Try all of this. Redirect, Even if there's an exception. Still redirect. The point is that if they click approve and approval, state doesn't change because something field along the way. Then when they go back to the index speech, it's still going to be in an approved state, at which point they'll probably call I t. Anyway. But that requires some more, you know, complex operations occur. Toe be ableto maybe dynamically indicate us whether or not that operation was successful, that we're not quite ready for that yet. So I'm just building up. Do it on. I'm trying to keep it as simple as possible, right? So everything that we just did in approve, I'm going to copy that. And then I'm going to do it in reject CNC. Earlier, I was saying that we could have to actions that do either scenario. And that's what we're doing. Who could have had one action that took a flood? And readers have one function that these were the Operation Basin. And if steam it so you know it's really open, it's really a matter off implementation. So you want to do it. So in this situation is all the same, um, data, except that Proust it was in tow falls. All right, so, no, we've done all off that. I want to teach this for a test run, so I'm going to open up my application using the browser link on. Then let's see what our work has yielded. All right, So we already have one leave request in the in the application in a pending states and went to just quickly create another one Onda. Then we can test it with either scenario with an approve or reject. This is something went wrong. I think it's because I'm on admin user. Let me try again. All right? So, no, I've made another leave request using a regular user. That admin user does have any allocation. So it got the arrow. Something went wrong. So we're testing again. So leave applications. I know we have to leave requests, right? Made by the same usable. That's urine event. So let's see what happens on someone to click review, which should load the details. And I'm seeing all the details. So I'm seeing that we're viewing this leave request. The requested was extent date on time, The requesting employees test user on. So you see that some off my labels still need some refinement. So we can just modify the view model so that these labels are printed better art and the leave type is vacation. We were approved reject on a battle is buttons. So let's start with a bottle list. Okay, that works. Let's go back on that. Let's try approved on then this read Eric's The index are so I don't want it to redirect this index page. I wanted to redirect toe the leave applications, um, index speech, arts or leave request in victory. So we'll modify that. I think I had specified the controller. There we go. So I specify that we should go the home, which I don't want someone to remove this on. Just see Read Eriks to Index. All right, so that's one of those Don't says copying and pasting court almost blindly. But thankfully, it's our own code. We wrote it so we can modify it as you wish. Alright, so I've made those modifications on. So we see that they approved functionalities working and we see that context only they can see which one is approved. So no, they know they have this one pending approval on this person is the same uses. Requesting some days Onda, we don't want to give them too often. So I went toe reject this one. All right, so we click reject and then this should know redirect that are listing and we see rejected and rejected so to requests rejected in our system. And we have one approved zero pending. So have three in total zero pending one approved toe reject it. That's good. Now, one thing that we did not do for the approval was to modify the employees allocation because remember that they haven't allocated Norm office for vacation. They would ever made their requests. We would have approved it. But we did not put in the functionality to actually meet the deductions from the from the A location for the period. So I have to go back into my controller and then we're going to go to our approve requests on. Then we have some more work that needs to be done. So now I get to use my leave allocation reports. So after we have retrieved the leave request, I need to retrieve that employees allocations. I'm going to say allocation is equal to leave I location and would be careful this time docked. Find on, then. Here I have find by idea and find all But then I need to find the allocation by the employees. I d number. So what I'm going to do is modify the repository for leave allocations on Duh. I actually do have it get allocation by employees. I I do have it. Sorry about that. So I just forgot the function name. So let's just listen toe undo all of that and it's not find, but it gets get allocations by employees on. Then I'm going to re passing the employee i D, which we know from the leave. Request objects coming from our database. So it's leave requests that employees or requesting employee I d. So there to patterns. When, when doing this. Sometimes people like to reference it directly from the object. Sometimes people lie to be clear variable, so they would just say, Employee, I d. Is whatever it's going from the object, and then they use that variable to actually do these menial tasks, right? So I mean, it's a different pattern. You do the one that you're comfortable with. I think it looks cleaner when you do the variable and then you do your your tasks with the variable instead of referencing the property and the objects over time. But that's fine. So know that we have the ah location or well, actually, we need allocation for the employees. This is allocations for the employer. We actually need the particulate allocation for the leaf type. So here ago get allocations by employees and leave type. So we thought off everything already so by employees and the type. So this one requires two parameters, which would be the employee I d. On. This is not very explicit. So we need to go back and refractor that So it's very explicit. And we know that we're dealing with employee I d. All right, so we just meet those changes. If I make it in the interface, have to make it in the repository. I mean these modifications while I teach because I want to show you that you write the thing. It works well. But in a different scenario, allies that all you could have been, you know, a bit more explicit or a bit cleaner in your court, and then they're going to be ending up making these changes as you go along. So you know you need to be flexible, and it's good when you understand what you're doing, What was done on why you need to change it. Those things will make you unstoppable. So no, we've made those adjustments on Then I can proceed also by being more explicit icing employee ideas. Somebody else wants to come and look at my core. They wouldn't have to guess which idea I'm talking about because it's already kind of spittle for them. So I'm passing in the employee I d but also need the leaf types. I want to say leave type is equal to on. Then retrieve that Leave type I d from the leave request object, but they leave. Request that leave type idea on DSO employee I d comma leave type and I really should say Leave type I D. Here. All right. Leave type I d. Good. So know that we have the allocation that this employee has for the request being made. I can proceed to see that their allocation should know Be the number off days in the request less the Sorry, the number off these in their allocation unless the number off these in their request so I can see a location on that's number off days is no equal toe the same value, which is number off days minus Leave requests dots on, then. I think I have a field that say's requested number off days. I don't. So the leave request itself is not tracking the number off days requested. It just knows the start date on the end. It which means that I'm going to have to do some month toe figure that part out, right? So I can dynamically determine that. And I'll use code that I wrote previously when creating the leave request. So earlier we would have done something where we took that number off. These requested and we did the calculations. I can repeat that. Now this copy on. Go back to my action. So Vier D is requested. So you see, we have quite a few little operations. It's after going, so we have the days requested on. Then that will be leave. Request that and a bit a minus. The request not start debt. All right, so once again, you could have put those in their own variables and then done the operation using the variables. You know, it's up to you on then. I know that I have the number of days requested than the allocated Normal is going to be that number. My nose there is requested on then, after making that adjustment to this field, are this year value on? Then there's an easier way that we could have done this. I could've said minus equals on. Then these requested. So that's a nice although we that c Sharp Alozie to write that statement where it's basically saying that what it says minus equal, It just implies that whatever value is on this side minus this value on, then whatever the welcome is stored in that value. So that's an alternative way of writing that statement. So what I'll do is write it both ways. So if you're a beginner would see sharp, then you may not be familiar with this technique, so that's fine. So that's another way you could ever in this thread and see visual studio's even come, you know, kind of suggesting that it would ever in it that way, all right, So after doing that calculation and removing or reducing the number off days that are no available by the number off is requested on, then sitting all off the flags on, then updating the leave request, I'm just going to say updated someone to actually take off this year because I'm not using it. So sometimes you don't want to declare available. You're not using in this situation. I don't need that variable. So I'm doing the leave request report update, and then I'm going to leave a location not upbeat because I just made changes to the allocation record. Also on then the entity or the object and passing in is allocation. And then, once all off that is done, Then we redirect store index off course. If it's rejected, then with your citadel falls and nothing changes for their allocations and remove this unused variable also on, then we can try again so we can try with an employee who will make a leave request. And then we see the change in the allocation after it's approved are here I am with the user creating the lever quest for vacation. Remember that vacation by default, at least on my side, was set to 15 days, if used a different value than you just need to be weary off the valley that you used. But I'm going to request from the 26th off January to the 30 f. All right, so what? 2016 Sunday. So let me make it a bit more realistic. So from the 27th to the 30th that's about three days. I request the leave, all right, and that was successful. So just log in as our admin user quickly, and I just see the passwords. I don't have to re type every time. No, let's just go back toe the leave allocation. Just verify or that does not show the leave allocations. Sorry I lost my bearings. That should be going toe employees on. Then I can view the details So this employee has 15 days vacation leaves. Let's bear that in mind. That's the number off these that they have allocated. So I go and I go to leave applications to manage Noah's. You have a new review, Andi. So one thing that I would probably want to do is order the leave requests in the order off the beat requested so that the most recently requested ones float to the top. Right? So I'll be ordering that's later on, or I'm going to challenge you to do that, ordering reordering in the control. Oh, that slowed in this data, but I am going to know just go to review and then I'm going toe approve. So know that it's approved. Andi, I know it's approved for justice User, which ste at B t. It s not be, I guess that's accumulators I used, but I'm going to look at test user's profile. I look at the details and no, I'm seeing that the vacation leave is no reduced. So the next time they make a leave request they have upto are as many as 12 days from which to me that request. So if I attempt this request again, remember that we put in some validation that the requests should never exceed the allocation. Someone to try and apply for the same vacation leave with the same user. But this time I'm going toe apply for a month worth off vacations and selecting to be it's that clearly exceed 12. These requests leave on. Then we get our arrow. You do not have sufficient days for this request. All right, that's good looking good. So far, I want to make one more change on that is toe. Remove that review button. As a matter of fact, I'm going toe remove the ability for Let me go back to leave applications. I'm going to remove the ability for on admin user to change the state off the leave request . So you know what is that even though it's approved? Are ejected. When they click review, they still get access to the three buttons. Well, more importantly, they still have access to the approve under reject buttons, which I do not want so back in my details view in the section or in that Dave that's loading those buttons. I can just put on if statements I'm going to say act, sign if and then call on the model on then said That approved is equivalent to know. So the only time they should be ableto approve or reject is when the approved flag is in a no state, meaning it needs to be said the true or false. Then I will accept the HTML associated with these buttons being displayed. Otherwise, it was only display back to lease so or will not. Otherwise. If it's in a no state, then you will display this, but it will always display the battle is born, so that's a nice quick way off. Controlling what? The admin user, what anybody is able to do based on certain conditions and business rules. So with that modification done, if I go back to this speech, which an already approved leave request and I refresh, then all they will see is the battle list button so they won't see the approve and reject because it's already in another state. But and this is almost a cause for concern. So another visual cue we can put in is putting like a little section at the top that shows is its pending. Is it approved already? Because they're coming here? They may be the forgot the state it was in when they clicked the review button. So you want to give them another visual cue? All right, so with that in mind, I had made a few adjustments to the interferes, and I'm going to walk you through exactly what I did. I did it off camera, but I want to challenge you to maybe the spots the video replicated, but I'm going to explain exactly what is happening anyway. So I put in an statement at the top off the details you that said, if the model is not equal to Oprah voice equivalent to know, Sorry, similar to the one that I did don't here with the buttons. So I'm seeing if it is equal internal, which means it's in a pending state. Then display at Dave with bootstrap classes. Alert on alert dash warning So you can always go to the booster of documentation and look at the documentation on alerts. All right, on just bringing it up quickly, we went toe. Get bootstrap dot com components and alerts on here. This is the example that I selected. So they are simple alerts where, you know you can just prints like colored gives or colored containers with text, and they have the different colors, the same primary secondary success, all of the colors, pallets that you have available for buttons and everything else. Then you have it also for the alert. All right, so that's all I did. I just said, If it is in a no state, then give me an alert that looks like a warning. So that's an orange alert. Give me a header. That's a spending approval, and that's a need for tug on, then a pita that is printing old the label on then the person's name on, then a little line. That's HR Tug on, Then that display for the D requested. So this guy, the same information I had in the header. Initially, I'm just putting it inside off. Give with some coloring art on, then I'm making context. Also have the statement for the null, then have a statement for True on. It's pretty much to see him. They've, except this time it's success right on the verb ege might be a little different, so no, it is approved by instead off pending approval. So the head US is approved by on then If if neither institution is true, then we get one. That's his danger. That tells us who rejected it on pretty much a seem information for the employees. And so if we take a look at what that shows us, if I go to the approved and others open them in separate tabs, if I look at an approved one that I'm going to see a green alert at the top, if I look at a rejected one, then I see that red alert at the top right and rejected by his blank. It should have the first name and last name off. Whoever is rejecting it. But our admin user doesn't have first name, last name in the database, so that's why that's blank. But it does work as we expected, toe and then we go back to list on. We know that if there is anything pending, then it will show it accordingly. So that's it for the administrative management. Off leave requests in the next lesson will be setting up the screen so that the employee can see their allocations, you know, and there leave requests that they've been making over.
43. Employee Leave Requests Module - Employee Leave Request Views: Hey, guys, welcome back for this lesson. I did say that we would be putting together the screen that our employees see when they want to look at their allocations and their leave requests to date on dso I already built all that entire interface and all of the functionality. Well, I left some for you, but I'm showing you what we're going to be looking at the Court four on. I was systematically bringing through all the code that was written to support what is being displayed right now. Now I did it this way for two reasons. One, I want to challenge you to actually write the code yourself with as little guidance from me as possible, because that's where you will really shine. I also think that this is relatively simple and it should prove enough of a challenge for if you're a beginner. But it should be fun for you to try and on your own. Either way, I'm going to be walking through the court that was written on day. You can pause the video at the different periods and copy off the court as you feel the need to do now. The first modification on. Well, I mean to modifications that Leo Ph. But the 1st 1 for the purpose of this listen, is that I added the navigational link toe our new action, which is my leave. So I just added a new never item on the consume controller as Acri apply for leave. But this time the action is my leave on the text is my leave. The other adjustment amid is that I change the verb ege for the leave applications dropped down to say leave requests instead, which fits in more with what we actually have. So there we have our navigational link to our Miley Fitch. Andi, I would have already been loved in. So the fact is that you are only able to get this fire fear log being because remember that would have authorized the entire controller. And then once you're logged in, you can click my leave on. Then we contextually determine who you are and show you only your information. No off course. For information like this to be displayed, we had to create a view model that was going to be capable off storing the data on, then rendering it on screen. So I'm going to bring you over to the view model that I created, So I created a new class inside off leave requests. VM on this one is called Employees Leave. Request View View. It's a multiple, but that's really what it's for. It's a leave request view, view model for employees right on then inside of that view model. I have a list off leave allocations and I have a list off leave requests. All right, so you can see it. That's off. Next up is our new action called My Leaves. So inside of the Leave request controller, I created a new action called My Leave on. All we're really doing is one determining who is logged in, and we've done that before. So I get the employees or the user who is currently loved being on. Then I see Well, I just store the employee I D, which I then used to retrieve the allocations of leave allocation report, get allocations by employees with the employees I d on. Then I do the same for the leave requests. Leave Request report gets deep requests by employees, which was not there before. No. So, in order to get the leave requests for the employee in question are the employees whose leap requested Definitely want back specifically. What I did was go to my interface for a leave request repository and create a new function . I collection Lee request get leave requests by employees accepting a string perimeter off employee employee I D. On. Then I implemented it in the actual repository class on. All it's really doing is just quarrying ready and the same quarry as the find. Also, it's pretty much to see him find all quarry. So I actually could have just written this as find all that where? So let me just rewrite that find all which is basically returning all off this data Anyway , on then I say Docked were so then the dot where no is just filtering on the requesting employee I d be equal to the idea that it's receiving through the parameter. And so what it does is return all off leave requests that this particular employee on more specifically the person was current allowed bin all of the requests that they have ever meet. Side dress made that adjustment to my cord. You can take that off. No. After ever treated on allocations and all off the requests. I then go ahead and do the mapping. So I'm mapping the I'm creating. Ever believe allocation employees allocation model. Sorry on I am mapping toe a list off. Leave allocation VM passing in object coming from or data query on. I'm doing a similar thing for the leave requests on. Then I load up the model so I create a variable for the model or an object off type employees leave request view B m on that, I'm passing the leave Allocations on em, passing the leave requests on. Then I'm returning the view with the model No, to create the view. What I did was I right Click view as usual Click Add on. Then I loaded up a list template, but on in the past you've seen this where we have a custom model on. We know that if they properties in that model are not the simple properties that nothing will get will actually get rendered on the screen for that model. So in this case, we have to class types. Nothing would really get rendered. So the kind of court uncle cheat the system. I use the model class, off type leave request VM. So that's leave request VM on. Then I added that view on then the view that got added. I can distract. We can go to view it would have given us a data table or a table listing. With all off the lever Quest VM feels as we know the list template does. So Then I change the model from the innumerable off type leave request VM toe my new view model, which is employees leave request view VM and then for the table. I changed all the labels because I'm sure we remember that when you do it like that, the labels will stop getting generated or the generated code will start giving era ciders hardcore that the titles instead on. Then I remember that in the four each it was for each item in model I'm Gina that toe for each item in model dot leaf requests. So these are the headers. And of course, I made sure to put in my i d for tbl data so that this table looks like the data table that we've come to know and love. So these are the headers for my table And then these are the columns on. Then for the columns I retained with the corresponding one to the head. Also leave time much us leave type. That name started Muchas to started in there to end it the requested approval state. I reuse the statement from over Previ ous admin view. So I just said If it is approved and show success if it's not a brochure rejected Andi on Otherwise show depending budge on. Then after all of that, I have one action inside off this action hitters. I actually put something there. That's it's cancer. The cancer requests because that's the one action that I want an employee to be able to carry out on their own leave request. Right? You made the request. You can cancel it. Um, yeah. I mean, even if it's approved already, it's still not taken, so you can cancel it now. I'm challenging you to put in that functionality as you have to make some data be exchanges . You're going to have to allo them to click this button on, wrote them to an action called Cancer Request, which is taking the I d for the request item on. Then you're going to have to write some logic to see that the flug that stays with our not it is cancel. So that means you're going to have to make a database changed to include some form of flag that say's is it a cancelled request are not so. Then you have to change that flag to Yes, it's canceled on. Then you're going to have to do some Musto re add those allocated days, too. The original allocation. Right on. Then, off course, you re add them only if the view if the leave was approved. So I'm just giving you a scenario where you're going to have to make your own business. Rules are on hold. Cancellation can happen in the system. All right, So if if if somebody made a request it has not been approved, it's still pending, then Obviously, they shouldn't be getting back in Edie's from the allocation If it has been approved, that means the allocation has been deducted from, and so if they can, so they need to get back their days. Tough logic is that if it is rejected and you probably wouldn't see the cancellations right now, the only logic I have to determine the circumstances under which they will see the option to cancer request is that I'm seeing if the item that started it or if the start date for this leave request is less than the daytime that no meaning you have not started leave as yet. All right, so the start did Ondas. I'm explaining that I'm seeing that I have a logic error here. So the start date, if it is greater than the time no means that sits in the future, which means that you haven't started. It has yet so see, that's why according together is good. So I have to change this. If the start date is greater than no, then I'm able toe cancel. That means the day it has not come as yet. And then, like I said, if it is rejected, then I don't need to allow them to Kansas, understand to use this opportunity and at that line, or that bit off logic and see Andi or rather, I'm going to say are so It's either that the start date has not yet come or item dots approved is equivalent to falls on the other circumstance and see another logic area, I should say, if it is equal to true, right? So if it's approved, then I can cancel on if it has not started that I can cancel. If the start date has already come, then we have toe. Um, we want a low the employee to cancel it on. If it is rejected, then we won't allow them to cancel. It doesn't make sense at that point. So that some logic that I'm using to show the cancel request are not so. Once again, I'm going to Hello, you two, or I'm challenging you to create the action for the cancellation. No, that's for the data table. At the above the data table. I have another section where I'm showing the leave allocation. So I have the title, the IV allocations, and then I'm using a bootstrap class called Jumbotron for this Div. That's why give it that gray back grown looking, um, effect on, then inside there, I'm using similar cards thought would have used. I'm actually just reusing that court from the admin panel. The only thing I removed was the ability to edit the allocation. Finally, I modified the create action. Are the post create action in our controller, where after an employee has created the leave request, remember that we were navigating or literary Derek's directly to the home page off the entire application, which I didn't want. So instead, I let it redirects to my leave. So after they have submitted it successfully, then it goes back to the patron, them their current allocation as well as their core, and set off Lee requests that are no pending. All right, serving the speech once again here is that my location section with the Jumbotron degree but groaned with our leave allocations listed on, then over leave records showing all off the leaves. Taken know. As I looked at this screen, I saw that we have another logic era happening here, So the start date has already gone by. All right, so this this is being done on the 12th of general, which means that our leave request for them to start on the first that have already collapsed on then. This is in an approved state shore, but then the cancer request option is still there. So we went after finding its statement toe. Make sure that we're not overriding when our dollar because I did see if it is approved, then showed cancer request or if it is passed a start. It's at this one off. Those conditions is evaluating to true and thus were getting the buttons. So we just need to fix our your statement to make sure that we don't get that button someone to fix it, and I'm once again challenging you to fix it. It's really not that difficult. You can just use a few permutations and started toads, but I will have it fixed. So with that, we're done with this model pretty much on the next lesson is just going to be a review. Onda Check in to get hub in between no and the chicken to get up. I'm challenging you to implement the Cancer Quest feature as well as the comments section. Four hour leave requests. A little more context around in the comments is that on employees, when submitting Oliver Question, be able to write in a comment to say, You know, I need this time to do X y Z on another section for the rejection where the admin or whoever is making the rejection, um should be able to see, This is why I am rejecting the request. Once again, those two activities require some database changes. Some view model updates on some view updates on I'm eager to see you do it on your own. Feel free to contact me. If you need further guidance, I'm going to do it off camera, and then we can just review those changes in the next lesson.
44. Review and Add Changes to GitHub: Hey, guys, welcome to the final video in this model here. We'll just be reviewing all of the word that we put in and the chicken in our changes to get up now. Quick reminder of what we did. We started off by setting up our administrative use for leave. But based on what's on the screen, I walk you through exactly what we did. We set up the create leave request form for our employees. Andi, I made a few modifications since the last time we're on camera. Originally, I had the forms Dave to be said toe call MB. Dash it. I expanded it to 12. So no fills from left to right off the entire container. Also did beat and block for both the requests. Leave one on the back to list button on. I made us like change to the data object where I included a field for commenced so I would have modified the data class and included a string column called Request Comments. That's what I call that. You can call it what you want if you choose to include it in yours also. So I included that field in the data class and off course. If I put it in the data class, then I also put it in the view model. I would have also given it the display name Employee commenced on Die. Give it a Muslim off 300 on on the field I included was one for canceled. So I challenged you toe put in the cancel functionality I put in a field which is a bully, and four canceled which off course, when the user is or the employees making their leave request would be set the falls by default. And in the chancellor request action, which I created in the leave request controller, I would have just said Give me the idea off the leave request on set that flag to true on Then run the update on, then return to my leave. So that's basically the function for chance in the request. I didn't make any changes to the create action on how I built that object, because really, if the object gets created, it's going to be by default falls. However, if you feel more comfortable, you could explicitly state that cancel these equals or false. I didn't, however, include the comments in the building off this object. So if I go to the form which is create which is on my create view instead of the leave request folder instead of views, then I see that I do have the field which is a text area on This is an SP for request comments. So it looks pretty much just like every other ah, form ruby that we've had. Except I'm not using input, but I'm seeing text area defining the feel that it's for on giving it that form control. So once we click submit, then this bit off data, whatever is entered in here will also be submitted over for creation. So that means I need to know include that data inside off the object that I'm building toe create a new leave request so we can just do that together. Where I see request comments in the object is equal toe model dots request comments, and there we go. So when we submit a new leave request, then that leave request will get generated with content for the comments. If it is there, I didn't make it mandatory. Maybe they want to put a coming. Maybe they don't. So it's not a required field now over to our my leave You. I made a few adjustments. I added a column and I put the title chancel request on. Then I added another column to the four loop section or the for each loop section where well one I added, and a new condition to the statements that give us the different budges for the status. So I added one for cancelled if cancelled. So cancelled in this field is our bullion. It's not a knowledgeable bullion, so I can just see if cancelled or if not cancelled. I don't have to facility it or take into consideration. Ah, possible no value. So I'm saying if the item has a canceled state meaning cancel these in a true value state, then I want to print the budge secondary with the class secondary. Sorry on then I see the word canceled on. Then I just put else in front off the if statement that we had originally. So now this is our new If block on then for the cancelled button, let's see. Each are contacted me and told me that the way I had the business rules were incurred. So I had to make a change. So all I'm checking for right now is if the leave request is not canceled on the start date has not yet come, which means that if they've approved it, then we cannot chance it again so that cancel buttons should not appear if it is approved or if the even, if it is not, even if it has not been approved or rejected in if it's spending as long as that started it has been passed, then it should not be eligible for cancellation. So back on over my leave page, the additional will the additional visual cue is the state off canceled. So notice that this date has not yet come. But I cancelled it. And so that that button does not appear again. But if I make a new leave request right now, then that cancer request would come on. No, I'm not going to spend much time writing much court. You can pause the video at different points and copy off the source code that you mean you'd help with. But I want to China and you to write it yourself. No, What we're going to be doing is checking in our latest changes to get up. So I'm just going to go in my solution. Experts at the top, off the file file tree on. Then I'm going to right click on, then Goto commit. Then, after clicking, commits I type of Mrs So high spirited the typing and just put it in already on. Then I think this carriage and see commit all and sink. Remember that every father you would have created or modified would be included. And if you had a file before and probably renamed it or delete it and you would see with a strike through a lion, meaning it will be removed from the next iteration off, your source scored. So understand, to commit all and sink. And that has been done successfully. So I'm on my ghetto profile and I'm looking at my repository, and I'm seeing that just a few minutes ago at me, the chicken successfully on I just want to congratulate you for getting this far. We've done quite a bit off work. You've learned. C sharp. You've learned Web development. You've learned how to use bootstrap Four Elements hotel include Jake Worry Um, you I elements inside off your coat you've done quite a bit. And you should give yourself a pat on the back. As always, you can feel free to reach out to me. Something is not creaking with you on, you need further assistance completing these tasks. Either way, if there were gaps in the source code as you know what I displayed on the screen versus what we actually did together, then the source code will be provided to you. I always provide the guitar billings where you can see that exact version off the source code for the lesson on, then you be able to replicate what you need to. As always, I'm always here to help.
45. AdminLTE Theme Preview: Hey, guys, welcome to this new model where we will be restyling our entire application. Now on screen, I have Ah, the Leo that we've been working with up to know. That is the Leo that has been given to us by default by our project structure. On this perfect, it's works well. We get to put in navigational links, we have that loads where we have that those margins to the sides on everything looks good. But then I mean, sometimes I want a little more possess so in this model will be changing over this loads to the admin LTTE. Leo will also be looking at how we can support multiple layouts, you know, so one page can use one layout. On another page is a motherly loads or everything. Those uses an entirely different layouts. So we will be transforming from this Sloat to something looking more like this which is the admin LTTE Leo Andi I mean, right now it looks very playing. That's fine. But then, as you can see, the nut bars the left. We have a few icons, so each button we have ah DACA ble bar on. We have a nice porter so we'll be just changing it out so you can add your own flares. You go along, but I'll be showing you the basics behind changing out or making major changes to the look and feel off your site.
46. Create New Layout Page: Hey, guys, welcome back in this lesson. We're going to be reviewing our layout page and observing the most important things that we need to pay attention toe when creating a new Leo pH. No exact examining the existing Littlepage should be familiar territory. We can find it inside off or views folder go to shared. And then we have our layout literally named underscore Liotta dot CS html on then this Leo pH and understand to dissect it. Firstly, it is formed on up off the basic HTML structure or skeleton, as I call it, where we have or HTML tags or head tug on or body time. All right, so everything basically falls into that same HTML where we're doctor declaration in html, tag head, body on DWI. Close each tag as we go along. However, you can see that there's a lot happening in between each tug on, then above even the doc type. We have some C sharp looking cord. So at the top off the page, we have all of our dependence is, so we need the library is be net cord out identity. We also need to include our data name space so that we can include our sign in on the user manager models for our layout. And if you remember, we used those for some operations further don't. So we have our dependence is or C sharp library dependence is at the top. Then we start our regular HTML. We can dynamically insert data. So we see here where we said view data is equal to title on or view data title on. Then we upended it with whatever the applications name is on. Then if you want to know more about this view data title, if we look at one off or views and I'll just go to leave allocation and look at maybe list employees. When we opened this, you see that we're setting you data title is equal to some amount, some bit off text this takes that have been automatically generated on then. This text, combined with our static text, is what appears in our browser hitter. So that means if I want a list employees to look more user friendly or readable, I could just put us space there on whatever modifications I meet this string, it's upended toe the entire title that is rendered to screen So that's what can make your titles dynamic. We also continue with the inclusion off all four stand. She'd somewhere there before some we added afterwards. So by default you'd a button bootstrap on its version. For at this point, we would have included our data tables or fund. Also, um, ceases on also r j query you I CSS And then at the end of all of that, we have a link toe our own CSS file. Should we need it at any point? Contents of the body are pretty straightforward. We have a header on inside. The header is really the navigation bar. So header than navigation and then or navigation bar is a bootstrap navigation. We added a few links on. Then we contextually displayed some things based on the person who is signed in. If they're in administrative roles are in an administrative role, then they will see certain things that the regular user would not see on. Then, after our header, we go on to our container which is our body, right? And then inside the body, we have ah, some section called mean on then we have this function called render body, which is really rendering the content or the view onto the screen. After that, we have or footer on. We had changed votes that takes to be dynamic for the year on. Then we have our script files, including now. The reason I gave you that tour is that this forms the basis upon which Leo pH needs toe be created. I actually for back toe point out, and sometimes this section gets forgotten because it's so inconspicuous. What this render section allows us to include scripts inside off our views. On day, it will get rendered after all every other script on the Peach art. So once, like I was seeing, we need to know this when they were creating another Leo pH. Because they're certain elements here that half toe repeat themselves, for instance, render body if there's over in the body than navigation, so have you will feel, because this is what actually renders what is in the view inside off the overall container . So to create a new Leo Page and have it recognised by the application, what we need to do is well, one go to shared on the shared is the best place to put its they can actually put it anywhere he wants. But then it only makes sense to put it where the project structure would suggest. You put it so we'll go to shared. We can click, add on, then I'll just create a new item. So for our filing went to select Razor Leo taught on day I went to change this side. It's They will be using an admin LTTE theme when we started. So I'm just going to call this one ad mean LTTE. So there's no mistake about right on. Then we click at so are resulting file is very simple. As you can see, it's literally that html skeleton. They just trying to give us a little dynamism for the title on They give us a section to render the body. So it's very, very simple. No, after you've made this and I'm not going to go through all of the changes that need to happen just yet. But after you've created this No, you wanted to be the default someone to make this simple page The default I had off our big layer page that exists already on to do that. What you can do is go to view start. So if you're still in the Views folder, then you have a file called View. Start on that in view Start it will say layout equals Leo. So on the score, Leo, that's the name of the file that it is identifying as the layout. So I am just going to duplicate this on the comment. Oats one line, and then I'm going to change this to say, Underscore ad men lt on Then we can save all changes on. Then let's preview what this is going to look like. So notice when our application or the Lords were literally just a blank page, because that's all we have. We just have the skeleton on a section that's his render body. So if I manually try toe navigate to any off for existing screens and let's say I try to go toe leave types on, dismantle the log in notice that the logging is still loading with the originally wrote on that is because for that section off for application, we would also have to change the layouts that is being used. If I go to eras alone, entire identity go into pages, then you see a similar file. That's his view. Start on The View Start file is pointing directly to the lay old peach inside of views shared and layout. So I'm just going toe provocatively duplicate this and commented Coat on. Then I'm going to change this to see add mean LTTE that CSE html on. Then save on and let's try and reload this page and see what happens. All right, so we're getting an era, and this area is seeing that we are missing a section that sees scripts. Remember that? I did see that they're certain sections that have to be there for some pages toe work on did in our log in page, which is what I'm trying to render some distant to drill down and find or log in view or log in view. Those call a section called scripts, where it calls some partial view so that sexual needs to be present for the Leo toe work for the speech. Remember that we have a simply old here on for or originally wrote. We do have that section that I mentioned before where we render scripts. All right, so in our next lesson we'll start transforming this blank page into the admin LTTE Leo. It's with all off the required section so that all of four views can use it.
47. Setup AdminLTE and Dependencies: Hey, guys, in this Listen, we're going to be setting up our application with the admin. Lt e layout. I've been seeing this admin lt admin, LTTE. If you don't know what it is, then you can get to their website by going toe admin l t e that I Oh, no, it is. Ah, Bootstrap administrative dashboard template. And, well, one very, very, very conveniently. So it is based on bootstrap, and I believe that they have had versions too much each version off bootstraps. So right now we're using bootstrap four. So the version that we're going to be using is the latest one that supports bootstrap four . They also have support for fun. Awesome. Five icons. So that means we're going to be going through on potentially changing old some of forefront , awesome icons I would have used previously on we can retain for, but then we'll be implementing five also. So, from their website, you can go to their Donald Page. You can go to a live preview and you can also visit there. Get TOB repository where you can just you can just download all of the source required for this template. So I'm going to first go to the template, the the demo, and show you what It's all a boat. As you can see that navigational bar to the left, they have one at the top. They have little notification icons on, Well, the potential for data display and the layout is really, really, really amazing. There they come, chock full with libraries fall of these colorful charts, and they've put a twisted on bootstrap stylings where you know certain things, look a bit more find orbits, you know, modified when compared to the original bootstrap Leo. It's our classes, right? So you have the dashboard version one template where you know it's pretty. It's different side of different. You can the sparrows and get ideas from it. And then you have the version two, which is all we're looking at. Just know, So you can actually spend some time and click a row and see all the charts, the different forms, the different tables that they have bought. Then ultimately, you want to get to the documentation section where you can actually go a boat learning ho to install it into your application. Now, the installation instructions are merely geared towards in PM, which is more pockets Manager Bore, which is a package manager for JavaScript, or composer, which is, Ah, package manager for Ph. B. But then we are using dot net core, so don't Record has its own pocket manager in the form of new get and it goes to some extent a loaded to use bower. But then, personally, I find it more irritating. Trying to get these kind off libraries in to a dominant core on, especially since it is pretty much straightforward, is just some core that they have given to us. Once again, it's open source. So in this video, understand to guide you on sourcing the cord on implementing its inside off or application No, by the time off. This lesson admin LTTE two point for is the advertised version here. But that's not the version we're going to go with, so we're going to go to get up on. I'm going to say don't know latest release, which is going to bring us to their repository for at mean LTTE three points or point one. So know that we're at this repository in the scrolled on get the zip file with all off their source scored. And that gives us a nice, healthy folder with a bunch off read Mies and some more templates that we can look at. So the temple so early can't may not necessarily have been indicative off the latest version. So I'm just going Teoh extract this toe folder on my computer. So I put it in my downloads folder on Then I'm going to just open one off these pages. So I have three index pages I can look at on that also have started someone to open each one and that we can assess them off. So I opened index, and this is what the index speeches displaying. So you see that the widgets understands that's slightly different from what we would have seen on the website. Once again, the website was probably showing 2.4, which is based on bootstrap three. On this is showing 3.4 point one, which is based on bootstrap four. So you see some, you know, improvements in the way things are laid out. But we have this dashboard example. We have dashboard where this is dashboard three. So have dashboard to example, and then we have dashboard three example on, then we have a very, very simple sample, which is called Starter Now, the start a template is much more simple than the other dashboards on Truth be told, based on the application that we might have with me or may not need all of those, um, charts and displays, right? So for our application, which is a leave management system, I don't need a charge. I mean, the any mop off a country are these kind off land grabs? I really don't need all of that. So the started template is a good place for me. Toe actually be able to examine the court on make those transitions over to my project another thing to notice that in the bonds off fires that we would have gotten, they would have given us all off the CSS and JavaScript files required to get this steam up and running. And we would also have ah, wealth off plug ins for all off the charts, the data tables on everything that would be included inside off what is being displayed in their templates. However, we just need a few off these things to get open running on one of those is the starter, someone to right, click on starter on Open it with. I have no part plus plus if you don't have it, that's a great tool to just view. Um, you know it mark open and simple court files. If you have visual studio code, that's also a good tool on anything short of that is no part. But I would suggest you get at least know Pat plus plus or Visual studio Court. So I'm just going to right click on Open With All By plus plus, and this will give me the entire HTML page with that whole each team, a skeleton that I always talk about on. They will point out what is being included, what fast and where they can be found on. So we can source these files inside off the fans that were in the archive and pour them over to our project in visual studio while we set off the steam. So the first thing I want to do is copy all off this score on, Then I'm going to go back to my layout page on. Then I'm going to control a Onda and control visa. I'm just We're we're moving everything that's there and I'm pasting this entire block off html. No, In doing that, I would have removed some things like the render body section on. We're going to put that back, but you notice that they are giving you comments to kind of guide us The what section off the court you're currently looking at. My next major objective would be to make sure that I have the required style sheets included in the project and that my references are correct. So I see here where they have a style sheet inside off the dest slash CSS folder called admin lt ee dot mean dot CSS. So I need to make sure that I have this style sheet inside off my project and I'm referencing it properly on visual. Student makes it relatively easy to get files over someone to go back to the archive folder , go to dissed, go to that folder called CSS. Identify that file on, then I can actually copy and then go back to visual studio on. Then we know that in our visual studio project to try to keep those static files, those CSS files instead are inside off W W root CSS and then I can just pieced it in that folder. No, I can do that. Same operation for or fund. Awesome. So it's in plug ins funds Awesome. Free CSS all mean that CSS So I'm just going toe go back and try and find that. So it was plug ins on then front. Awesome. That's free on then CSS on. Then it was all that mean that CSS I'll do the same thing where I copy on then go back to visual studio on then. Right click in CSS Onda pieced. No, at this point are actually forgot, Holder, right? The path to the CSS fools understand? To look back in my original Leo pH Just for some inspiration on. Then I see here where the HR should be till day slash CSS slashed the file parts. Understand the copy that fire path to the fuller since all the faster and that seems CSS fuller. And then I can just replace the relevant part so well, those ccs already CSS arias. I can actually say till they slash CSS on. Then just to make sure you at the right place, you can actually just remove this your control on space and then it will list all the files . If you're seeing all the facts, that means you've written the pop. Partly. So I'm first, including the admin lt. No, that's incorrect On first, including all that mean not CSS on. Then I am just going to modify this one toe include the admin lt CSS file. Now, the admin LTTE file pretty much encapsulates all off our bootstrap classes so we can still access or the classes from booster that we know in love on. We don't actually have to go and reference bootstrap against. I'm just opening the ltte dot CSS file so that you can see that it is really using a lot off the bootstrap classes on the bootstrap version on this 4.3 point one. So most of those classes, if not always still work, But they would have put their own twist toe hold. They would be output to the screen. My next major objective would be to the to do the same set off steps with our job, a script files. So I see here where they need the g inquiry. But we already have jaker. We already have Bootstrap but we do need the admin LTTE that Js file So if I drill down into the GS Well, not Jair. Sorry, the lib on. Then we will go down into Bootstrap dissed on Js on. We also have the same for Jake Worry so I can just modify the references for Jake Worry and Bootstrap. Actually, I can just go back to my vote on reuse those references. So that's the J. Corey and that's the bootstrap on. I'm going to copy those and then I'm just going to replace these references because it's referencing the same set of files on then for the admin LTTE on went toe have to go into the Js folder inside off their dist. Find the G s file copy it's on, then put it into the project. So I'm just going to put that inside off the GS section pieced on. Then I can just use my till there. So then that's still this slash gs slash admin LTTE that mean that gso No, I have my Js files and my CSS files being included. All right, so we've done quite a bit off work are simple as it may seem on DNO. I want to preview what this speech will look like. So But before I do that, let me just set the title to be as dynamic as he used to be. Somewhere back to Leo. And you find that you be boring a lot from the existing Leo or Paige because, I mean, you did a lot of work to it. So instead of retyping, then you will be used reusing a lot of things. So I recommend that you don't delete it, at least not yet. Some just copying the existing title on I'm pasting it in the new Leo Peach on. There are other things that will be transferring, but right now I just want us toe view what the page looks like. So understand toe preview that pretty quickly. And when we do that, we're getting this very nasty arable s a steak or time and read what it to sing. So it is saying that we have an invalid operation exception where render body has not been called for page at and then they just list all the path toe over new leotard. So the key takeover is that it's complaining about the render body section, so there's no render body function being called. Remember in our originally oats, we had that very, very crucial section where we said Render body. So we need to make sure that admin LTTE knows that it should surrender body No based on the sections that are given for the page, we know that the body should be rendered in somewhere with contents not sinned enough bar not in the sidebar. The MIT sidebar menu bought more in the content era. So I see here of content or upper and then I have a section that's his mean content. So that means inside off my main content section. I should be rendering body. So this is all sample data, As you would know, from looking at our our Leo door or starter sample page, that's all. Just sample date. I really don't need that. So I'm actually just going to take all off this section Haute. As a matter of fact, it starts from starter page. So everything that is inside off the Deve Container fluid I'm going to remove or well, actually, I'm just going to see from content. Rapper so content Dash rapper Everything that is inside content. Dash rapper, I am going to removes. I'm just taking all off this boat, right? All that it was used the plus sign until well, the minor sign toe, you know, condense the sections. Alright on then I'm going to take all off this oats on. I'm going to put my function to render body. No What? I do that and save and refresh. This is what we end up with where sister have some ways to go. But this is progress. You can see here that the new layout is being displayed on our content, is there? No. We need to make sure that our nav bar displease our navigational links Are not the sump links? No, Back in our layouts, there are few references that I want to make Sure I include from No, lest I forget later on. So I'm going to go back to my Leo Ph and that I'm seeing that. Okay, I have some core libraries above someone to make sure that I make reference of these libraries inside off this layout and they go above doc type. Andi, I'm going to make reference toe some of these style sheets, so I have a style sheet for my table by data table. I have one for fun. Awesome on. I have one for my geek. Where you wise? I'm just going to take all three, even though I don't really need the funds. Awesome. One for this because we're changing the version off front. Awesome. Some archer Justin to delete that one. I just did that because it was easier to just take three lines and delete one. Um, so we have all of our CSS references on. Then I'm going to make sure that I make reference to my data table as well as my G s and G . Query filed someone to copy those also and make sure that I include those scripts at the bottom off the page. And then, in addition to those scripts, I need to make sure I render the scripts sections. I'm also entity that do it in one seat, but that's fine. So I'm just making sure I've accounted for all off the references from a existing loads because their pages that depend on these. So if I were changing little that we want to make sure that these are included now, another thing is that I I mean, it's like misjudgment with our bootstrap bundle where it is bootstrap dot bundled up men dodges on not the bootstrap dot Js file. So actually needed to include that file, and we found it inside off Brogan's Js Sorry. Plug ins. Bootstrap Js on the file is bootstrap dot Bonded up mean that GSC could copy that. Taste it inside off the GS folder alongside l admin lg that mill dot Js on Then fix the reference accordingly to make sure that it is included. Now, another thing I omitted was fun file for our funds. Awesome. Noticed that we have squares where you should have let the icons. And that's because you did not bring over the Web funds folder from the fund. Awesome. That's free. So I'm just going to take this folder and copy it, and we have to put it in our project in a very relative part relative to CSS. So noticed that it is beside the CSS folder. So weapons has files? Sure, but then relative to the CSS folder there on the same levels have to make sure that I copy this folder and place it in our project relative to see assess. So the only place I could place it relative to CSS and have them side by side is if I put Web funds as our folder inside off the W W root folder or our section, so different people may a little differently. I'm just trying to keep it simple. So after making those adjustments and reloading or peace and we start seeing over icons so you see that little chat icon, the Bell icon and where they were squares. There are no icon. So no, we have or icons up and running on. We can continue with or modifications. No, I did say that we were supposed to be modifying over navigational properties, and I'm going to go step by step. So this is the nub bar on that is the top note bar. So this entire section, if I just click the talk that's is enough, we can scroll until we see the next highlighted one. And we know that all of that is the nub bar, and then our number has sections for top of bar links. So if we want links in the top on dry, no, they're giving us 14 home on one for contact. If we want them there, then we can just change the motive. We want more than we can just duplicate. And at more. I don't want any enough navigational links in the top. Some just want to control Casey to comment. The moat. I'm commenting the moats, but you can believe them if you want while committing them all. Because maybe we may find use for them later on, right. And it's easier to keep the template than to try and remember what it looked like. So I don't need that search bar, at least not yet. So I'm commenting that also then over to the rights. They're seeing that we have a message drop Don't. So I can actually just go in preview what that message drop down looks like, all right. And then, you see, now have a bunch of broken images. But we didn't bring over the images because you don't necessarily need them. But right now, I don't need any messages. Notification on. We see that we have the little bell with the notification surround. I don't need any off these notifications, so I'm just going to t those old but It would be really cool if maybe for every leave request or every new item that comes in that requires action. We just display a number off there for that on That would be really cool. However, I'm removing them because I really don't need them, right? No, This entire section from the open to Close UL would constitute the right inside off the never never bar and so I can actually just condense it or collapse all off that and I'm going to manual the type or the comment cords that that's an ad sign on and on. Asterisk Andi will open and close it almost automatically for me. Someone toe caught that on. Then I'll have to be sure that I am closing the U else understand toe place that comment at the end of the U. S. You know, all of this is commented once again, you could delete it, but are leaving it in case we you may want it later than you can have it. All right, so our love bar at the top is pretty much empty. It's literally just there as enough bar, and it's not buyer dash light. It's white on. I mean, it's It's it's there. So it May added, may subtracted. It's neither here nor there. What That not buyer does at this point Our Children second thoughts. I just remember that there's a portion off this knave by that I really do need. And that is the part to make a collapsible. So this section that you know, I can click it and it expands or it it contracts actually want to retain that on that is phoned in the US section for push bars. So if I look very close to dinner, see at the top off the the enough bark us actually have ah on on orderly section that I would have commented out earlier on Did it has the enough borrowings for the home, the contact, but it at the top it has a section for the push menu or the buyers. So what I'm going to do is just on command this section because I really do want that section so contra Okay, you on, then what I can do is just commend haute, the two links that I really don't need. So I just want to routine the part with the pills that alot Mito me the side buyer go in Ah , wrote No four or me in sidebar We would see that it has something toe maybe the index speech, because the sample Andi I mean, that's fine. That's understandable that you come with that, But we can always change all that e treff. So something else. I'm just going to put a hashtag so that it goes nowhere. It retains its class on. Then it is waiting for an image. So I'm not going to put any image. I don't have any image, but then in a later time, maybe you can modify the application that it accepts an avatar for a user on. Then, when that users love being that ABBA tires displayed. So I'm just going to comment old this section for a picture on then for this spun sexual as his admin LTTE three. I'm going to let it say the name off our application, which is other say, leave managements for this section off the sidebar. I wanted to display the logging sections. Remember that we have a logging, um, partners is logging and register on. We had that on the previous, um, Leo. It's where we had the six John in the nav bar, and it was really a partial that was being printed. So the court for the log in and register links are really inside of this partial. So I want that partial to be rendered in this section. So I went to take coat the content of this sidebar on I'm going to replace it with the par show for our logging hundreds, the buttons on. Then I'm just going to add a little visual effect and put a horizontal rule so that there is a little line to show where this section starts on there where the next section begins. All right, so this is what our work has yielded those far We changed with sections of silly management . We have the tool ings, and we're going to put somewhere stars on that because notice that they're visibly different from hold. The other links look, but for know they can remain on No, we need to modify hold. These things look so noticed that you have one section that can drop down on. You have a simple ing, so I'm going to be creating some links that are looking like the simple ing on. Then we'll be creating a drop down section for our love bar, so back in our cord. So I'm going to start off this transformation by just dissecting this, not barcode a bit. So we have the UL on did. It is it has all the classes that are required to make it go to the side. And then we have the first list item on this, like a list item has a classicists, has tree view menu does open, and then it has a link on then another on order list inside of it. After that, we have on list item that has the words simple ing. So this list item can be our template for non expandable link items on this one can be our template for expandable link items. I'm going to take this one. That's a simple ing. I'm going to cut it, Andi. Then we place it above the one that says has tree view No for our Simple Inc. We're going to make a few modifications, notice that we have an ankle tag and it's pointing to nowhere. So I'm just going to go back to our original Leo on. Then I'm going to copy the relevant parts for toe Have a link someone to take the SP area SP Controller SB Action section off the anchor tug Because I want this first simple ing to be home someone to replace a true if with those with those those attributes on, we leave the class on. Then I went to change the icon from FAA Dashti aged If a dash home and noticed visual studio is making these suggestions because the CSS file forefront awesome is not part of the project on then I'm with the chance on the text from simple ing toe home so on this one to stay home and I really don't need that span. All right, on, it's good. It's a good idea to kind of retain the temple that they give you, because if I was to remove those p tags than the layout would be slightly different from what I'm seeing in the previous. So you have to be very careful and deliberate when making modifications. If you want to retain the original look and feel so I have the hometown and I'm going to duplicate this tool times because I also want the tack that say's tuck that says Apply for leave on also one that sees my leave So going back to the original links we had one. That's it. Apply for lease. I'm selecting or taking all these attributes from that link on, then placing them inside off my second Simple Inc that's replacing them. And then the text is going to be apply for leave. So this copy that. So I'm doing a lot off copying and replacing off existing being sold the same thing for my leave on DENR. Replace those attributes accordingly. I really don't need to bring over the class because you notice that the classes now dash link. And yes, there's text white. But it says now dash link already in or Uncle Attacks are really delete. Er place that again. So just replacing the real event attributes so that Uncle Tags work all we expect them to work no for the next section that features a drop. Don't recall that or drop down from or original Liotta would have bean active or visible only if somebody signed in on even more so if they're sending as an administrator, so we can actually just reuse these estimates. I'm just going to take these statements, go back on, then I'm going to paste on. Then everything is getting indented and out off work. But that's no problem, because at the end, off this ally block, I'm just going to put two races just the clothes off the statements on. Then all off, our code will be realigned properly. So if the person is signed in and if they are administrated, then they will see this drop down section. And then this drop down sexual needs to have the same links that were in the urge. No, the top most level off the drop zone had the word man, it's understand to take the word manage, and I'm going to replace the very first link with that word. The content off the the top most, um, item or navigational item in the entire drop known should see manage notice that the right of it he will have an icon Nazis uncle left, so it's kind of like a drop down. It will toggle when it's, you know, hope are known, Um, and then the tackle meters. So I'll go through and change these icons later. But for no, we want to just focus on the nav bar items and the links, making sure that they go to the right place. So then the contents off our enough bar would be under enough dust review and you see that we have to Ling's here What we need four. Some just went toe copy and pieced one off them two more times. And then we can start over surgery where we starts changing all the text on the references are the a trip. So I'm going to do that quickly. We did a few already Someone to pause the video are You can pause a video right here and try to yourself on when you want pause. I would have done it already, and then we can just compare afterwards. All right, so the end off that exercise, you should have something looking like what I have on the screen. I also took the liberty off changing all the icon. So I have something like a list for the leaf types. Have Effie Dash Angelis for allocations on Actually did this blindly. But all that it was great. Effie Dash and then a little bizarre ceded to suggest toe what I have available to me on. I made blind decisions. You know, if you don't want to make land decisions, you can always go to fund. Awesome. But come on. Since we're using version five, you can proceed to goto icons on. Then you can see everything that is available. So pretty much. If you see listed in the intelligence and you want to know what it will look like, then chances are on more than likely, you can go over to front Awesome the website on Just type it in on. Then it will kind of filter wrote and show you what your icon might look like. Another thing to notice that more than likely it will be the free version off what you see in the listing for the 1st 3 navigational links. I also made changes because author of them would have had the home icon. So I'm changed those old also Andi, I'm going to make one more adjustment, and that is to the log in page, because if you observe and let me just go back to my page if you observe that the log in Ling's don't quite look to like ho or nut bars, links look. So want everything to look uniform as much as possible. Someone to modify the layout off our partial logging page on. We'll see how that works out. So this is the log in partial pidge Andi. As you can see, the UL, it's lacking some of the classes that the U els for our sidebar needs. So if we look at one of the existing ones, we see that it has classes. Love, knave Dash bills now have dash sidebar and flex columns. I'm going to take all of these classes and make sure that they are present inside off the log impartial. So no, the not bar will look something more like what we have already on. Then the list items inside off that you will need to look more like the list items inside off the existing one. So these list items they have the ankle tag on, then they have the icon, which off course is optional. But it's there and they have a P tug. So all of these things actually work together to give the kind off effects that we need some discipline to perform. A little modification on this are really their uncle Targa, Just brake line. Bring the text over. So this text is what is saying hello person who is logged in. So I want that to be display. So I wanted to be displayed inside of a pita on. Then I'm going to include an icon just the same on the icon. Here can be maybe, like a silhouette off a person. So I'm going to say icon, tug class and then include my f e or F E s this time because they're changing oats. The the front awesome. So it's F e s. And then if e dash on, I will see user dash out. So that is, that icon is going to show beside the persons using the once they are logged in. Next up is this button, and the modifications that I'll be making will be pretty similar. So I'm going to take all of this content, replace the word law goat on, Then in the P tag, Well, it's going to say low goats. So that's law. Goat on day butchered the Pete. I got bit there so that me do that again and do it properly this time. So that's log boat instead, off that Peter on for the icon. I'm going to do something. Like if a embassy, they have anything about signing Also. There we go. I have signed while that sign in we have signed olds. Terrible. So f e d sign note out someone to modify the other two off screen, and I'm challenging you to meet mods. Chose to zero in icons. Use your own creativity, but I'm going to do it and then we can compare court afterwards. So I have two icons that I included one called Effie Dash registered for anybody who wants already surf with us. Whatever. Just the link. And then we have evade us user for the logging. So you I mean, I'm repeating a few I ponds around the place, but ultimately, once again, you can choose your own icons and do what is right for you. What? I'm going to save all these changes and go back to my age Reversion. See the fruit off my labor? All right. And so I'm seeing a nest are for register on the silhouette for log in. And just to make sure that I wrote the court properly, I'm just going to click this and watch it expand and contract properly. So just like it did in the them over the text completely disappeared and only show the icon . If you did not write the Todd's or the list items for the navigational links properly, then when you try toe contract, then it may not be as clean saying me want to review that. Either way, I'll provide the court for it so you can always double check or replace. Now, the final thing that I'm going to do is replace the content off our now our four footer on . I wanted to be a bit more official, but it's always good to give credit toe the persons who create the themes and the open source things that you you. So I have ah footer message here on this filter. Miss its is to the right styled by and I create a link toe admin. Lt e dot io Andi. I retain that original footer message from our previous layout. So I'm just going to log in as admin so that we can see the rest off enough buyer and verify off the word that we've done on when I go to the log in page. You see that? This page could use some work. It needs some modification to fit into the theme Better. But I'm going to leave that alone for no and log in as the admin. And when I do that, they're seeing some squares appearing. Where? Where icons should be Some Justin to double check what's happening with the code Onda. Okay, so I see here where I have if they are instead off if he s so that might have been there before. The temperature may have come with F e r for that section, but I want to change it o f a s because that's what I really want on. Then save. And then let's review that again. All right, that's more like it. So, no, we're seeing on one is still missing. What? We can fix that later. So at least we've made some progress. We're getting icons, and we can see that we have this drop down menu for certain Well, for the admin on when we're not loved in this admin, we won't see that also, when we are logged and we see that it is saying hello on the user on We have our low goat link. How much you're going to remove the word Hello? And I'm just going to print. Oh, it's the email address that is associated with whoever is logged in. So that's those are the modifications I'm going to make. I'm going to fix this icon. I'm going to remove the word Hello on. I'm going to see what's up with the log in page, and I'll share all of those with you. But if you stuck our own to the end and, you know, have the admin panel looking something like this, then good job on.
48. Essential Layout Fixes and Additions: Hey, guys, welcome back in this video lesson that will be going through some essential fixes that we would meet me to our layout. So I did leave the previous video saying that I would remove the keyword hello from the section where we're displaying the user name. I did fix the icon reference. I had injured list initially and that was not included in my fund set. So I changed it to User Plus and I made an even more critical fix for the Lay. Also, if you recall when we had our log in page and I just navigate to that beach weekly, it was, you know, attached to the side buyer or too close to decide by that margin was not defined enough. And so every other page was kind off rendering in that fashion. So we I mean, those fixes off camera, and I'll just show them to you. Um, so for over Well, for over long, impartial, all it was ruled the hello keyword from the section that renders the user name. I'm hoping we're all comfortable with icons by No, So that is so. I fixed that square and the the icon that was ensuring parity. So I changed it to use her dash plus so that's always good. If you try one and you get the square instead, just try another. And then the most important section which affected over Leo was our content section. So I had removed a bit too much court from our content. And so it was not rendering properly. So I needed a give called content Ash header which had its fluid container fluid inside off that if and then add another one that said content with a container dash wouId give also and in that we rendered the body. So if I go back to the original template, you can observe that this was the original code. We had content, referendum it at a bunch off sample information and then it had content with a bunch of sample information. So I had inadvertently removed too much from inside off these dips. So what? That it was reintroduced them and then this time just removed from the rule onward and then replace that with the render body and so over content is no rendering properly. So you can positivity right there and copy off the cart code. If you, Nieto, but I'm going to press ahead and I'm going to make a few other modifications to some existing elements in our sight. So I went over to our leaf types page on. We're looking at the data table here, so some off the icons are missing notice Some of them look different, but then the pen so that was there is missing. So we need to make sure that no, that we've changed the version off the the fund. Awesome icons that were you don't going through and making sure that our icons are showing up for each page. So they're missing from allocate employees. Notice the text in our leave request pages, Not quite how we left it on. At least everything is okay with our employees speech. Another slightly irritating thing is that this link seems to always be active. So I'm going to modify this thing So it's not always active. So starting with the modification off the link, if we look at the court for the link, we see that it has a class called active. So I understand to remove that So all the links look for seem if we wanted it to change activity, then we'll have to read some other court. But I'm not letting into that right now. I'm just making it look a bit more uniformed. Next in our leaf types in XP, Jim went to modify the icons used So first, then went to say F A s. So we get the that class and then I'm changing this from Effie Dash, pencil toe, maybe. Well, pencil dash out is what they have for me. I can leave the inflow circle and leave the trash on. Then we can review that. Those changes now we're seeing are Pensa icon once more. Now I'm just going to take a trip over to our detail speech because we created it a while back. But what we did was to tell it explicitly which layout's page to use. So when we created our new Leo to would have set it as the default on, however, that can be overridden on a specific Pedes. I'm just going over to that detail speech on you would see here where it is specifying the layout to use. So this would override that default setting that we put up in view starts. I'm actually just going to remove this. But if you have the admin lt d more have a theme. Working with what Have multiple Leo, Peaches, anyone? Some pages to use one and not the other. Then that is how you can specifically override that little reference for our I locate Leave allocation index PGE I'm going to change the icon Toe FD Dash User Dash edits on that will render something looking more like this with that pencil with that silhouette and then I'm going to give or leave Request age some attention. So firstly, I'm going to remove this, um, this text that is index and I'm also going to remove this button since we didn't really implement anything for this button and then I'm going to modify the display off these cards on the data there in so back in our code, I can simply remove these stop two lines the H one type for index on the button for creates I just remove those on. Then let us review our cards. No going back toe or admin. Lt Age or sample pages that we would have gotten in our archive file. I'm looking at the widgets page and I'm seeing here their idea off what widgets can look like. So I like the top row off widgets. I think that they fit in perfectly with what I want accomplished. Now, in order to find the court associated with the displayed widget, we can just right click it or to inspect Element. And that will bring up all of the court associated with that widget. So inspect element is a nice to lake and use the assess. What is going on? So you see that they have the rule. Then they have the call MP three, the division, the same divisions that we have for over four cards that we implemented. But then the me in part is that you have in four box and then inside info box. They have some content, so I'm just going toe collapsed. This def. That's called info box. I can right click on. Then I can copy on dykan, copy all of the other spot copy elements, and then go back to my cord on, then inside off. Call MD three. I'm going to paste all that I just copied. So, for each call MP three that we have, we have that info box. I'm just mental duplicated across each one before I start meeting any modifications. So that's that. And then it's easy to modify and incorporate because I already have all off the script files required for the info box the work. Now let's start our modification. Notice that what we copied have static text on. We just need to support the static text with our dynamic text the same way. So we have the content area on the content era has some text on some numbers, so we remember that we had hired Title, which had the text. So this is total requests. So I t this replace the word messages and then we had the cones value on Die replace that section and then I can do away with my original card and then I'm going to do that. Suits your own for each one off. He's going forward, so I'm going to do another one for you, someone to take this value that we're dynamically generating. I'm going to replace messages on that. I went to take the number and then replace that number, and then I can do away with that card, someone to do the other two. Andi, I'm going to resume Having done them, you can pause and do them yourself are great. So I hope you had no issues on dure coat looks similar to this? No. The next thing that we want to do is change the color. So we have B g info. Remember that we were using different colors for the different statuses. So pending requests would have been BG dash warning. Um, then we have B g dash for approved success on notice that we have BG greedy in successfully . If we want a greedy in color, we can do that also. And then we had B g dash danger Onda leave. I leave. The torture report says in for the next thing that you probably want to do is change out the type off icon being used. So, for instance, spending request. I'll probably use something that is like an exclamation to say, Hey, you know, attention required on these. I use chick circle for the approved requests. All right, so I'm just going too fast truck. I'm not going to bore you with my selection off icons, but I just want to show you what it should look like at the end off that exercise where you have your icons being displayed. If you try and icon and it doesn't work, chances are that the first part off the classes, if they are on you want to change that? If he s so you can try that modification. So you see somewhere fire based on the template that we copied and some are If he s so me work so me not work. I'm not going to bore you with why one will work on why one will not. But you can destroy and try all the icons and see which one is a good fit. No, I have one more modification that I want to make for this particular lesson on that is surrounding the data table. So yes, they look nice. But then there's actually a bootstrap four look and feel that can be applied to the data table on admin. LTTE does have the plug in fast to me that happened. So we go back to our archive with our admin LTTE files and go into plugging shorter than you see. A folder called the Data Tables Dash Bs four and that comes with a CSS file on a J s far, so we just need to copy those over toe our project like we have done with other files in the past. In case you for button, I'll do the CSS won for you by clicking the the one that ends with men dot CSS copy and then go over to the project and inside off the CSS folder. I'll right click and Click Paste. I would then repeat those steps for the JavaScript file. Next, I'll go back to the admin LTTE Leo Page on in the section where I had originally referenced the data table, sees this file by CD and link. I will know replace that text with a reference to the local CSS file in my sis's folder for data tables who strapped mean that CSS on in like fashion at the end off this blow peach, I will replace the reference to the script file with a reference to the local GS file. So that's still there, slash gs slash on, then that is the tables who'd struck then I can see if this on then test my changes. All right, so my page reloaded and the whole table went away. So that means I'm missing some file reference summers understand? To inspect element Onda, check what is happening in my console on it is telling me that it cannot find some function call, and it's pointing to geek worry. So I believe that I am missing some other J query files. I want to go back to my plug ins. Andi, I'll check my details. Tables folder. Ah, so I'm actually missing this essential Java script file, which is just required for data tables altogether. So I'll just copy this. Andi, bring it over to my project. He sits in the folder, and then I'm just going to duplicate the line that includes the data tables. But then above the original line, I'm going to meet reference to this new data table J Query data tables file. So I'll save that and try again on we have lift off. So no, we're seeing or data table looking a bit more refined, and he kind of fits into the, you know, the entire project a bit more so we see that we have the same functionality of you. We have our search have or filter what searches of filter we have or paging Andi. Everything looks more uniformed. So I hope you had fun doing these exercises, you know, restyling our pages. I'm just going through making sure everything is okay. But I do know that there are a few gaps. One, there is no homepage. We have gone this far without making a homepage. I'm challenging you to come up with a nice creative home. Be it share with me. I'm sure that I find value in the way you did it. I'm going to come up with one myself. On also there other pages that maybe the icons have disappeared. Or maybe the page wasn't, You know, not much care was taken in the actual putting together off the page when we were working on them initially. So I'm challenging you to just go through the project, clean those off change of those styles and make it as beautiful as you need it to be.
49. Custom Login And Registration Pages: Hey guys, welcome back in this lesson will be looking at setting up a custom log in page and registration page for our application. As you know, we've been working with the admin LTTE theme and so we'll be drawing inspiration from the steam and their presets toe design, our own log in and registration forms. Now, on my display, you'll see the admin LTTE log in screen templates where they asked for email address password. They have a remember ME box assigning button, and they also have buttons for any other signs in engine that might be in use. Also, they have links for Forgot my Password and register and new membership. You will also see that they have a registration page that is very similar in nature. But the fields will be different and relative toe the information that will be asking or users for to register ultimately from anyone off the sample pages. Whether it's index 12 or three, you'll be able to access the section that says extras. So in the knave barter left, you see extras and then you see log in and registration links on both off. These links lead to the previously shoulder pages so they don't give you those sample pages on. You have some other starter and air for four or four pages and other pages that you can draw inspiration from. But once again for this video will just be drawing inspiration from the log in on the registration. No, I have already set up the log in on Die can click, register on and navigate to my registration. And if you take note, you see that I already customized either form toe my context, right? So I'm not going to meet this one a long lesson. I already this the resource is toe supports. The activities are included with this lesson, but we're going to spend a short time going through. Some of the customization is, and some of the modifications that had to be made, you know, it's a facility. This facelift no, on the screen is the code that I used for my logging pitch. But before I get into my court, I want to show you the original court and then kind of walking through Hawaii, you know, transferred its the changes I made on DSO. If you're going to be doing the same process as me. Then you can be got it accordingly. Now the original pages can be found inside the at admin lt folder inside pages and examples and then you see register and you'll also see log in. So I opened them both in Nope I Plus plus And let's start with the log in now the bloat is pretty straightforward. They have one additional statute which I did not bother toe include because I really didn't see the need for it. But you can include it and see what's different about it. But I didn't include this one. Everything else has been included. The star seat for iconic Framework is really a Cdn link which is scanned off, already implied by our use off the admin LTTE CSS files. But moving onward. The section that I'm mostly focused on was the Dave with the class logging box. So everything inside off that Dave, I actually copied boat, so I selected all off this give and I copied it over. But then I removed the section for the Social Loggins because I really don't have any need for that in this context. But outside off that I I took all off the cord associate ID with the log in page or set off that you noticed that the body has a class called hold dash transition on another class log in that speech. So I actually created my own live instead of using the body talk. I create that ideas. Andi. I reuse these classes, and that's what gets its center aligned on, do you know, displayed on the page as close to the demo as possible. So back in visual studio and in my court, you see that I have that divide the top with the classes, hold that's transition and log in that speech. And then I have the data for the log in box. I have the title lugging on, then inside off the card for the title I have sent into core leave management. I re included my live with the validation summary, so I actually took some off the court out off the original log in page on re included in this form. So I have the court for the validation summary. I started changing old the inputs for the elements so the original input from the template would have had input type equals email on the class and the placeholder while my modification to that was that I said input. And then I took the S before input that email from the original text box for the email on I used that to replace the type equals part because remember that once use our SB helpers, it kind off implies the type on implies the validation that needs to occur. But I retained everything else. I did that for the E more email text box, and I did that again for the past four textbooks. I also went ahead and included the section for the validation on. I actually should have placed that outside off this give because then it would actually appear in the same line. So I need to put that in between the Dave's. So I just made that change while we're here. And so the section the span for the validation message will appear outside off the input group gives from the template moving on. I didn't modify the remember me on die retained the sign in Andi. I didn't change anything with those for the four, but password onda register links. I changed the links or the paths for the ankle. Toxie is be dash speech on for about password. In the original, they would have had a drift, I think hashtag well, they had a trip something. So they're pointing to the other template pages in the admin LTTE theme for Forgot Password and for Register Sarah place those with our practical ones. But of course, once again, if you want to draw inspiration like, for instance, for the Forgot Pastor page, then you can do so. That's it for the modifications made to the large in pitch. And then I can move on to the registration page on you see that it's pretty similar. So I just go back to the urge now so that we can see what's happening. So you see, it's the lotus participle. The body has classes, hold dash transition and register dash page on die once again used the leave substitute for that body tag right there. I have a deep for the header on, and then the form. So you notice that the form takes ah, full name on. Then it takes email password and retired on the confirmation for the password. So my modifications coming from my original register page would have had first name and last name. So just the full name Dave Group Live Input Group on duplicated it and made one into s before first name on one into this before last name also made sure to include those validation spans just the same way after each input group on guy changed oats, the S before each input, so have input. Sorry. Have password of email of first name, last name and then have the password and confirmed password on then for the submission I to coat any other links and just use the button inside. The rule on this button is Bt and Block. So it stretches right across the screen and then for the I already have an account. I mean sure to just change it to sp page dot slash log in. I didn't make any more modifications on DSO. I'm just going to bring back to screen what I did on then we can screw tonight. So this is the registration form on this is over lugging form, as usually can always pause the video at the different points where you want to copy off the court either way have included the court references with this less. One more modification that I made was in my home control, where I set it to authorize. So what I don't want is anybody to be able to Bro's toe. Any part off this application without being authorized are authenticated. So by sitting authorized on the home controller, the first thing that's going to Lourdes when it trance alone. The home page is the law in pitch. So let's test that experience. So if I go to the application completely on Bothered, then it's going to load the log in pit. So let me try and Bro's directly from my website, and then that would try to lure the home control. But notice it went straight to the authentication pitch. He won't go anywhere else until you are authenticator, because I have put authorized pretty much on all the controller. So at this point, either have to authorize yourself or authenticators so sorry or register so you can have on a cones pretty much summarises all off the modifications that I would have made to the registration and log in pages. Andi, I hope that you, you know, follow suit, and I don't want to toe carbon copy me. Use your own creativity and try and get it toe. Look the way you would like it to Look, Andi, I'm always open to feedback. I'm always open to seeing what you are doing on. You can share your screenshots with me and we can all, you know, scrutinize all of our work together.
50. Review and Add Changes to GitHub: Hey, guys, Welcome. But this is our final review lesson for this model where we would have implemented a new layout using the admin LTTE theme. Just a quick review. We would have changed over the layout from our standard bootstrap for Leo. That would have come with our project on. We implemented this new layout where we have a sidebar. We have nice, intuitive icons. We have a few more animations. I would have customized the log in page on the registration page on then for our home page . Well, I would have challenged you to come up with something creative, but then for me, what? That it was authorized it so that when the application loads, it requires a person to log in before they are able to proceed toe anything else After logging in, the user is led to the homepage. And once again, I'm interested to see what you would have come up with for your homepage. I kept mine simpler and informational so that you can see exactly what this, um, this application is all about. Either way, I want you to be creative and to bring the best out off the tools made available to you. So I'm just going to go back to our admin LTTE sample pages and show you that we have a section there called the documentation where they actually show you how to implement most if not all off the plug ins and components that are, you know, included in this entire framework Andi building On top of that, the fact is that admin lt uses all of the bootstrap for components. So anything that you can use from bootstrap that we have been using upon to know it is also available inside admin. Lt just with, you know, a slight twist since they would have given their own flair to eat style. However, you can peruse all the documentation, look at the other plug ins on components or the other JavaScript components and see that, you know, there might be things there that you would like to use that I didn't use in my lessons. But you can go ahead and implement. And as always, if you run into trouble or difficulty feel, Frito, let me know and I'll be sure to help you. Like I said, this would be a short review as we're just going to you know, take stock off what we've done on, then go ahead and check in to get up. So I just right click my solution on click Commits Then I provide my check in message. So I just said that I implemented the theme and added required fast on then I'm just going to go ahead that current on, then commit all on sink after completing this exercise. Our court is no up to date on the link to this repository or to this set off changes will be included with this lesson as well as any other resource. Is that you mean need? If you have made it this far, I want to congratulate you. Good work so far on once again, be creative. Try something on side of the box. Andi, if you run into any trouble, let me know and I'll be sure to help
51. Asynchronous Repository Functions: Hey, guys, welcome back in this video we'll be looking at converting over functions into a synchronous functions and will be starting off with the repository. No, I have open the logging dot CS that see occasional that CS file, which is the court behind for our identity. Age is a ConEd fire for logging on. I'm just using this file toe depict what an asynchronous function looks like so would have seen asynchronous functions in use. The roads are application, Andi. Sometimes I use them, sometimes a skirted around them. But today we want to look at how we implement them and why they're either there. So when the asynchronous function is really implemented as ah part off the parallel programming paradigm which is geared towards making or quarter on a bit more efficiently and use system resource is a bit more efficiently. All right, so what happens is that in if core are dot net core and into different work, or that he was quite a few asynchronous functions and they usually use the word a sink at the end off the synchronous functions is here they sino tasing. You have the password sign in a think you have a bunch off them. But I think you'll also notice that the function definitions are also a think. So you will see something like public facing task on then the name off the function, right? So when it's avoid function, that's what it looks like. It's just public facing task andan on get So if you have a void for sure that you want to make internee synchronous function, you do it something like this. You would replace that void with the keyword task. All right, Any time you're making a function call toe une synchronous function, it has toe have the keyword away. So anywhere you see a sink, you're going to see the key word a wheat. So that said, those are three new two hours. I will be looking at easing task on await Andi You'll also notice that when it is a volley returning Foshan that you have task andan uncle bracket on the data type being returned and then close uncle bracket So those are things I want to look out for as we start to re factor are cord to be a synchronous I'm just going toe minimize the areas here on them would to start off with my eye repository beast. So here we know that we defined all the functions that every other repository inherits on. So I want every repository to inherit on asynchronous function. All right, so right. No, they're synchro nous their default the way we made them initially, what I'm going to do is see task open angle brackets around the the return type, which in this case, is I collection off time t t be ordinary class and then I close angle bracket on, understand to go ahead and do that for the next one, which is fine by I d. T being the generic class that we wanted to find on. Then we're that with the angle brackets. So these are all valley return functions that we just saw. The pattern is that we see task angle brackets are owned the value or delete the time being returned, and then close angle brackets. I'm just going to do that for all the others. All right, so no, every function inside off my repository based file is a synchro us. So I'm just going to say that on then I want to start a transformation with the leaf type. So I'm going to go to the I leave, type our positivity. That's a concrete clash in the poster photo. Sorry, Leave type repository. Not. I leave Tyra Buster the concrete class on when I get there, I'll see the Red line. Know the red line is there because it's saying that well, I have not implemented the interferes. That's really because I just changed out every function to be a synchronous, but I still only have the same Cronus implementations here. So we're going to go through these together on will be changing each off these functions to be a synchro nurse so that start off with creates. So we have public bull create. So, like we just discussed, the first thing we need here is public a sink, and then and we'll just see task. And then I went er up the return type, which is bull inside angle brackets. No, we're going to get a green line here because it's saying, Well, I see that you're implementing something a sink, but you're not doing anything. A sink? No. Once again, the racing functions that are given to us usually have the key word he think at the end. So, like ad is given those buy into different work. But I should be able to do at a thing. So if I come to the end here or if I just remove the dot the word add up to the doctor and then I do control space. Then I will see add a sink, right? So no, we have add, however, at a sink now another green line is appearing because remember, whenever we're making an easing function call, we need to precede it with the keyword await. I know that that is done. You noticed all lines are gone, all warnings are gone, and it is no satisfied that this is a good implementation off on a sink function and a sing function call. Now we can do the same thing for delete. So once again, we need the key word a sink after public. Then we say task angle, bracket the return type on, then the leads. Well, so it needs something asynchronous. So I'm going to look if there is any remove, isn't. And when I do that I don't see, I removed a sink. All right, so there some functions that they give us that Have on a sink Twin are alternative on there ? Some that just don't so, you know, way pick Andrew. So I'm going to leave delete, as is for no on move onto the next ones. Actually, I'm going to do that for all of the functions inside here. I'm really just into copy the A sink task on the first angle brackets and then understand toe pace that onto each one that I go to right? So no over find All is our public facing task angle bracket. Returning our collection of time e harms our leave type on, then under bracket at the end off that right on, then what would meet this season could be an A sink version off the to list? No. When I come to the end off the words to policed on press control and space, I would see intelligence pop up if there were more options on. As you can see, there's nothing popping up from person. Randall. There's something popping up that's really because there's no a sink being provided now. This is really because I don't have the library that I need. I need to make sure that I I'm using, I believe Microsoft dot entity framework core. All right, so the thing is, that link gives us some amazing functions. What? We're really limited toe Aleen Cust offer, but the Microsoft entity framework or library really opens it up. So if you don't see the racing functions his brother, because you don't have this library, if you're seeing them, then it means you have the library, and that's no problem. So if I come back to to list and then I press control space, then you will see that I am getting the tourist is sink. All right. So, I mean, if you're if you are still not seeing that, then maybe there's a bigger problem on, you know, you can contact me, but you should be seeing to list he sink right on. Then once again, once we're making a function, call Tony sink. We need to precede it with the keyword. Uh, wait. All right. On that solves that. So then we can just continue with this. Um, we just put this back in the clipboard on. I'll just be pasting it for each function on defined. Is there find a sink? There is a finally sink on DYP received that call with a weight moving on. Andi, I have this phones and I didn't modify this. The definition for the declaration off this function in the eye leaf type repository class . Ah, leave it as is. But I move on toe one that's actually implemented. So hes exists, making it in tow. Synchronous Is there any think? There we go on, by our way, it all right. So please notes that if you feel to put in the hour it even if you put in the death that for the header for the phone shown to be a sink and everything if you don't put our it at the function card and you're going to be seeing a narrow which is not really telling your hair. You missing the keyword easing. Oh, wait. Sorry. Right. So just remember to put in that awaits because the error doesn't really tell you that it's missing. All right, so next we have save making that one asynchronous there is a safe changes a sink. There we go on dive, prevent it with the keyword. Await over to update make it a sink. Is there an update a sink. Let's check. Okay. There is not an update, A sing. All right. But then you notice that save is giving me an error all of a sudden. And that's because save is returning at type of task boule when this is expected to return a bull. So yes, you may see Task bull here on this is a turning task bull. But you're still going to see the arrow once again. If you're making a call toe on asynchronous function, whether it is defined by you or it is one that's given to you by the framework, you need the keyword. I wait. So once I put in a way, it's than everybody is happy. All right, So you may not be ableto you know, do the F core part is synchronously. But at least if we have this implemented as asynchronous, then we would be ableto call or make use off that asynchronous functionality. Now, given that there some cases where we can make it asynchronous in some cases where we can't , you know, you gray outside, you could put it some places and not have it some places. That's perfectly fine. I mean, the fact is that you may have the option. Some things they may not. All right, so if you go back to create yes, we had the ad facing but then we're calling another a sing function here. So this is one easing function call. This one was given to us by the system. But then this is our defined function, which is a thing. So I need to say a weight on then for delete while removed didn't have an amazing We do have a fortune culture on a sink function. So look at what happens if I did not make this whole function is synchronous Then I will be getting on error here on then it will be seeing cannot implicitly convert the type on. Then I would say Oh yeah, because you think I need a wheat and they look at what happens when I say Oh, wait. I get an even bigger error because the fact is that if I'm going to call on the synchronous function than the function, making the call also needs to be defined as a synchronous tried. So those are little things. Little gotchas. Once again, the errors may not be as clear sometimes suggestion is not the best or the actual solution that you might want in the situation. So it's good to have an understanding off what each situation cause for no. When we look back, we see that we have implemented I leave type repository successfully. Andi know a repository for leaf type is okay so we can move on to the other. So if I go over to leave request repository that I'm going to see the same red line on would have to perform the same kind off surgery on the same thing for leave a location. So what I'm going to do or what I suggest you do, it's positive video. Attempt these for yourself. I'm going to do them and then when you resume, we can compare our notes. Alright, some back and I will pick up with the leave request repository. So firstly, I'm modified. Leave requester positively by turning the well. I leave requester posture by turning the one definition or declaration sorry in tow, a task function. And then I proceeded to change everything else into a task much like why didn't I leave repulsed er there certain ones that were on exception on Well, really. The get requests by employees, I kind of had to refractor the court because what happened is that I was returning. Find all dot where? Everything else that you notice that where doesn't have anything on the to list in this situation does not have on a sink. So f core actually gives you these link functions the link functions being the wear and the tourists and the first our defaults and those kind of functions they give you them when you're directly interacting with the detail, be so like first our default in this situation, it's directly interacting with the database. The to list a think is directly interacting with the database. However, in this situation I had to define a variable call. It's leave request await the results off the find all function call which I changed into an easing on. Then I returned the leave request that were actually so these willing functions are not interacting directly with the database anymore, but no there interacting with just another variable, right? So that some situations you see the link with the A sink on. Sometimes you won't see it. All right, so that's why it was important that we included the Entity Framework Library because the library works against the database is not necessarily the data sets coming or the data results coming from the database. So after the fact to the court a bit so I could facility that weight on the final on day, return the results accordingly when we just, you know, reform out that everything else, though, was pretty much in line with what we did over in the leaf type repository. So I'm sure you had no difficulties there. And if you did, then you know you can feel free to pause the video on review these functions as I'm scrolling through and focusing on each one. All right, so next up we have the I leave allocation or poster, which had three additional custom functions, which I also changed into tasks. All right, on then, in the implementation, I will have to do similar factoring. So in this case, we're returning. Find all dots were you know, everything else. Instead, I created a variable away to the results off the find all on. Then I returned results thought were so you know you can in fact, it accord. You may have foot face difficulty if you figured he told them. Kudos to. If not, then here's our way our own daughter and difficulty may have faced. As for the other generic ones create delete orbit. Andi is exists and find by I d on find off all of those Look the same. We're pretty much we have the to list a thing where the first, our default a sink on, then for the other custom ones where we had to find all on we quarried on them added the same thing where I just well, the results of the find all inside off a variable on then returned the operation against the results off the find all the same thing for the gets leave allocation by employees and type rand, Everything is pretty much looks to seem. The cool thing is that our posit Torrey should behave more efficiently when querying the database when carrying out our quarries and such. But then when I build, you will see that we have a bunch off errors so well, this area looks like it is just ah miss much. I believe I may have changed something into a sink on. Let me just verify that. So let me just voted. I believe that there goes I made this a think in the victory some but I didn't do it in the definition. So let me just do that quickly. And then I went to build on dso I'm going to show you the errors that I'm expecting to see . So I know that I'm going to get errors. This is not a done exercise because we just saw that every time you call and asynchronous function, you need the keyword. I wait now in our controllers, we were calling these repository functions in their synchronous form on No, that we've changed them to be asynchronous. We need to go back to our controllers and modify the way that we interacted with these functions are the results off these functions. So in the next video, we're going to go through and we're going to clean up our controls on make sure that or were you know, we have no eras
52. Asynchronous Controllers and Actions: Hey, guys, Welcome back in this video will be looking at converting our controller actions on function cause in tow code that supports are asynchronous repository. We'll also be reviewing other instances where we use the synchronous functions on be making you know, are taking full advantage off what they have to offer. So I'm starting off with the leaf types control. I believe that this is the easiest one to start off with. It was fairly straightforward on We'll just be converting. We see all of these red lines all of these errors on we'll just be refractory our court in a manner that we know is needed to support over no asynchronous repository cord someone to start off with Index Noto, facilitate this Orwell toe assess this arrow First we have to understand what's happening here. So find all is, ah, function that we know we just converted to be a synchronous Andi report is, well, the leaf type repository on. Then we see here that it is well giving us an early on the two lists. So it's basically saying that I can't just to list on a synchronous task so you will find that method chaining will become a bit more difficulty won't be a seamless as it used to be , because here I can't just chain on the two lists. Even if I put on the away it which we know when we have ah, function. That is a thing we need to say our way it. But then we are in Contra an error here because we need to change the actual function in two and a sink one. So to do that, we need a sink on the task, and then the return type is action results. So we wrap that in the angle bracket on even that is not enough toe fix the arrow because they're still ending up with the arrow. So this is basically going to tell us that it cannot in piss? Well, it based Palestinian cannot to list something that is a task. All right, so what I went out to do is remove the to list from the find all on. Then I'm going to have to add it to the mapping. So no, the a removed from this to list from the final line to the leaf types line because now it's saying that well, this is an eye collection on them. Mapping beast on list. So I'm just going to say, OK, leave times. But this I can do it like that. Or I could have introduced another variable where I said leave types to list and then that variable. Either one works. The fact is regarded off the got rid off the red line, and we can move along. All right, so it details has to get the same treatment. So I'm just going to copy easing task on your bracket on place it on to the the option results here on. Then it seemed that it cannot just performed the knots on on a task. Right? So the not operated the explanation cannot be applied toe operate and off task bull so that someone to do is just introduce a variable. Right? So you find that a bit offer factoring hostile go on toe, facility it this change. Some want to say this new variable is exists is equal toe await, and then I'm going to call report. That is exists. I ve said that film showing call I'm putting here as an easing fortune call on. Then I will just pass in the variable inside off the original. If statement on there we go. Everybody is no happy camper. If you look at this function, call here via leave type people find by idea, no friend by ideas. Asynchronous son went to see a weight on then that should take care of that, so you may not see an arrow, but when you do see the opportunity, you know it's anything call you. Just make sure you put the outwait right. Now. Create isn't doing anything that's asynchronous. It's not doing anything special somewhere to leave that, so sometimes you will convert them. Sometimes you won't on. The fact is that if you convert it and it's not required than bizarre, studio adjustments have suggested that you don't converts that all, since you're not using the synchronous methods anyway, are so for the post for creator putting a chasing task, corrupt action, resulting uncle brackets on. Then I'm just scrolling, slowly looking for other erasing functions. I ce success here is create, which is on a sink, so I'm going to say away it and they noticed that this red line goes away because the result off awaiting the task to complete is the concrete type. So without the how it will be getting from this form, shonka will be getting the task bull. So I'm awaiting the results off the task. And so the result of the task is the actual Boolean right? And that's why that is processed even one better so or process about an error. So moving along we go toe edits we put in our task on, then we have to do the same kind off his exists here andare awaits the results off the report. So I'm just typing this up because I really don't want to lose what's in the clipboard some copying and pasting on. Then I can just remove these, um, other elements. So no, we await the result off these exists and we do the if statement, I also await the find by i d. And then we move along on then changing the post in tow on easing task um, the orbit. We owie it because that's asynchronous. And then we move along to the delete, Say, see, after you get used to the patter and it's really not that difficult to just convert your court to use up all of the casing functions or the casing pattern that that mitt core has made it so easy for us to implement, right? So anywhere that you have a knee sing call. You just make sure that one the function is asynchronous onto your are waiting the call. All right, so that's it for leave type controller. Look at that. We're done. So if we do a build Randhawa and seeing the air is coming back from the types controller on , we can say that file, but we still have leave requests and leave allocation. So we're going to do leave requests together once again on then I'm going to leave you to do the IV allocation, and then we'll just compare notes. All right, So for the index, I'm just going to convert that toe task on. Then. I'm just looking through. So find all we need to await the results off. Find all on. Don't see anything else from upper is not implemented or mop. Is that you think? Is there? I'm up a sing. Well, there is not. So that's fine. We can move along my leave. I'm going to meet this a synchronous. So I put on the task my leave on. Then we get sore points where we're using user manager. We had get user a sink on that. I said not result. So remember I said that when you await, then you're getting the result off the call as a concrete type. That's what happened here. So that results actually give us about the concrete type? No, I don't think that that results is actually or or calling the easing function like this is actually making full use off the asynchronous functionality being afforded toes. So what I'm going to do is remove the dot results on going toe, await this call. All right, so no, we have user manager dot yet user a sink and we don't have the doctor results. So what happened is that at this point, I didn't want to overwhelm you with making the action into easing just so we could use the user manager, get used a sink, So I left it alone. I just used that results. So you see that you can use that results, or you can just make the entire block asynchronous to facilitate the actual easing call. Right? No moving on. We see that we have the leave report on just by hovering. I see that this is a task. This one is also a task. I know that also because, well, I made the changes. My program. Right. So I understand Awaits those two calls my perm upper on then there No more cause than Uday Singh so we can move along in details me the function or the option. Sorry. The, um, action results. We make it You think we are weight on. Then we move on to approved requests will make it a sink on. Then we cannot wait. So notice if I put away it on this line, it's user monitor. User manager, get user a sink on then it's that results. So with the result that how it won't work so it's one or the other. So if you're function is not a sink, then you can use the dot results. If you make it a sink over you just use the G word. Ah, wait and remove the dot results. All right. So we can await all of these cause and notice how many Earths went away when I just said I wait this on. They were actually getting about the concrete type, which was required to begin with on when I put away a tear. Those other errors below should go away on then. You know, it is the green lines here. So these green lines are saying that I see that here calling asynchronous function, but it also using the sinker stuff. So if I over over it, then you see that the Liable was saying that that's what he can just insert await. All right, So the same thing I've been saying is something bizarre studios been to suggest just put a weight in front off your function, cause All right, so we move along. I wish I know the situation here where I tried to protect you from the complication, but hey, where Brad? Back here on dso I make reject results. Asynchronous on guy. Make a take advantage off the user manager gets user a sink and see away it on. Then that should take care of some things on. I'm also going to await the find by I d call on that. I went to await the call to update and I move along to create make it a synchronous Andi insert my are weeds where it is necessary and you see how many things get solved there. So maybe I won't be talking as much? No, because I think you guys are catching on. Either way, I'm just going to go through on I'm just going to be making these changes. You can always pause a video at any point where, you know, I may have moved too quickly and rewind where he didn't understand. On def, all of that feels and feel free to reach out to me. So that's we can have some dialogue our own what was being done. All right, so I'm just moving through. And I think I'm almost done with this controller where a tense a request made it any think inserted a wheat inserted a wheat again. So for me, the aim is to have no lines. Whether they're green blue are are red but especially read God's word means it won't run. But whether they're green or blue, just remove all lines so anytime delete were not applicable. Leave request controller. So we move on to leave a location controller on DSO. You can pause the video here, attempt this one by yourself. I'm going to do it, and then we just computer files. All right, so I'm back on, have made the changes someone to go through each function on dso. Well, I made the changes, and clearly I didn't complete them because here we have the leaf types with awaits to the find, all on the to list era that we saw when we're gonna leave types, controls, understand. Toe me that adjustment and see that to list over this side. If you go with a more elegant solution, feel free to share it. Um, but then we can move along with this one. So that's the index. Made it internally synchronous function off course. Put in my away. It's moving to set leave have put in that we await are we to remove the dot results from the user manager In the if statement, I also inserted the outweighed So once again, once you have a function called on asynchronous function, you can just put the out weeds all right. It works almost anywhere and what to say Almost anywhere. All right, on then. I inserted the out. Wait here for the create for the list employees. I waited the user manager gets rules. Get users in rural a sink, remove the doctors. Look, that was there in details. I Okay, so I missed one. So I did the away it here for the mapping for employees. But I missed this one. So it's good to compare notes. I'm sure you pointed out to me if you did a good job. So for the allocations were way. It's getting the leave allocations by employees. Andi, that's done in the mapping. So philosophies differ in terms off how we handle these function cause and were put them. So really, actually, for maybe educational purposes, actually, that you could have just done the function call here. Um, my my preference is really to put them in a terrible. So I would define a variable where I would store the they use that covers back from this function. Call on. Then I would pass that verbal in tow. This, um, full single for them up. Right? So that's my preference, really and truly. But we'll just leave it. I'm not literate factor to quote too much because, well, this is new. A new topic, Andhra. Factoring it for that purpose is not absolutely necessary. to bring in this topic across, so we'll just move along. So for the edit, um, we await here for the post for the edits. We awaits the record. We also ah, wheat success on That's it for converting or controllers. So if I do another build, then I see that this was actually very successful. So one build succeeded on I'm actually going to run the program and go into some of these controllers. Just make sure didn't break anything. All right, so I'm running my application and I love being successfully. Let me just, you know, take her own. Just make sure that I'm seeing what I expect to see. So here I see that I'm bringing about belief task from what this would have been calling our find all all right, if I go to leave allocations and I can click allocate employees, all of those functions off them is during any exception. So I guess they were leave requests here at so remember that all of these get or anything that is retrieving data. All of them would have bean well converted into asynchronous function. So I guess it's safe to say we didn't break anything when I just click our own, I still have all the functions that I had before on. They're all working quite fine, so the application generally would just make better use off the system. Resource is when querying the database and retrieving data on well with users interacting with it on, you will see the poor off asynchronous functions over time. As you know, system load increases it will make wants us again. Better use off the resource is available.
53. Review and Add Changes to GitHub: Hey guys, we're in the section where we're just going to review what we've done and then check our changes into get hooked together. So once again, just a quick review. What we did in this section was toe one implement our asynchronous functions in our repository. So each off our interfaces got the task declarations for the functions. The country classes that would have inherited from the base or from the repository that's inheriting from the beast would also have gotten those asynchronous declarations or modifications. We also made sure to include entity, framework core so that we could take full advantage off the asynchronous functions that entity framework has afforded us. Then we extended that bit off work into our controllers and actions because once you have been asynchronous function, the way we interact with the changes. So the initially that we interacted with it and initially the court had to be refracted a bit toe facilitate these changes. So everywhere that we had a function called to, uh no a synchronous function, we had to put the keyword a wheat hard and we also mean all for actions is synchronous so this simply means that going forward we can write everything it's synchronously on. Take full advantage off the pilot programming mechanism that dot net core affords us any hole in this video. We're going to be checking in our changes. So as usual, we just go to our solution, right click, click commutes on. Then it will let us know that we have to put in a message. So I'm going toe, start typing and I'll see changed Repository. Let me just start with so quickly. All right, so my message reads Change depositor controllers on actual ins to support asynchronous programming. All right, so that's my commit message on. Then we'll just let this car it's go to commit all and sink, which will offer us commit the changes locally and then synchronize with digital. So once that is finished, we can off course go to get hub on. We will see the changes the latest commit on the latest calm. It happened a few seconds ago on We'll see the change message there. So as usual, I will share the specifically toe this chance it with you on so you can review those changes on your own
54. Review of Programming Patterns: Hey guys, welcome back. In this section, we're going to be exploring different coding patterns and exploring why we need them. So in this particular video, I just want to kind of take a step back, look at what comes out of the box with or MVC.net core application. And then we can look at why we would have implemented our pattern. Because while I briefly alluded to the out-of-the-box functionality, we really just went to implementing the repository Patreon would, without really exploring why we need the repository pots arena. And then by extension, we're going to look at the weaknesses of the repository about cern and whole weekend well, both implementing the unit of work pattern and what advantages and disadvantages will be. So let's start this off. I have the lead management project and what I'm going to do is generate a controller and its respective views using the out-of-the-box scaffolding mechanism. So once again, we briefly be did the starts where we went to add for the control of follow and to add, add new controller. And then we can select MVC controller with views using Entity Framework ad. And then we select our models. So I'm just going to use, let's say leave. Let's find an easy one leaf types. So leave tight, sorry, not the repository type. Alright. So I'm going to use the leaf type to generate, to scuffled. Now in earlier parts, I would, I would have in error use the view model, let's say a US view allocation or elif type VM, right? I would've used lifetime VM and lift the data contexts class. And that was an error on my part, because once you include the data contexts class, what it will do is automatically assumed that this is a database table. And if it's not already included in the data folder, it will then include it in the application DB context. Alright? So if you Bach and you see any leaf tie VM and any of the VMs up hearing in the BB set, you can safely remove them. Did they should not be there. But when you're scaffolding using a class that is already there. So in this case are going to be using Leaf type controllers, controller views with Entity Framework. And then we select leaf type and we leave the application on DB context in there. And I'm just going to allow it to name the controller says leave types one controller and old problem because RAW types controller, so add that and this activity, you don't necessarily have to do what I'm doing. I'm really just doing it for demonstration purposes just because we want our discussion. All right, so once that scaffolding is done and it was done with data class, then you will see that it initializes contexts. So application DB context, that's his ART gateway to the data. It has the context. So this is the out-of-the-box MVC pattern at work, right? M standing for model V4 view CFO controller. Right. And we've been through what the MVC, what each component, those. So that in itself is actually a pattern. This pattern was developed because what would happen is that you would have a lot of logic, like what goes in the controller being mixed up with the HTML, which is almost in the view. And then the data connection and data communications happening right there. So they tried to abstract these three distinct functionalities into the M for the model data stuff, V for the view, the visual stuff, and see for the control of the logic stuff. Now when we get this out of the box controller and it injects the application DB context. You'll notice that it actually generates all of that code for you. So you have the ability to read or read all of the context types. So this is just simple link contexts, leaf types to lists. We've been through this, right? Yet the first our defaults when you are going to create Gua bind on to the data class. And we can modify this list to say we don't want to bring a one-day creates. It would go on to bring all of this or somebody puts in addition, they are not already a part of the model, then we can ignore them using this list. Alright, so this is all out of the box and it's easy for a beginner to pick up and start using and that's no problem, it works for Microsoft gave us a good template from which starts. The reason though we start to implement a pattern on top of what comes out of the box has to do with minton ability and possibly readability. Meaning in this case of this bind, home maintainable Is this when we have to modify this data class. And then we have to add fields to leave town because then the business comes back. So Census hey, you know, leave type needs to have these additional USA, we add them. Sure, we modify them and will have to remember to come back to the controller, extend this list of boned fields for the extended list for the edits. And then that's a cycle that has to go back and forth every time. And, you know, I just think that's not sustainable, right? So then we implemented what we call MVVM on top of that, on top of this whole mechanism. So MVVM is short for model, view. View model. Alright? So MVVM basically is where we brought in the view model. So we abstracted what Leaf type really looks like and put it in the form of view model. So that then got rid off this bind, the dependency on this bind lists. And then we could know, say what the view model should look like. So it will automatically bind to the leaf tie VM, right? Additional fields need to go and we just go to leave type VM and add them in and they're added university because we're looking at the model, we're no longer looking at this bind, at least. All right, so then we can limit what we want through all our view models. So that's the first pattern that we probably could pay attention to and say, okay, so you can see where the Model-View-ViewModel was actually implemented. So we added a view model to kind of media between the real model, which is the leaf type coming from the datatype glass, and the view itself, which is the display of the data. The ViewModel added or subtracted the fields that we deemed necessary for the operations. So moving on from MVVM, let's talk a little about some of the auto-generated data access quotes. So we have contexts, dot-dot-dot, IV types, dot ac, this one that first started defaults. And we have them all over the place, right? I had to find etcetera, etcetera. No. The thing is that if I needed to rise up costume way to get Butler leave types. And I think we kind of had to do something with getting the leave requests for a particular year or somebody's leave allocations for a particular year. Then that means every time I am retrieving this list after remember to put on my whereClause and then put on the lambda where and whatever. Let's say, let's just say default is, I said it would leave allocation what we're using leaf types here. So this just humor me, flooded. So I would have to remember to do that every time I'm trend to pool buck leave types afternoons in the index and any other custom screen after rhomboid when I'm doing an drop-down lists where the leaf types after remember to write the query exactly like this every time. And then that leads to some amount of repetition. And while it might be workable for a small application in an enterprise setting, it's not sustainable because business rules can change almost any second. And you know, you need to be able to modify it application quickly based on these new requirements. So that is why we introduce that obstruction that we call the repository. Alright, so let me just jump over to the repository. So of the Leaf type repository. And that's implementing from elif type repository and by extension from the B's repository. So we had the base repository because we know that there is, there. These are the basic functions that we'll always be doing. We'll always be doing some amount of crowd funding it. And then we can always close them Mies, exactly how we find any one of them by giving it its own repository. So for the Leaf type, I could see that when I'm finding all for the leaf types, I wanted to meet, done. So then this custom queries written a 1s, one protease and used elsewhere if he needs to be updated, I just have one pre-installed. So that's one of the advantages of the repository pattern. And all where do Repository pattern can get rather annoying is in the case where we have to interact with many repositories and at being Request Control is a perfect example of that. So we have to have reference to three different repositories because we needed to interact with three different tables. In this controller. I mean, it works. We've gotten this far doing it. But then, you know, to me it was actually getting a bit 1B and because it out to be like, oh, yeah, I know I need this repository. Oh, yeah, no, need that one, et cetera, et cetera. So then that is why we are looking at implementing the unit of work pattern, which is where we'll have an IV or generic repository Bs. And one repository implementation that will suffice for all the tables that need to access. Or with all the tables we need to access rather. Alright. So that was just a quick run-through of why we put it in the repository Potter, and I hope you'll appreciate why the repository butter and wasn't necessary up until this point. But then, sure, often during the leave allocation activities, you'll realize that, okay, this was a bit annoying. C in this case, this is me by location where to do this twice in requests. We had to, you know. So it could become a bit annoying when you have to be bringing in 56 different repos, even wafer, you only need one query don't against one of the tables. So in the next video, what we're going to be doing is sitting up or modifying our base repository to be a bit more generic. And then we'll be implementing our unit off work pattern and looking at how that can help us have more centralized code, more customizable code, and even extend some of the functionalities like with the find us, because there are times when we've had to find all and then write a lambda expressions of field on top of it. So we're going to be implementing all of those things where we can create filterable functions and have a more powerful repository. So stick around.
55. Implement Generic Repository: Alright guys, welcome bucks. So let's get right into it. So the first task is to modify our base repository. And all we've already done a good job City antelope to be quite generic. And then we have the concrete implementations per class. After being generic, initially, I wanted to kind of modify the functions here, namely the while, the find, all the find by ID. And the ease exists right? Now what I'm thinking is that right, no, these are only allowing it to find if it has an ID, but what if there was a different condition that you wanted to find by, then what you'd have to do is find all and then do an dot any if you get what I'm trying to get that job, I know you're proficient enough in LinkdIn. Whole desalting works. But what if I wanted to find if there's any leave requests without particular d two are starting on a particular date or whole Mini, which leave requests are XYZ, right? Then I would have to write custom queries in each of the repositories for each one, right? So we have our contracts and we have our repository obese. Sure. But then if I wanted custom queries for leave requests than I would have to have a bunch of them here. And what's really be doing in any of them is looking at the fire and then filtering all it's based on the find all results. What if we extended the find all that? We could just include our expression as a parameter. And then if the expression is present, then it will act as our filter automatically. Alright, so that's what I want to do, random. So instead of saying find all just blank or you know what I'm going to do, I'm actually just going to start from scratch. So without modifying the base repository, I'm just going to do a brand new one. So let's just start over and do it from scratch to avoid any confusion. So I'm going to create a new interface. And let me just do it underneath there. So in the same file, let us have one file, which I'll just creates a different interface. So public interface. And I'm going to call it generic, and we'll call it s1, I generic repository. And it's going to follow the same kind of incrementation. Have the abstraction which is T. And we're specifying where t is supposed to be abracadabra. Alright? And then I'm going to have pretty much the same functions. Alright? But then, like I said, we're going to have modifications to hold their implemented. I've tasked ie collection. I mean, well, it's parses isn't into alist anyway, so could probably just see I list from the get-go, right? And then the find all is going to have three parameters and I'm just break in the line so that I can show you each parameter individually. So we have the ability to write an expression. And I am telling this expression that it is going to be a phone Sean that involves, that's FUN. C, sorry, that involves a generic which is the same T generic, some form of boolean. And I'm calling it expression. So that is a syntax. So this is basically the data type for a lambda expression. Alright, so when you're at a lambda expression that looks like j2, and then you have your lambda r and q dot id is equivalent to something. Write that lambda expression that you would write. Literally this is the data type that facilitates the, so this value would be stored in these expression. Alright? So Q represents the tea and your Boolean here is represented by that expression at the end of it. All right, so that is what we're facilitating where allowing somebody to say find all and then putting the lambda expression if you have, if you want to add a field that sort of find all from the get-go, then do with that. But then it's not all the time that somebody wants a filter, so we need to make it null by default. So if none is provided, then we just assume that, well, we just bring back all the records. If this is not null, then we need to set up the function such that it will do the filtering and then return. Also want to add the ability to, to art or by someone to say FUN NCI. And I'm going to specify that the queryable for whatever t is that generic, right? And then I'm going to say I order or order I queryable. There we go. Ordered queryable for that same generic, right? So that's what that function will be. And I'll call this one order BY and also equally distant null, right? Because when we're want to order it, suppose you wanted to filter, and then we wanted to order the filter. And seeing something wrong here, an extra angle bracket. There we go. Alright, so then this second parameter allows us to see Q dot, Q dot order by sending, or it could just be ordered by, doesn't really matter. But this secondParameter allows us to specify that we want to order by a particular column in whatever fashion. Alright, so that is what. On the parameters for. And then when we wanted to include, Remember that sometimes on to, to pull data and sometimes we needed to include. So I think what we did, we just went through and did like a wholesale include for them in the repository. Let me see if I can find any example of that lie here. We didn't include so we did the find all we said every time you find all, please include the leaf type and include the employee. But that's not necessarily true. It's not everytime that we'd find all that we want to include. So right here, the Including is not optional, especially down here it's not optional, right? So we can actually implement something to make it optional. So what I'll do is create a list or a parameter that will be a list of type string. And we call this one includes and we created to null, right? So that means if I want to find all and I'm included in I'm sorry, I'm interested in including the related data. Then I can list out what I wanted to include because I may want one table and not the other. Right. And in another situation I might not want to include anything. All right. So I just want to find all the records for this particular table without any includes, without any filter, et cetera, et cetera. So then this allows us to kind of reduce the number of customized queries that we have to be writing to get bac certain data does I think here like we have check allocation. Well that's a custom one. That's fine. But as we go along one where refactored, all of this are light. This one gets allocation by employee right here. We derived a custom query to get the allocations and then put in the filter. So what we're doing will allow you to just call findall and add your filter accordingly. So let's move ahead. The next one that I would want to modify is the find by ID. No, I don't want to specify a find by id because there might be other, let's see, other factors that I want to use to find a particular record. So instead of just finding by IBM when to give it the same kind of expression or the ability to facilitate an expression. So is I'm just going to copy this and use it as a parameter instead. And then I'm also going to give you the ability to include other red cards or other related tables, right? So you have the expression and then you can include, if you so desire already, if you need to at all. Alright? And then for the Xist, let's say it's the same thing. I might want to find out if something exists. Not only based on the IID, but based on something else, are based on some expression. So this expression is very powerful because once again, it allows us to put in almost any expression here, and it will just execute that expression and the desired results. Alright, so that's pretty much it for the generic repository setup. Now let's take a look at setting up the concrete class that will be inheriting from our new high generic repository. And in keeping with the naming convention, I'll call this one generic repository. And in keeping with where we're implementing and went up to implemented in repositories on notice we add one BCE, but that we had several inheriting interfaces for contracts. And then by extension we had several inheriting repository classes, right? Which is why at the end of the day we had to be injecting so many repos into all controllers at that time. So this time around I'm just going to create one new class and I'm just going to call it generic repository. So once we have that generic repository, I need to tell it that you are relative to a generic called t. And you are going to be inheriting I generic repository, which is also relative to a generic t. And where t is a class. Now done as we know, we need to implement our repository Art, sorry, our interface. So go ahead and do that. I will get all of our functions as expected. But then now our injection is going to look different. The first line is going to be a familiar line. It's going to be our application DB context. And then the second line is brand new. It's going to be for a DB set of type T. Now we would've seen the DB set, that syntax we used for this, including the missing libraries, would have seen this syntax before a DVD set because in application DB context and every time we added a table, we had to use DB set. And then we specify the data type, bread, employee, request, etc. In this situation, however, DB set is going to be initialized to whatever t is. T is very generic. So it's just a DB set for whatever generic class is going to come in. And then of course we know that every time we do new class, we just inject in through our dependency injection art inversion of control container, right? So we have the context being initialized, but we initialized to be equal to context, context dot of t. So we're not dependency. And initializing this one. Where initializing it after, after we initialize RDB contexts, then we tell the table, right, that you are from the context and your offset, I will say creates a DB set of T entity. So whenever you see these two are in intelligence service here the t is really a generic. So they call it t or quality class or an entity or t, whatever. It just means, some generic class I am prepared to facilitate any class that is passed into me. That's what I really mean. So it creates IDB said that can be used to query and see instances of whatever it is. All right. Notice whatever t is. So it is very i keep on. The door generic is probably overused by nobody, is very open, right, where not being as specific as we were in our repository, right? So the generic repository is allowing us to facilitate one feature set for almost any table, whatever it is, I am able to interact with it as I need two. Alright, so let us start with the simpler ones, the simpler functions to implement. Let us look at our creates. So for the Creates, What do we want to do with the creator? Created is fairly simple. We just need to see how it And well, I need to actually meet these is synchronous because of course we want to take full advantage of or asynchronous programming. So it's already a synchronous order are the tasks on this side. Let me just make sure that there is a sink on this red. So async for Create. Alright. And then what we're going to be doing here is seeing DB. Well, the reason I paused, I just noticed that we're still returning a bool, so we are going to change that up a bit. So at this stage we're not going to be returning a Boolean. We're just doing a task, right? So we can go back and remove bool from these operations. And we don't actually need to have the save either. I just did a copy and peace. We will implement the CVE somewhere else. So I'll just comment that out so you can go ahead and make those changes to the epigenetic repository interface. The only one that should be returning a Boolean exists for what I think would be obvious reasons, but the others are conducting tasks. And we don't need the C, at least not here. That will go in a different section. Alright, so let's go back. And so because we just did that updates, we need to take the bool of these flows through an update demo, all, take all the save until the mood of updates. And then our interface should stop complaining. Alright, so back to create. All that's really going to happen here is that we are weight. And then we can say underscore DB Sono dB is our connection because db is no initialized to whatever is right. Db represents that table. But it also uses very generic abilities to just add, remove, and update, right? So db.json async. And what we're adding is, alright, and that's it. We just added T. So following that example, sorry, not T, my bad entity, sorry, plus concentration there. T entity, so we're adding entity, right? Alright, so with the delete, what we want to do is I'll wait on the score db dot, remove and remove Ising. Okay, there's no remove aliasing. So that means this can't be a task. Alright, so just remove and we're moving entity. Alright, so let me go ahead and modify this. This is not a task, this is void or so, a bit of refactoring, but we know that that was going to come. So there's a slow buck over engineer to strum to avoid. I think updates also does not have an async. So let's just change that to avoid from here. And then find updates James dot to void. And then update is fairly straightforward, is db dot update, right? I know async is there, so our taking the entity, that's all right. So when we do albeit one line, when we do deletes, one line creates one line. Alright? Now let's look at an, like I said, we're dealing with the easier ones first, right? So the next one that I would want to do, the exists. So let's look at the exists here. When we need to find if something exists, it means that we need to get all of the records in the table. So I'm going to initialize a variable i queryable of type t. Alright? And I'm just going to call a query. And that's equal to underscore DB. Though, one thing to note, DB is going to art, Sorry, I queryable is basically like a datatype that is still tethered to the db object. So when it's when you went in just the query is going to be queryable form, which is why we usually have to parse it to lists are to i innumerable for other operations but in wearable it's like still tethered is like a collection of the actual database objects when you parse it. It's no longer a database object stored in memory, so it's no longer attached to the database. So inside of this repository butter and we want to keep everything I wearable. That's why we keep on using AI queryable all over the place because he wanted to stay as tethered to the needs obvious as possible, right up onto wearable to release it into the memory for an applications. So I queryable of type T query, right? And then I can know C return. And I'll just do an await here, which means this needs to be sink, right? Return our query. So query no embodies the ICC wearable version of all of the records in the database. And I went to see a doctor. Any A scene. And then guess what I can do. I can just pass in the expression. So remember that the expression, the value of that expression would have would look something like q, r, whatever lambda token. And let say ID is equivalent to ten. Alright, that's what this expression would look like. So if I did this syntax right here, it would work. So instead of hard-coding this syntax, right, especially since it's being generic. So that's an important part. Notice that there's a red line under q because q or really doesn't, right? And the lambda expression here doesn't really make any sense because everything is generic. Query the Bb, it doesn't know if it has an ID field or a name field or it doesn't no arc here. So I can't hard code the, the check to see if the ID exists here, because it doesn't know if it doesn't ID q doesn't know what he is. It might've, which is why we're abstracting its own expression so that we as programmers on this situation, when we want to know if it's the ID, we just write based on the id and then based on the table that we're querying, which will be determined by what we pass in as T, then the expression can be executed. So that is why we are being sold. So once again, generic using the word expression and not hard coding anything, total. Alright, so that is the first days before that expression will work. So let us look at the next easy one, which would be to find by oil just to fine. So that's this one, right? Just fine. So let me make it async. I'm sure we'll have async operations that we can carry out and see how this all works. So the first thing that we do is get the DB set just the same way that we did in the, in the exit I queryable query equals db. Then after getting our query being equal to db, what I'm going to do is go through and include someone to say If includes. So remember our parameter includes would have us string or a list of string representations of the table means in case that wasn't clear. So that means when we are trying to find something, if we wanted to include it after, say, new list, new string, list, right? And then initialize it to have quotation marks, table name comma quotation table marks and does a bridal valleys. So I'm seeing if the includes variable is not equal to null, then it clearly indicates that we wanted to include stuff with what is returned, right. Then we'd go off for each and a will be for each. Let's say I'm going to call it a table, just to make it clear that we're including tables, right? So for each table that is listed in that includes. We're going to say query. Remember, query is equal to query. And we have access to the include. And then I can say a table, right? Because this will be a representation off the table name. So I'm seeing this include whatever comes into includes this. Just go ahead and include it. And then at the end of all of that, I can now return and the result of query first our default. And guess what expression. Alright, so actually quite frankly, in the find, the X person should not be nullable. Because what else are you going to find if this is nullable? Alright, so I'm actually going to remove the PNL from there and let me go back to the repository and remove the PNL from here. So what's nullable is what you want to include. But you must give me an expert on bio, which I'm going to find one record or as it doesn't make sense, right? So then we do return o its query. First, our default async. That's why we're getting there. Red line async, expression semicolon. So that is how we implement the new find to be generic. And then know for the bigger one, which is the fine dog. And this the bigger one because we have the three parameters. So I mean just britain lens vacancy, all of them on screen at once. All right, sort of on bowed out. We have to cater for if there is an expression. If we need to order by and if there are any includes. The preliminary part is going to look very similar to what we've done with the exists and the fine. And that's the first line. We always start as almost all FOX. We can take everything upon to the includes part, again, this copy that and bring it down into the final bullet. I'm going to just reorder the quote, upbeat art. So we have our query object, shore. The next thing I want to do before I go on to the includes. And next thing I want to do is to find out if there was an expression. So I'll see if expression is not equal to null. Right? So is there a filter, right? If there is a filter, then the query should not be equal to query dot where expression. Right? Because then if we wanted to find something we're created BY, sorry, Libya and find something simple where number of B's at our dS is greater than one, et cetera. So you'd say q dot is greater than 21, that's easier. John, Right? And of course all of this would be in a lambda expression. And this would be erupt Oppian No.2. We're alright. So instead of requiring you to get all the records and then apply aware, I'm giving you the ability to call this function, this golf find all. And then you can just tell me the experts on you want, right? And then if if this and I get stored in experts on if this has content that we just apply the where clause on your behalf. Right. And then we have the includes and we just went through 1A includes those. So I'm not going to repeat that explanation. Then we have another parameter which is art or by someone to do the art or by alas, it doesn't. I don't think at this point you really matters. If you do the first 1, first r into lots of all, unless I think maybe in terms of efficiency, apply the expression first. Few are required to do the includes and the ordering ideals as opposed to ordering everybody and then filtering. So in that sense it might make sense, but in the grand scheme of things, it's neither here nor here. So we do if order by is not equal to null, then we do a similar thing. We say query is now equal to yourself. Order by and then the expression R. Well, the orderBy value that was passed in, right, are already looked at an example of what that could be, right? Oh, actually, no. So this wouldn't require a lot. Order by order, by, sorry, order by would be the function that takes the parameter. So if you just look back at the definition and this is a function, right? So order by is a function and it will take as its parameter that I queryable t, which in this case Query. So query is not equal to whatever all function returns after it has ordered that I queryable. Alright? And then at the end of all of these weekend return how we query dots and everything goes into alist anyway, so two list. Alright, so noise when we release it and send it back. And let me see what the error is. O the method is not async, so let's make it easy. There we go. Alright, so that is it for setting up our generic repository, right? So we did two things. That's just a quick recap. One, we implemented this generic, generic repository. I just use the same file if you quantities at different file, that's fine. I just use the same files that I will have the old code compared to the new code quite easily, right? You said all we did quite a bit of refactoring goes with called Booleans, which go the safe function and chins off them from task to irregular void functions, right? And then we implemented our generic repository to be as generic as possible. Cause once again, who wants it? This codebase one still facilitate every other class, every other data class. So everyone not to exist, Senate rwanda might exist, should be able to use this. Instead of every time we introduce a new table, we have to introduce a new repository. And that game of backing E14 thing. This will take away that whole jumping between and have one solid code B's barring any extenuating circumstances that require more customized code, of course. So when we come back, we will look into implementing our unit off work file and then we'll see the real work starting.
56. Implement Unit of Work: Our guys. So where Bach and know what we're going to be doing is setting up our i units of work and the unit of work files. All right, so let's go over to our contracts and create a new interface. And this one is going to be called i unit of four. Alright? And then once that's created, of course you have to remember, make it public. And then we will start to implement certain things. So the first thing, well, actually I wanted to inherit from i disposable, disposable. So in our controllers, there is an implied garbage collection method called dispose, right? While we want to do is kind of creates an overhead where when it's disposing it includes this unit of four objects. Because the units of work, like we've been seeing was spun all tables across every file. Instead of having 20, depositors will have one unit of work that has access to them all. So it kind of comes with the price tag of using volatile memory so on to handle disposal properly and garbage collection on properly. And so you'll be implementing AI disposable along with our units off where 1or M0 dot ran Nolan, we get tweets. You'll see how it will work. Alright, so when we want to do our unit of work, what we have to do is make a reference to our generic repository and the different tables that should be included. Alright, so let me make, let me, me, and that makes sense. So I engineered repository, I don't remember that I generic repository which we just implemented, right? I generic repository requires concrete class, so it's in the I am itself work no doubt we start to specify the concrete classes, right? So the first glass that we can use, type, leave type, not vm, ludus neve type. All right. Let me just get rid of the Moguls. So leave type and then I can call this one simple leaf type. And then I'll just duplicate this world and others. So what else do we have web requests and we leave, leave requested. The data type will leave requests. So similar to always sits up the DB sets where we have the class type, but then we have the pluralized version that's doing interior, just wanted that naming convention. And then we have the allocation. Alright, so I'm letting the i unit of work, or at least I'm creating references between the leave allocation, the concrete class naive allocation and the generic repository. So no, Through the generic deposits or we can do all those wonderful things with anyone of these glasses. One code base. All right. And we didn't need anything for employee Sorry, I know I only have three tables. Those are the three, but I'm sure you can already see that in an enterprise system when you have 20 tables, it would be easier to just manage them all here with one code base than to be implementing 20 contracts and 20 matching repositories for those tables. All right, so once that is done, we have one more thing, which is a means and that is saved, right? So we need to put in the units of force, so that will handle this. Because once again, it might be handling operations from multiple tables. So it will just handle the same operation one time. So we know when we implement an interface, we have to have our concrete class. All sources go down to the repository, go ahead and add a new class. And then its called unit of work, and add it. And then you get off work, inherits from, well, you guessed it, Unit 04. And then we go ahead and implement that. So let me explain know what's going to happen. So you see, because we implemented I disposable that our function call dispose as well as the other ones that we declared our cells. Alright, so the first thing I want to do is implement, implements and inject, initialize an instance of our DB context. Alright, so we'll go ahead and do that. Obligation DB context. And in our construct, tough work, obligation DB context, contexts. The second thing that's a little on to do is implement private versions of each of these. So for each public Wanda we would have done in the, in the interface, we need to have like private objects that represent them over here in our concrete class. So I'll just do that quickly. Justin, to lubricate this orwell, let me duplicate this one time and bring this over here. This tends to be efficient with my copying and pasting and call this leave types. What I'm going to duplicate it. And then you are in all the requests and you are alone. Alright? So that was due, but so we have our private application dv contexts and our private objects that we are going to be using to return the obstructions and encapsulation. The public is the public facing one. What would really be returning our private and whatever is in the private one, r. So let us start off with how we implement for our leaf types. So you can see that the Communists automatically with a get and set. But what we really be doing is. Getting we don't need to sit anything. Alright, so what we get from our leave types will be the object, private object to leave types, right? But then we need to do a knowledge check. We're going to see if it is null. Then we return a new instance of the generic repository with the context. Alright? So then this line of code would look something like if it is equivalent to null, then return. That's if you're using ternary operator leave types or return a new instance of leaf type. Sorry, I knew incense on generic repository following leaf type and with the context. Alright, so that is why we are to get the context in this unit of where because the generic repository, remember, this resume bullet there has the construct of that requires the context. So we'll just pass the same context object right through. And it will be relative to whatever the class was specified, which in this case is leave type. Alright? Some, getting some errors here, actually, using the new features I'll see Sharpie that don't have to do that gets itself. Prefer to just use my arrow right there, right? So then this RO doses leave types if it's equivalent to null. But then I'm going to shorten this a bit more. I'm going to see leave types R0. And then I can see at this point, question mark, question mark equals, right? So this is the null check is like a null check that says if this is null, then return that. So it will return this. What if it's not, it will return that. And I'm getting this era, I think we thought, oh, this shouldn't be read-only. You should not be read on the right. And then of course I need the semicolon. So again, do all of that in one line like this, right? Whether it's more or less readable to you, I'm not sure, but pretty much. Whenever we have a quick function that we need to write in the more modern versions of C-sharp diagnosis use this arrow like a lambda arrow, and then riots whatever it is that we want returned when this is called, this construct is called. Alright? And okay, so here, here it is giving an error because it said that we are not implementing. Surely we don't need the sets, so let me go back and remove those. And those just probability of habitats we put that cause we're not setting anything in the unit of work where we want to get, right. So, right, that, that goes away. So when the unit of work is causal, it'll be seeing some unit upward leave types. And then we can access the contexts and everything, all that is implied through our programming. So following this syntax will be doing the same thing for the request. So let me just go ahead and just copy and paste and then made the adjustments accordingly. So here, it wouldn't believe types what you will believe requests and the concrete classes, the requests. And here it would be leave allocations and concrete classes leave allocation. Alright? So you only tall four is going to give us access to whatever table. Say if you had another table I needed to introduce tomorrow, then you just create the private, create the public. Of course it make sure it's in the interface. So probably put it in the interface first. And then this will complain you implemented to create the privates and any red dots, similar lines. And you're probably looking at this retina and saying, okay, so why didn't we do this pattern before we did the repository Patreon? Well, they're all building blocks and at least you've gotten exposure to the repository Patreon already nowhere does we can add another pattern that we could throw into the mix. Alright, so let's discuss this dispose function on all the dispose function, like I said, is really going to do our handle or garbage collection for the unit of four objects, right? So typically you would see this implemented is that you have the function that we're going to create, God dispose. And then we call this garbage collection controls garbage collector. That's a service of automatic diary claims on used memory. So it's very important if you want to have an efficient running application. And it will see GC dot suppress finalize. And The, alright. And then dispose is going to be, well, let me just generates a method call dispose right underneath here. And then it is basically asking for a Boolean. So we're telling it that it's true at all times. All right? And then here we see if these are well, if V, So let me change this apartments on Gamow noisy, they call it v, I like to call it. Alright, so if dispose, then what we want to do is disposed off the context itself also. So on to free up any memory that are database connection might be using up. All right, so that's it for the dispose. And then for the save. And here's where the save is pretty straightforward. We're really just going to see how we on the score contexts. Let's see if changes AS seen, right? And of course, you have the Me scene. So the save changes happens in the unit of work as opposed to the repository this time around because it's always going to be seeing it seeming one time. So on lead lasso derived CFD changes or four times at our repository, we would just do it one time in the unit of work. Alright? And then all of these are implementing our inheriting the functionality that we just defined in our generic repository. And that will make querying much easier across the board. Now the next thing I want to do before we close all this activity is to register the units off for our startup dot cs. So we know that every time you add a new interface with the common wet or dry it, every time you add a new repository. Well, this time with the unit of work I can do c and services. And I'll add this one as transient. I'd transient. And I have the same unit off work. And you need tough work. Alright? And so when we do that, we can have one implementation of all the database related operations for all our tables. One time in one place, easily accessible, easy to see and change. Alright, so let us, in the next lesson actually goes through and we'll start by modifying our types. Controller. Does that one only has one repository. So it would be easy to just modify this one repository and then we build as we go along. Alright, so stay tuned.
57. Refactor Leave Types Controller: Alright guys, so we're back on where ads are. Tabs controller and let us start our surgery. So the first thing that I'm going to do is and I'm not going to delete any of the coda, does comment out anywhere that there would be conflicting, quote others comment. But I want to leave the origin alkaloids IQ and at least have it for comparison purposes or so. I'm going to go ahead and include my unit of work and I'm going to call it underscore units off work. Alright? And of course, if we're doing this, we have to inject it just the same way that we would have done with the actual ripple. So just go ahead and do our injection. Doesn't really matter where you type it understands to be structured. Alright? So nowhere I've accessed or unit off work object. What do we do when we want to find all someone to comment on this line and move to the next nine. Well, let me duplicate it. So the new way to find all will be always Unit 04 dots. Which table do I want to find all from Ramallah, those public facing objects, those are all we have access to here. So unit off, we're not leave types, thought find all. Alright, right there, I am finding all of them. So if I, I'm, I mean, we're all human who could've mistakenly said leave allocations or either you said you need software, locations, find all, then obviously you would get an error down here because then this is returning to evolve location types, right? So of course, you know, the checks and balances kind of would deter the ability to make certain kinds of mistakes? No, the reason we have it called leaf types here is that I called it leave types in the units of work. So if I call it the leaf type t blood type entities or whatever, what their virtues I call it. It would come up on here. Some people, when they implement this, you would actually sit MC Light to leave type repo and leave requests repo. I don't see the point in seeing a repo again, I already know that we're dealing with real Unit 04 types dot find. All right, let's look at this one for exists. So let me duplicate the original. And then I'm going to say unit off work. Leave types. That is exists no notice icon does pass in the ID because it expects the expression some went after arrival, the actual expression. So I'm going to say Q. And then when I do the expression here, it's actually knows that relative to leave tab, these are the columns that I again look up. So if I wanted to find out if there exists one by this name, R1, by the default, number of b's are by ID. I know have better control over what kind of filter I apply here without having to write three or four different functions to facilitate through our four different filters scenarios, right? So I can say is exists where the ID is equivalent to the ID here. All right? And then don't hear where we do the find by ID. Do the kids and comment someone to say here that I want unit off word.lower types, not find, run by, renamed it from find by ID. But I now have the ability to write in my expression Q dot id equivalent to ID. Now what I want to do is go back to the original repo for the Leaf type. Well, I don't think we included anything for the Leaf type, but I just wanted to double check. So leave type repository. When we find we don't include anything. I don't think anything is related to it to get include it anyway, That's fine. But if we have to include and when we move on to all those that involve includes and you'll see exactly how that works. So that would be the new way to find. And once again, we could easily find by any expression that we need for the create. We do all of that. So even lay this bead created where we manually put in the date created there and even be modified, stuff like that. You probably don't eat all. You can abstract this functionality out and we'll do that in a few. But right now I just want to focus on the, so let me comment that out. Duplicate KU and then unit of work. Leave types dot create. And then, well, what's the error here? Void. Ok, so we actually get rid of this stuff now, right? Well, actually the is successful then top in here. Alright. So what happens is that when we create one, it's just doing the creative or whites not saving. So in the older repository we seemed after every time we created, let me just go back to the older repository and look at it again. So when we created and in this sea of would return. And let me just don't, don't deceive those unsaved changes and returns the one or 0. So let's replicate that in our unit of work just so that we're on the same page. But then the problem here with the unit of work is that these contexts saving changes receiving across any table. So it's not quite easy to destruct on Xj o for this particular operation, was it successful or not? So I'm actually just going to do away with that tool to check because most times when there is an error, the catch would, would, would jumping anyways. So I'm actually going to take all these 0s success check altogether. And what we do is just our unit off work dot c. And I know it to c. Right? So that is how you do that. So yes, it's two lines. If you weren't doing the if statements and so on, you'd probably just do it in one line anyway, lead that. But yes, it's two lines. What I think the long-term benefits or we, you know, just the fact that we're producing one nano is two lines. So let's move on. So here we do the same is exists and this looks exactly like the details. So I'm just going to copy and paste. Really for the d, for the edit, copy and paste. And then for, well, we modified or delete anyway. So let's look at the other edit null. So for the Post editor, we have the same is success, check, meters, comment all of this old. I moved it initially, but I'll just comment it out. And then what we'll do is, well, the update was not a synchronous, so unit of word.lower types Update and we're updating leaf type, right? And then we save. Oh, and save is right. So there we go. So then we did a similar thing. So here the delete, we found it, and then we went ahead and deleted. Alright, so what I'm going to do here is thought, which ended me do it in. We actually made two of them the same way. I'm actually not remembering which one. Recall. Let me just go back to the view so I can get it right. I think we did that from the index. So more than likely we did it. So even like this, deletes, we're going to modify the way this works with. I'm going to remove this. Onclick clauses can be a major security concern. And what we'll be using is like a form submission to the post. So I'm just going to modify them both boards going forward we want to use the post because I want to have the protection of the anti 4A Tolkien. When we're doing a delete operation, the way we wrote it initially, while it was easy and it looks clean. This is actually a security risk. It will be revising that in a few. So I'm one of them will just modify a both of them so they look the same way. But once again, we want to move forward with this. So what we do here is the find. So let me duplicate comments, the origin. And then I'm going to see on a square unit of work dots leave types, dot find and the expression will be, and then in case he does want black, I died. When you have multiple parameters, you can say experts on colon or like you want to specify which parameter you're preventing a value four, again to see the Parramatta name colon and then you put in the value, right? So j2, sorry, expression is q. And this lambda expression where we say q dot o, sorry the function name is wrong about. So find was wondering why that wasn't working. There we go. Geodata ID is equivalent into ID. So then it's going to return a parameter, or sorry, the object here. And then we see you want to talk for dot leaf type delete and relieved that it's void. So we don't owe a1 and of course we don't check for the success or anything like that. Remove all of that. Of course would wrap it in a try catch. So it's broken bits, it's a rapid tend attract gets, which is what we did here. So this is permitted a bit o on to use anyway. So I'll just copy that code and paste it down here. Alright. So like I said, we're going to refactor our deletes. But that's actually it for changing or the leaf type controller code. So we can go ahead and test it. You can test it. I'm not going to test it. So I'm really just here to refactor and change up a pattern where you can go ahead and test it. I'd create, delete and update, and you'll see that everything will work as though nothing was changed, right? But then when you look at the code base, you see that we would have used unit of work instead of the repo? No. For this one to one modification, it doesn't look like much of a big deal. If anything, it looks like more like a bother. Because sometimes we replaced one potential line with two lines. Alright? So what we're going to do is o and here, right? So remember, I always need to save changes. So it needs to be in a tough word, save whenever you do the update, right? So he did the CVE, save for the Delete, Update that. Alright, so what I'm going to do now is move on to the final one. Are not well not fan out on the next one, which is the emissivity requests and Aleve allocation. Alright, the leave allocation is a bit easier to handle. So I'm going to be doing the leave requests to do because we had three different repos interacting with. So we're going to go through refactoring this one together in the next video. But then I'm going to challenge you to try and do this one on your own. So I'm going to do with this one off camera and then we can go ahead and compare that you did it correctly or even that I did it correctly. But we'll be doing this one together. So you can see exactly how the unit of work pattern allows us to convince or generic, sorry, our original Repository pattern a bit more.
58. Refactor Leave Requests Controller: All right, so we're back and we're modify and leave requests control or controller. Sorry. So I've already gone ahead and injected, right? I didn't delete the original references to the repos just yet. So after I finish the modifications that we can go back and clean it up and it will see how much easier the code is to look at. And I'm truck. So let us start off with modifying our index. So it does fall into seem Potter and I'm just going to duplicate a line then come in and then we see unit of words. So notice that we add to the very specific leave requests, repo, repo. So this time I can tell you and it's off work, specify the tables. So this one is the request dot find all No, no filter or anything. So that's fine. Everything will snap ON accordingly. And then here, here's a good one note. Here's a good reason for the whole expression and the ability to do the filter on the fly because we had to look at employee allocations and then look for the leave allocation. And we had to do a custom function for that employee requests to do that and in a custom function. So let us see how we can rewrite. Don't follow Shun's and be more generic. So we'll have the employee, we retrieved the employee ID. So let me duplicate this 1 first. Put some spacing so we can see exactly what's being modified, right? So employee allocations will now be equal to unit off work leave allocations, no costume, and say there's no custom code or no cost on function, just fine. All right, and then we get to put in the expression Q lambda Q dot employee IDs equal to employee id. Look at that. All right, so we are saying unit of work leave allocations Give me all other acquired where that condition is true. And we can do the same thing for this one. So let me come Momento. The original, Our seeing this time is leave requests. So it's Unit o forgot leave requests table. Find all of them. Where the expression q dot is there an employee ID or well, okay, So this is requests by employees. So let me see exactly what was being used here. So it's artifact discipline to go and see So I can use does go to the implementation. And it was checking where. So that was the original lambda expression, right? So I can literally just this original lambda expression. This is a custom function, remember? But no, I don't need a custom function. I can do that lambda expression and put it right in the find all. And we're good to go and let me comment that out. And it will do the same work. Alright, Polar off being generic one code base and allowing us to read powerful queries using very simple expressions. And then there's snapping on because nothing has changed really. Alright, let's do the same for this one. So let's do Pickett's comments and then unit of work. This is what leave requests. So this copy this, and it's fine. And the expression is q dot ID equals ID. That looks good. And then here's a bigger on nowhere. I think this is where we had all of the all of the repositories that are being included were acquired in this one. So let us work through. So firstly, we find the leave requests. Well, we did that here, so I'm just going to copy and paste that code. All right, like for like, then we get the requesting employee, the leaf type ID, then we have to get the God, this leave allocation, get leave allocations by employee and type 1B costume function, right? So if I go to implementation, I can see the X-Y thing it did. It had to get the period at which this year. And then it said, I locations, soil will got all the allocations. And then we said allocations get me the first are default for the employee, for the sphere and for that leaf type ID, right? So I'm just going to copy this whole expression on unclearly, we have a little more work to do, go after get the PIR on. What we can do that from inside of the controller. We don't necessarily have to do that in the method, right? So I mean it's a refactoring exists as a salt where here it's not absolutely necessary at this point. Let me just close. All right, so the Requests Controller, here we go. So I'm going to rewrite it. And when to say var location is equal to. And I'll just write as one all mano 08 units off work dot, leave, locations, dot find. And this is this was supposed to get one, so it's fine to not find. All right. And then we have our expression, which is Lindsay looks something like that. But I'm went off to modify the subnet because we need period. So let me just get the peer to save var periodic date, time, dot No.2 year. All right, so I get the period no. And then we move on. So I'm getting a little error here. Locations o, and that's because I didn't bring over the cue and the leaf type was spelled incorrectly. So B to this spinning off an IV type. And clearly q for the lambda expression. And there we go. Alright, so now this is what the square root like. So I mean, it might not be as neat as having that coastal LM function. But to me, it's far more maintainable and I'm not saying this to be prescriptive. I'm not seeing this. The way you must know implemented if you feel comfortable with the generic, with the orange now Repository pattern, then by all means use that. I'm just showing you a different dimension to how we can get code written and more maintainable. Alright, so we'll go ahead and get our allocation using the unit of work. And then for the updates AC we update here, right? So it did update then see if in this one than update and see if that one. So I can, I'm just going to comment these two lines. And I'm going to see underscore unit off work dot, leave requests, dot albeit. And it will believe requests. Alright, so that's the first slope needs. And in the second one will be leave allocations. That'll be janet staking the allocation. And then what do we have to do after we do all of that? We just need to see. So this is literally just going to carry out i seem operation on once. So while we are turning two lines of code into three, the point is that we're not doing something then saving and then doing something than saving where letting the context nor that this needs to be done. So and we finally see it just gets committed and satisfied. Alright, so we commented out a few lines. And, well, some lines look longer than some because this one, this entire line looks a bit more chromosome then this BOD to me. And this is first and I'll once again, it's going to be more maintainable going forward, right? Alright, so here we have user manager getting that and then we don't hear, we do a fine so unit of work, dot leave requests find. And in our lambda expression, she would not equivalent of that. And then we do the update. So I'm still just trying to comment and rewrite and so we can keep track of the changes that we're making. So that's leave requests. Thoughts about the and leave requests, right? And then of course we have to remember to follow that up with us. And this is a sink. So for the So to create, we get to all of them. So comments, var, sorry, let me duplicate and see you in it all for. So that's one of the annoying parts of refactoring is tough to pay attention and Chen be very meticulous center rumbled off these things. But hey, so we change that OneNote for the create. And here, here we did that same lookup for the employee and the allocation stuff. So I'll just go back on borrowed that bit of code. So it was these two lines. And just replace this one with those two lines? There was the same wasn't it? Leaf type D, OK, it was the same look-up, just different data being passed in. So this should be model.predict type. Oh, he was employee ID and then model dot leaf type ID. Alright, just double checking to make sure I'm making the right connection between the tool. So it was modeled on elif type ID for that parameter. And this one would have been employee dot id. Alright, like for lack. And though you do all of those things. So when we get down to here for the creative, just combing the soul. And remember Unit 04, dots, requests create. And we're passing in that leave request object. And then this is a scene. And then weight the unit of work dot. And I'm going to just take all of this check. So once again, I'm taking all that jet because more than 90 something went wrong, we would catch the exception and we'll sudden we'll be doing the same thing anyway. So just trying to be while we're factoring, I'll be more efficient to it's our operation and I see I have an arrow here, so let me just fix that. Employee dots IID with I kept it. I don't hear find by ID. Did you do an if NBA ID anywhere nearby? Oh, we didn't change this one. This should have been changed. So I'm gonna change this one before I move forward. So that's null Unit 04. Dots leave types, not find. All right, so for this one, let me just rewrite it. You will get all four types. And we're finding by the expression q-dot, these equivalent. So that's alright. And so, so I don't want you to get me wrong. I'm not saying that it is hard on foss that you most and this is neat requests, sorry, it's not hard on Fossae you must use the generic because if you had custom functions that you wanted to type in my Yolanda to ride the functions for some stuff. You can always implement your own your own contract, your own interface, and then have the unit of war or other theropods derbies inherit from that grad. So whenever will interface inherits from an interface. Then whoever inherits that interface, which in the case of the generic repository, it will, it will be kind of tricky. So I had a train of thought and I'm sorry. But you could maneuver yo arrow and if you really wanted to add a custom functions, what to me? Writing it this way is much better because then you don't need to have too many customize functions are on the place. Another pattern you could actually implement something like command and query pattern, where on top of the unit of work, you would have an commands layer where you interact with the command. And the command would actually have the costume functions, which then cause a unit of four functions accordingly. So there are many obstructions and layers you can put on the end of the day, it's somewhat off what you need. It's not a matter of doing it in style. It's a matter of what is maintainable for you, sustainable and going forward, you can modify it an add-on more easily. So I think we're done with the leave Requests Controller. We didn't do anything with the editor, so we don't have to modify those. Oh, here's one more line. And then when we're done this, we can go ahead and clean up all of the code that is no longer useful. So this is leave requests thought, Oh, this is not seeing so there's no weeds were then of course you have to awaits unit off where not. Alright. So now we're done with cleaning of the repose. The older IPO quote. If we're not, then I'm sure more errors will pop up when we started in this. But now that we're using the unit of work, we don't have to inject all of these anymore. So I'm actually just going to remove the references. I'm removing them because I wanted to see the new code. So anything that was commented on nor moving. And you have all the versions of the code. So if you need to go back on Earth me references, you can always do that. But now that we've removed them, let's just go ahead and anything that's commented out, I'm just going to take it all. I don't like seeing too many comments in our code, right? So assessor moved them. And this cleanup activities almost done. And most of it is really alike for like like I said, a lot of them like the queries are 19. But then we're pleased to one land with more lines of code later on. The operations that are required, saving. But the ultimate advantage or the ultimate win for me was the fact that with one injection, wanna reference one reference point, I can access all tables. So initially when I had the three repos injected, you know, I mean, you could figure that I was interacting with this table, that table and that table. Alright? And if a fourth table came into the mix, then I would have to go through the whole process of new contracts, New Repository, injecting it, remembering very disturbing to startled, and then using that report, specifically beanie with a unit of work, if a new table comes in all afternoon is albeit one, the interface here for unit of work. And then to update the concrete class for the unit of work, make sure I initialize it and then we're done. And once that is done, anywhere you inject your unit of work, you know, have access to every class or every table that has been defined for interaction through your contracts. So that for me is the meta advantage with this generic units off work patterns. Like I said, they're always pros and cons because some good no, argue that they find dismissive. They don't like the fact that after writes the lambda expression directly inside of the controller, which is a valid, which is a valid point of view, right? Because then it kind of becomes one Missy and too easy to forget to do something later on. So that is a valid points. Of course, there are pros and cons, but then, you know, no two distinctly different patterns are, well, one builds on the other, but you don't know two ways of implementing this kind of pattern. You can use marijuana suits you in your situation is Maribel contexts than what is new and what is the bus. So we've done leave requests controller, I'm going to leave you to go ahead and do the allocation controller factoring exercise. I'm going to do it and it will come back. We just compare and goes through. And then you just move ahead with one end to other modification and store application.
59. Refactor Leave Allocations Controller: Our guy, so we're back and I wanted to start off on the request controller. This is the one that we just did, but there are certain things that I omitted. And I hope you at least tested and you would have seen some errors. So you would've been getting Arecibo, the null or forensic subsonic. And those null reference exceptions would be regarding the tables that would've been included Based on the previous repository. So remember that's in the original repository like for leave requests who would have automatically gone ahead and said we want to include these three? No, in the generic we make provisions for including what they have to be explicitly stated. The reason for that difference is that you don't necessarily want to get all of these details everytime he wants to do a lookup, right? And so that this square would actually be much slower because then every time you're finding all the leave requests, it's automatically inner joining all the details for these other tables, which might not absolutely necessary for this particular view. You just wanted to list them. You don't need any details, but then you're getting about God, the details do not use them, right? So in the generic repository or units of work butter and we actually made provisions that you can see for this particular request, I want to include these tables. Alright? And so for the leave requests, let's start off with the index. So I'm just showing you the completed picture right where already switched or leave requests to be the unit of work. The requests find all well, we didn't do was include or parameter for includes. So remember I said that you can always, whatever the parameter name is in the more recent version or C-Sharp, you can actually see that Parramatta name colon and then say, what do you want to write originally, you would have had to do something like express that the first one is null. Express that in a second on is all those T3 parameters takes expression. It takes order by Annie takes that includes LR. So originally you would have to say null for the experts on nullify the order by this value for the Includes. But no, if I only want to provide a value for the Includes, I can just say includes colon and then just have whatever value should be for that parameter. So that way I don't have to go through each parameter just to say no, I don't want that one. So that is how you would go boat, including your tables in this new pattern. Alright. So we wanted to include the requesting employee and leave type because on the leave requests index, I believe in that at least we are actually showing the employee's name and we're showing the leaf type that they requested, so we need those two details. And if you, if you're not sure when to do the include Darwin not too does backtracking because we already build applications. So again, this Bach truck and go to the leave requests index page. And anywhere that you see us doing something that I don't here, where you have this dot something dot something else that you know that this is what was included are this is what needed to be included, right. So requesting employee needed to be included. So it will get the first name and Type needed to be included so we could get that name. Alright. So I'll just go through the rest of the leave requests. We already did it, so it's not much more that I need to show you. So for the index, we have the requesting employee and leave type, so you can go ahead and update those values in the function call. We have in the miles, we have to include leaf type. So in my leave, I don't need to include the requesting employee details. Because the theory behind the My Leaf pages that I the employee revealing my own page. So we're getting all of the details of whoever is loved being. And then when we get the the allocations, you just need to find out locations on such far that employee and doess include leaf type. That's all. And then my leave will work for the details we have to get who are proved it, who requested it, and leave type. So you see, that's what I'm seeing. We can dynamically decide when we need only one detail. When we need some details, are when we need all details, we don't have the room, buck all details all the time for no reason because here you are seeing that the approved by the requesting employee data would have been obsolete for this particular page. So you don't want to introduce something that's going to mean the PhD language load when it doesn't have to. Alright, moving forward, I'm just going through and seeing if there was any other one that I had to put in an includes and there wasn't any others. So that would be for the leave requests. Alright. Though the challenge would have been for you to finish all believe, allocation. And I went through and it's already ready to go to all of the injections and replaced them with the unit of work injection. And let's just step through. So for our okay, let me just go school one line at a time. So for the index, I know just how to find all, find all the leaf types. Alright, and then we load up the index page for the allocation on screen. For a set leave. I swapped all the find right there and some of them I deleted and so on. And then afterwards I remember that there should be commenting. So like this one to check allocation. Check allocation would have originally returned a boolean. And that Boolean would've executed this expression using these values. Alright, so ID MID and when it has period. So they can always go back and look at the original tick allocation. But while we did, we just defined period here. And then we said Unit 04 allocations is exists. And that I'm seeing those exist where the employee ID matches that, leave that much is that under peer at much? Is that. So that's, that's pretty much our boolean right there, right? And then down here, we go ahead and do our Creator and our in the list employees. Well that's one is already relying on user manager, so nuances haven't touched user manager. We didn't build a repo for Usama. John, I'm not doing software for user manager because it's already implied inside of our user monitors. I don't want that would be overkill. Moving on to details, we go ahead and we get the details for all the allocations. And so this one line splits into two lines, right? So we did the Fang Xiang call, when did the mapping and then the function call. And they'll split it into the function call and then the mapping, right, so that it'll be easier to consume. So in this particular one, we have red cards where we are doing a lookup on leave allocation on stable. And then we have the expression. So this now we have two parameters expression to get the employee ID equals. So that's under period, was a period. And of course out, find that there. And then we have the Includes, where we just include the one thing. So once again, in the origin, our repository would've been including two or three other tables when residential, you only need to include one for the details view. So where being a bit more efficient here, right? And then moving on for the edit, when we get into leave allocation where then the same thing, we have our expression and we have our Includes. Alright, so after moving on from the edit, we go over to the post where we get the record underwater robots we needed to do update and then see. Alright, and that would be it for our leave allocation controller. And by extension, that's really it for the generic units of work or the generic repository Patreon and units of work wherever you wanted to freeze it. So that's really all we needed to discuss for this section of the module. And later on what we'll do is we'll go through how we can customize sitting up emails, like when an e an email request goes, oh, probably wanted to e-mail the administrative user. Just shoot an e-mail or a win leave gets approved or, you know, it's interrupted with approve, rejected or whatever, then he wanted to e-mail the the employee to let them know. Right. So we can look at notification emails. And we're also going to clean up that delete. Like I mentioned earlier, that we want to change the code here where we have that. Let me see if I can find on leave types where we do that onclick. We want to kind of secure this upbeat more. So when we come back, we'll look at those modifications.
60. UPDATE - Strongly Type Includes for Unit Of Work: Hey guys, welcome back. In this lesson, we're going to be taking a look at modifying our units of work to be a bit more strongly typed when it comes to the list of Includes. So right now it's only relying on a list of type string and we, the developers have to type in the strings manually. Now this can be mitigated against for those that have class names, because we could say name off and we could see employee. So that would actually just render out a string representation of the name employee. So this works, but then it's still not foolproof because not every navigation property has a corresponding class name. For instance, in our I think I locations controller or leave Requests Controller other, there is no navigation. There's no class that corresponds with requesting employee, right? So it's not necessarily foolproof. But if you're wondering, why would you want to modify it? Another issue might be that if we change our class name or something that's in the future or even not property. If I modify the property in the leaf allocation stable from being employee to twisting employee, then there would be no indication in the code that something has changed. So it would be, it would compile, it would build, and then it would be deployed, and then you'd run into an error later on. And users complaining that this feature worked yesterday, it's not working today. And you only know that you change one property which didn't break the code. Well, it did because of this loose typing, right, or loose constraints on the property. So what we're going to do is modify our generic repository and we're going to change the data type for the Includes from a list of string 2, what we call an I included, I queryable HIS, that's a mouthful, but let's look at it together. So we're going to jump over to our eye repository in our clinic tracks folder. And when we're here we have our find all and find. So retinol once again, we're only using list of string for our includes. So I'm going to modify this a bit. And what I'm going to introduce is going to look similar to our eye orderable, queryable read or I ordered queryable. But this one is going to be of type I queryable with type T. And I include double queryable, which is taking a lambda expression and just the same way. All right, so that's what I'm replacing that list of string width. So you can just go ahead and pause and replicate that and include any missing references accordingly. And this is just good to have one big ripple effect throughout the code. So if we jump over to the generic repository, which is where everything needs to be implemented, we can just go ahead and modify the parameters accordingly to include what needs to be included. And then we're just going to have to modify how we do the include part. So when we're doing the list of string, we said if we have content in that list, then for each or included property, go ahead and do the include. Now this is actually going to give us a function called include. All right, so this time, I don't need a loop. I can take this loop oats, and this property should be called includes. So let me just go ahead and fix that. This is includes this includes all right. Just to keep the naming consistent so it's includes. So no all have to do is say queries equal to includes, which is a function. And then I'm going to put in queries. So in other words, we're seeing that we have the query. The query, yes. But then for the query, I want to effect all of the includes that were stipulated here. So let's see how the code is going to look in a minute, but I'm just going to replicate that code in the find all version of this method and fix that parameter, right? And everybody's happy. And then I'm shear. So when we implemented it, I did not create a new file. So this is kind of leading all costs separation of concerns, of course, because I'm putting too fast and it's actually in fairness, took a while to find it. So what I'm going to do is just create a new file while we're here. So we need to go to contracts. And I'm just going to add the class. We know how to do this already, calling it either generic repository, but it's really just going to play host or I generic repository interface, right? So right there, I know where to find my generic repository at all times. Go ahead and include any missing references. And that looks better. So now we know where our eye generic repository is. We have our generic repository. All right, and we have our units of work which minority? And we can build on that. No, Let us look at what we need to do in our controllers. Because no, everything is in RRE, everything that is in disarray, sorry, everything that had an Include is knowing disarray. So let's look at what this new syntax. Will look like. So in the find all, all I did was find all. And then I said I wanted to include these navigation properties, right? Requesting employee and leave type. So null, I can use a Lambda expression. So I can say q dot and then say include. Q-dot, include. And I'm getting a red line here because I need to insert this using statement for Entity Framework Core. So once you go ahead and do that, you can continue. So you're seeing q lambda expression, Q dot include. And then inside of this method you want another lambda expression. I'm just going to use x as the Tolkien this time. And then it gives me all of the properties from the table. So originally I would've wanted x-dot requesting employee. And then I can chain these include statements along. So look at this part very carefully because if feed, if you don't pay attention, It's easy to mess up. Alright, so includes, then we start the lambda expression and with this Tolkien we say q dot include. Then we have the Lambda expression inside of the include, and then we can chain other includes. So I can see then include if I want, which means that if there was something in this property I wanted I could see include the requesting employee, then include something inside of that table. Right. I could also say requesting employee dot and include anything else a boat, although navigation property. So that's another way to have multiple includes in the one statement. But I can also just say include again, which gives me the opportunity to use another lambda expression and specify the other navigation property which is leaf type. Alright? So I hope that didn't confuse you in any way. Just know what's living, just recap quickly. So know when I'm doing the Includes, I have a Lambda expression. Then I say q dot include. Then another lambda expression inside of that include method where I'm seeing this is the navigation property I wish to include. So this all assumes of wanting to rude statement, or at least this sums up wanting food statement. But then as many includes as I have, I can continue the chain and say dot include and then another lambda expression in that one. And then I can continue to include or not include dots include, you would use then include if you wanted light the grandchild's. So if you were at the parent table and the near included in the child and you want a child off that child, then you would say include the child, then include the grandchild's, so to speak. And you could go down the chain, lead that. So now we can get rid off this list because everything now is strongly typed. So if anything changes inside of the domain class, then the code will definitely break. And it's better when the court breaks during debug and compilation time that when it breaks when it's in production, right? So we can continue our repeat that feet down here for every other include statement and we'll just do them together. So this is just leave type, I'm just copying and pasting the top one. But of course I don't need requesting employee. And here is a case in point. This is the leave allocations table. All right. It does not have a navigation property of requesting employee. So an order using the list of string, there will be no way to figure out that we're trying to include something that is not in the current class are occurring table. And then we would actually get an error from Entity Framework Core seeing it cannot find that navigation property. So this is a good way to see the arrows during our typing as opposed to when somebody's using the application. So we can go ahead and remove that, gets an error-free line, and then repeat that process. Don't hear. So this time, I am including the requesting employee yes. The leaf type, yes. And then our third one. So I just say dot include once again. And then in this lambda expression where including the approved by, approved by me, make sure, alright. And you see once again you're getting errors when it cannot figure out what you're trying to do, right. Cause approved is not something that can be included, however, approved by NB. All right. So we can clean up our code, get rid of some of the smells, and get a cleaner looking more sturdy, cold, right. So that's was the leave requests controller. Let's just do I'm just going to run through this one and show you. So what I did was just copy and paste lines from the other controller into the leave allocation control. And then we're just going to fix those errors together because now we can be fully aware off all the arrows. So first or include the missing using statement. Second one, get rid off the include statements that we don't need to believe in this one, it was only leave type. So I'm just removing anything that is not necessary. And then in the edit it seeing include the requesting employee. What I know, I don't need the approved by four this one. But requesting employee, I believe that was just employee. So case in point, once again, it's always going to be looking at what are you trying to reference? Is that reference really even there? Alright, I believe we have one more here which is just a missing brace, 0, have an extra grease. Alright, so that's two controllers don't on the last one, well, this one didn't have any dependencies on any include. So let me go ahead and build the project just to make sure that there are no other debug errors anywhere in the code. And it was successfully built. And I can assure you that up until this point, everything you have done will continue to work. And once again, the importance of this refactor is that it will reduce the likelihood of you introducing any errors as human T in this application.
61. Review of Built in Security Features: Hey guys, In this lesson we want to review some of the built-in security features that is V.net Core has afforded him. Now building a secure website is of the utmost importance. There are quite a few ways that person's cannot tacos. And while some of them are more based on the network, like maybe denial of service attacks. Some of them are actually in the control of the developer. They are actually the responsibility to make sure that these protections are in place fall squarely in our labs. As the application developers know, Microsoft of course knows the importance of security. And you would see that they already kind of baked in certain things like if we review our user management stuff, Lucy, that the passwords are hashed to, the same password will never the same way twice. And lots of considerations went into those kinds of things. It's easy for us to put in like authorized to restrict access to certain parts of our application based on the role or just needing somebody to be logged in, certain things are already built-in. So I wanted to kind of move away from that because we've already kind of explored that security and access control, but then adds an application level. What are the mechanisms that they've already given us? So one very popular attack is cross-site reference Forgery, CSRF for short. Now this type of attack allows an attacker to induce a victim user to perform actions it didn't intend to. So long story short, somebody can probably write like some form of JavaScript to kind of automate an option. And you'll being our regular user, you think you're doing something. But then because their script is running in the background, they could be manipulating the data on the website that you are visiting. So as a website owner, right? So that was you as a user, your ear, you don't know what then as the website developer, the owner of the website, do you want to make sure that the attacker won't be able to manipulate any user's session on to carry out any malicious attacks. So one special way of doing that R1 Lupo that people would usually want to exploit would be anything that is accepting data like up post. Alright? Well, when you do an edit and then you click Submit as we've gone through before, you know that it does up post and then it comes here. But then notice that all of these controllers, once we generated these controller codes and these options, right, they all had this flag above the post method, validate anti forgery token. So what happens is that every farm that dotnet core generates the automatically put in, in the form tag some anti forgery Tolkien to see that makes sure that any requests coming to this endpoint. Has the, has a valid Tolkien. Alright, so the Tolkien is baked into the form by virtue of you generating that edit form. Once you do that farm Tang, it's automatically there. You're not seeing it. You don't even have to put the top there. You don't have to do anything else. We didn't have to do anything else. But it wants the user hits Submit. Token is going to get submitted along with the request. And then this annotation is seeing, make sure that this token is valid. So if any requests comes from somewhere that where the Tolkien was not a system generated and valid, then it will reject that request. If there is no Tolkien, you will reject that request. That's like an automatic level of protection that's given to us. Know, when we were setting up our, I believe leaf types. And I would have alluded to setting up the delete. Remember that we have the duty tier as the get and the delete as the post. But then we modify the user interface to kind of bypass the need to go to the post and just deal with the git know that dissolvable in our ability. So I did say that they're more secure ways to deal with it. And I'm just addressing it at this point, right? That is a security vulnerability because somebody could automate our requests with any ID, this delete option, and delete the data, but then we have a more secure one. So that's why they gave us two steps to begin with because I wanted to make sure that the delete one you confirmed on to that it was coming from a valid source. So we will be addressing that security vulnerability in this section. Another kind of built-in protection that I want to point out also is that afforded to us by Entity Framework Core. So because of how Entity Framework Core builds its statements, sql injection becomes very difficult for an attacker to perform. So SQL injection is a type of attack where they would fill out a form and in the text box they would put in some form of conditions such that if you're not forming your SQL query, we're using the best practices, also known as prepared statements, or just using an ORM Object Relational Model, our mapper, sorry, just the Entity Framework are in other languages. You know, each language has its own. So Entity Framework is native to dotnet. If you're not using one of those are once again using prepared statements, then you run the risk of exposing the tool, an attacker just buy them, putting in an SQL command inside of your form. So using our Entity Framework, the Access, database, access layer, that is like an instant level of protection, a very, very capable level of protection against regular attackers when they tried to use SQL injection. And there are times when people maybe want to write their own SQL statements. We didn't really write our own. We relied completely on EF Core, our link syntax. Well then there are times when people may use EF Core or other libraries that dapper and end up writing their own SQL statements. And there's nothing wrong with that, but they all give you the mechanism to prepare the statements before you send it off to the database. And prepared statements mean that you create like parameters and then you plug in the values into parameters as opposed to just concatenating the user provided inflammation. So the SQL string. So that is an incident level, level of protection again against SQL injection. No. We're moving on and the next thing that we're going to be doing is modifying our whole delete process, right? So like I said, it's a security gap in our application. You'd see a lot of examples doing it the way that I did it. I mean, the simple enough to get started. But then at this point we're no longer getting started. We have a full fledged application and we want to publish it to the Internet, so we need to make sure it's airtight. So we're going to go through and fix some of these gaps as they arise.
62. Secure Delete Method: Hey guys, welcome back. So what we're going to be doing in this lesson is securing our delete button. And it's going to be so simple, they are probably going to say so why didn't we do it this way from the first time? And yes, I accept that feedback book where here no, and that's just deal with it. So what we need to do is, and there are quite a few ways. So one way that you would probably see people do it is the confirmation. And they probably don't just use the JavaScript here. Sometimes they don't just use that. What they sometimes do is The put in like third party libraries like sweet alert and stuff to handle that dialog box that comes up. We can do that. No problem, but I'm going to keep it simple, simple enough to be effective. Because what we really want is instead of an anchor tag that is simply going to pass along this route with the item ID and just call the delete method here, I wanted to submit standard request with a valid and T4a Tolkien to the delete method here. So it knows exactly what it needs to remove. And that's actually a simple As, and I'll just create another line right above. We can wrap a button inside of a form. All right, So this form I went into, LET is B dash action. Your action is delete. And then I'm going to say that you're the rule to IDS. It's still that, but then your method is post. So what's going to happen is once this form gets submitted, we call that post action, right? So then instead of having this anchor tag and I'm going to just reuse this, but instead of using an anchor tag, I'm going to use a button and the button type, we'll be type submit, our type equals submit. So we know that this really represents a submit button where it's still keeping our Bootstrap classes and icons on everything. But it is a submit button that will warn, confirm if you really want to do it, and then go ahead and call the actions. So I'm going to remove this route ID. I don't mean that inside of the button itself. All right, so let's take that one for our students. So this is leave types. Let's test this. Alright, so let us test this. And you see here that it's causing our design and say, well that's secondary, I know, but I want to show you exactly what's happening in the code. So I'm going to go to Inspect Element and show you that when we look at what is here for that button. So this is an R form. All right? And then this is our button. Sure. But then look at this. We have an automatic input. So notice all we did was create the forum on the boatman. They are bought it generated this input with the name. I think that's about two underscores. Request verification token, type equals hidden, and the value is equal to this blob off stream that Hush. All right, so that is our anti forgery token. So this annotation above, and I just put a breakpoint here to make sure that we're hitting it well, this annotation above the method is saying, I will only allow our quest once it has an anti forgery token that I recognize. All right. That way nobody can hijack our sides. I'm just send our request because they can easily figure out the path and just send our request slash, delete slash one and the first record, which is what we want to avoid, right? So when I click Delete, we still get the confirmation. If I say cancel, nothing happens. If I do it again, I click Okay, then it hits our breakpoints. Were still getting over the ideal kid. There's no ID. Okay. And I'm sorry, I know exactly why there's no ID. So let us go and correct that. Let me just stop the execution and then we can go and current in the button. I didn't take this, so DSPS. So what happens is that it, it has its own farm auction and it's competing with the action that would have been generated with this. So let's remove that and try again. So I'm just going to delete, click. Okay, we're hitting the bird point and we see the ID is now coming over. I'm just going to continue. And there we go. So that is a far more secure way to delete. So not much changed visibly once again, you could spruce it up a bit by using one of those third-party libraries to prompt the user. Are you sure? Are you sure works just fine. But then the mechanics behind how that request actually goes to the server is no far more bulletproof than it was before this, this lesson. So all you can do is go through the other listings and just make sure that they're doing the same thing. And I would also recommend that you either comment old are just delete this the delete method because we are not going to be using it. We just want to rely on the post method with the and T4a Tolkien. And then that will take care of everything. And I also modify this not to, not to one tick any parameter outside of the ID. So to call it that model that was being referenced in the parameters and just lift that try-catch and I just put a return to the theme of index at the end of this operation. So that has less to do with security and more to do with just me modifying it. So I think my code looks a bit cleaner. Another thing that I did to clean up my button display was two in that TV that we reserved for the buttons, create a div with a rule. All right, and in this role, and just run as a straight divert. There, there we go. So in this role, I have a div PRB button and I'm just giving you a col dash whatever size. So it could be two. It probably could be one based on the size of our buttons so that everything is in line. So the div, div with a class called dash T2 for the, that is the edit. Then we have the details and then the same thing for the form. And we're just so you can see clearly. And so our buttons will be displayed in one line so you can go ahead and that just steer your interface like that. Now that's it for three or no reviewing this delete operations so you can go ahead and implement these measures in your other pages.
63. Send Emails using MailKit and SMTP: Hey guys, welcome back. In this lesson we're going to be taking a look at another security concern and that is with the registration. So the reality is that yes, you might be setting up a system like this for internal use within your company and well, okay, only company employees would be expected to access it. However, regardless of that, you still probably want to put in that chicken balanced, make sure that the person who is registering confirms who they are at the very least. So adding that e-mail confirmation feature to any application is very important. And of course, even though I'm presenting the email feature within the context of security, we can also use that email feature in other parts like when the submitter leave requests, we can fire off an automatic e-mail to them, stuff like that. But for now, we'll just focus on retrofitting or a distribution process to make sure that an email is sent off to the registrant and they confirm and then they can access the system. So let us just review what our on post action looks like or what a handler other. And we did make a few changes because we modify the user. And then we went ahead and created them at the same time. And then we just went ahead and added the rule and send them in all at once. So there's nothing here to confirm who you are once you register. So I wanted to kind of change of this flow will still need to do all of this object Creating was still need to proceed if the registrations or successful. But we already had I email sender which was kind of built in. And I email sender in the original code was doing some work here after logging that a user hasn't been created. So let us, us reintroduce some of that code and then we'll go ahead and configure that I email sender class 2 what we need it to do. So to reintroduce what happened here, we would have had a code being generated, right? So we have had these two lines of code. Var code is equal to our IT User Manager. Dots generate e-mail confirmation token, async, and we're passing of that user. So some Tolkien is going to get generated relative to this user. And then we're going to encode that Tolkien. And we're storing that Tolkien as a string inside of this variable called code. Now that code is going to get a touch to the page. Pretty much solar are going to have a confirm Pete. So when we scuffle at it, we did have a page called Confirm Email. Here it is. Right. So when they get the e-mail to confirm who they are, they need to click that link and it needs to load up this page on get, it's going to get that code. There we go. So and once again, this was all that was there before and I removed it. You probably commented it. So if you commented it's OT can uncomment it at this point. But what we're going to have is a callback URL equals URL dot page. The page we're going to tell them to go to is a cone slash Confirm Email. Right. So that was the one that we just looked at. And we're passing in the values new area identity, user ID is the ID given to this user and the code is the code that was just generated. And then return URL is whatever return URL we're passing in from here. It may or may not be there, That's fun. But the point is that this is the URL. Let's go into get created. So the next thing that we need to do is confirm or allow them to confirm the email or their email address via sending an email to them, right. So the next line would be awake and alert to and through what asynchronous programming introduces. So awaits, score email sender dot send email is sink. Our sending an email to whatever e-mail address was just used with the subject, confirm your email. So if you just hover, you see the email, the subject, and the message. So HTML message, meaning that we can put in our tags. So please confirm your account by, and then we have the anchor tag with the href, and then we issue them encoded that callback URL that we just built. All right, and by clicking here, so you can change that message up as you please. But that is at minimum what we know. The original code also erupt if, if statements, and it actually had these two lines in an if statement to see if we're just starting up, then send them to the page where they can just click on, go ahead and confirm else, send them to the sign-in. So nowhere actually implemented in the e-mail. We don't need the fit the fail-safe that we were given arginine is so this is what your register on post needs to look like. So I'll just leave that on the screen for a bit so you can take it off if you don't already have the original chord. All right, but no, we need to actually configure email sender because if it hits this, then nothing will happen, no email will get sent or anything. So we need to configure or e-mail sittings soul in our AP settings.js on file, we're going to have this new stove for configuration. So I'm calling it Email Settings. And we're going to say yes, use SSL, the mail server. So I already put in some sample stuff based on Gmail. But then the reality is that in your own company you might have different SMTP settings. So I'm just giving you an idea of what goes we're right relative to your situation. You put in the values, you put in the sender name. So any email colon from the system. And then you could put maybe the company name at the end so people know it's not spoof. The sender email would be what email am I dispatching this e-mail from? So this could easily be admin at leave management are no reply, something like that. Leave management and the password that will be needed to access the account associated with this, right? Once again, all of these, these two have to be configured in that mail server for the utility to actually connect and be able to execute the sending of the email. Now, outside of that, I'm going to introduce a new folder. And I'm just simply calling IT services, right. Because I'm just putting in that e-mail Cinder service, so sorry, I'm just adding a new folder and I'm quoting IT services. And then instead of services, I'm going to have a new class file that I'm going to call e-mail settings. Now this class is more like a model class and it's going to have identical fields matching to the app.js settings JSON file. So I'll just go into really serve the purpose of is seen from the app settings into an object of this type, and then we can use those accordingly. Now the more important file would be an interface that I'm going to create. And I'm going to call it I e-mail senders. So this is a, well, I'm just going to put everything in one class for us. So I'm calling it I email sender. And this one is really an interface. But then we're going to have a public class. So if you want to separate them, that's fine, but I'm just going to keep them together just for educational purposes. So I email sender and that class is inheriting from our interface. So our interfaces going to have one simple function which is going to actually mirrored the function that we saw here. So email sender that says backtracked, even sender here is referencing I email sender which is B fault. All right, that, that comes with the system, but we're just going to be overriding it with our own functionality. But it does have that function, Send Email, a sink. So I'm just overriding that send email is sink. All right, and so we go ahead and implement that interface here. So we have that method available through this. So I'm going to firstly in this class declare an object of type Email Settings. And then I'm going to have a constructor which is going to initialize this from the options file, right? So I'm just going to see AI options, Email Settings, and then, and that's my tiny object. I'll just go ahead and include that extension. And then I'm initializing. So it's almost like I'm injecting into this local e-mail settings object from the options File. And Options here represents me. See, realizing this section of the app settings JSON into the matching feels like we discussed soul afternoon. And this should be dot volume, sorry. All right, so now that we have our local object called upsetting someone to start configuring what happens inside of the send emails. So I'm going to pause at this point and I'm going to include a library. Probably should have started with that. What we need to go with two new Git and a library called meal kit. So there are quite a few libraries that you can use and third-party services. But Mailchimp just slips right in. And thus the one I feel comfortable using, so mail kit. And when we find it, we can go ahead and install it. So just find it and know that we have that set up. We can go back to our configuration. So the first thing that I wanted to do is define an object of type mime message. And then this will require me to include libraries know I'm using my kit. Alright, so we can just go ahead and add that missing or difference and that my kid is courtesy of our meal kit are and as we continue, we're going to see my message. So we're just building up the message. Now my I'm just means various datatypes. You don't know what kind of messages. So we're just using a generic message type to build this e-mail, right? We don't know if it includes pictures or anything like that. So that's why we're using that my message object. So I'm going to say mime message from DOT. So my message dot from DOT. And in this method, we're going to be adding our mailbox address coming from the e-mail settings sender name and email settings, sender email. So we're adding the mailbox address based on those two values. And then in the same manner, we need to see where is this e-mail going to. So I'm going to say my message dot to dot, add mailbox address dot parse, email. And email is what would've been provided in our sendMessage method. The next thing I want to do is make sure that I mentioned the subject. So my message dot subject is equal to the subject that was passed in. And then I'm going to start up a builder session or a builder objects. So I'm going to say var builders equal to new bodybuilder. And I'm seeing HTML. Html body is equal to the HTML message that came in through our method. And so nice and easy and straightforward so far it then I'm going to see my message dot body is equal to Builder Tool message body. So it just those are quick conversion. Know for after we've prepared our message, we actually need to execute are sending. All right, so I'm going to try and I'm going to start off new session of type SMTP client. And I'll put the using here because I wanted to die, right? It's finished, so just have that there. But when including the library for SMTP client, we're using Mailchimp not System.in a meal, right? Meal kit. So pay attention to that part. So Mailchimp dotnet, the SMTP, that is our library. And then we're going to validate the certificate call buck. So we have this line, client.write server certificate validation call buck equals. And we put in these object values and in our Lambda is true. So we're just saying yes, it's a valid certificate Pretty much. All right. Then we're going to connect to our SMTP server. So we're going to say, I'll wait, client.connect is sink. And then we're passing in our settings and I'm getting this, okay, and let me just deal with what this line is seeing. So client.connect, async, email lot settings, meal service. If you just look at what it requires, it requires the holes, the port. Are we using SSL, right. So mail server, mail port and yes, or using SSL, we're getting this o and we say dot configure how it falls, right? But this red line is here because we said we didn't see a scene. All right, so moving on. After we've done that, then if authentication is required for SMTP, which more than likely any secure SMTP it probably will be, we're going to say client not authenticate a sink and they were passing in the e-mail and the password. So that's what I said. These have to be configured under-recognized and the SMTP server, I will associate not configure our wheat falls. And then we're going to see client send a sync. I'm pretty much all of these we're just seeing configure, a weight falls at the end. So we're going to say send a sync my message. So this is a message that we'd built up, send it, configure our way, it falls. All right. And then we go ahead and disconnect asynchronously and configure a way it falls once again, so that is pretty much it. And then if we hit an exception, what we want to do is probably just throw a new invalid operation exception, pos single message. All right, so that everybody knows what might've happened. Of course, in a real sitting will probably wouldn't do this, but for test purposes we can leave that. All right, so our next order of business is to actually register our email sender. So we already know that when we create our own services, we have to go into our startup. And then in our configure services section, I'm going to add a little I'm just going to carve out a section somewhere here. I'll put it right above the mapping. And I'm going to just put a little comment, says see exactly what's happening. So services.com figure and we're adding e-mail settings. And this is our module 4, 4 up settings.js IN fine. So configure email settings. And I'm going to say configuration gets section Email Settings, right? So that's what I'm going to call the AI options. It will just know this is a section on it should serialize into this and use anywhere else. Then we're also going to add singleton for email sender and the email sender. So one instance of this will pervious throw the entire application on pretty much know, it would be nice to this for a spin, but like I said, these were really just demo values. You will get your SMTP settings and you can use them. You can try out different providers like send the grid or male jet. They all have SMTP servers that they will allow it to use for relatively free or very low costs. And once again, if you're in your company, then you should be able to access the SMTP server and put in those credentials as needed. Be very careful with those credentials. And you can go ahead and test it till it's for register. But once again, this email sender can be used anywhere. So another practical, less security-driven use of it, they'll put practical use of it would be maybe in the leave requests controller. Because when somebody submits a leave request, it will be good if after it has been created and put into the system successfully, you send off an e-mail like red here. Send email, tool, supervisor are whoever we know gets those emails right. Upon cancellation. You could send an email to both the user, so you could send user to supervisor and requesting user, right? When it's canceled, you send an email once it's successful and send email tool user who requests that again. So these schon, The point is that the same way we injected every other service, like our units of work, we can easily just come here. And now those are those duplicate one of these lines and say I email sender, email sender, initialize it. And once we have that, we can use this email sender anywhere so I can see upon creation of our requests or do you put the comments? There we go. I could say email sender. Send email is sync. And so the email this could be the supervisors emails. So I'm just going to put in an e-mail. I think we're using admin adds local host.com as our admin user. That's fine. The subject could be leave request. Alright. And then newly request, once again, be a son your, your situation, you make these decisions, right? And then you put together your HTML message so you could context to other buildings. So there's so many things you could do, right? I don't want to necessarily put too many ideas in your head, but I just want to give you the concept and I trust that you can take this concept and apply it in your own context. All right, so you could do that email right here. Once again, you could do it upon cancellation. You have so many applications, but no, you know how to configure your application and configure it to send e-mails where and whenever you need them.
64. Publish Section Overview: Hey, guys. So we've had quite the journey we've built on up from the ground up created the court. First of the database we explored all off the nuts and bolts. Put it together and we have a nice working out weak and log in IQ and create a user apply for leave on everything seems fine. No, this is all on over machine on the final step. Really? To any application that has been developed is to put it into production and put it in a way that this is it is accessible toe other people. So, like I said, open to know we've been right in the Cordon Results studio and then running it in people more. It's only on our machine, the databases on over machine on. Unless we leave our machine on for ever, nobody else will ever be able to get access to it. No, For this morning, we're going to look at home. You can go about publishing this application to public spaces for other persons. Now, we're going to just stay this time to look at a few options on going, just giving you an overview off the different publish techniques that we're going to go through. So the 1st 1 that we're going to look at is publishing to a local server on when I say local server doesn't necessarily have to mean that it's on premises because no, you know, everybody's movements of the code servers aren't necessarily in the same office space. So when I say local server, I mean really just a server somewhere on what we would need on that server is, ah, special software called Internet Information Services, or II S. So this is Microsoft's flagship Web server software on DSO. If it is going to be hosting or from machine is going to be hosting a Web application like our own, we have to make sure that's outfitted with II s Andi. It is ready toe, receive that. So we're going to look at publishing using IIS or to a server that has iis on. Then that would be more for like an intranet sitting right. So, you know, people would be ableto roasted that's ever using the machine name on, then are our own custom set up for our Earl on. Then they would be able to access the application accordingly for that one for that scenario also need to take into consideration that there has to be ready to be server. So whether the data bees sits on the same server or it's on a remote server, that is going to play a huge part in our ability to publish Andi. Use the up afterwards. The other scenario that we're going to look at its publishing to Microsoft Azure. So if you're publishing toe a virtual machine on Microsoft as your than, it's pretty much the same set of steps as what we just went through with the I s and a server cause that service I served regarded software, it is right. But then, as you are, also gives us managed instances called as your Web apps. So we're going to look at, you know, signing off for in a spherical, and she can get one for free for a few months. Rights problems, off free services and a few credits on that should be enough to get you started. I already have Annacone, so I may not be able to bring it through the Senate process. What? It's a relatively easy process on, actually, how we can go about deploying Web application toe as your and also spinning up a managed instance off the database server or will serve these since it's managed to. So it's actually a deed to be service offered by Microsoft as your so stick our own guys. In the next video, we're going to start configuring a server on, then publishing our application to set server and then just reaping the wards off that.
65. Setup Internet Information Services (IIS) on a Server: Hey, guys, welcome back. I have here on screen a machine. I have a virtual machine and let us to see it is going to play the role off our production server that we're going to be publishing over the Net core application to no, just so full disclosure. This virtual machine is actually in the azure. It's in my clothes cones, but once again it's the same dynamic. It doesn't really matter where the server is is just a matter off getting it or fitted with what you need for hosting a dot net core application. So the first thing that I'm going to get is IIs installed. So we have to have this application or this Web server application called II s or Internet information services. So if you're on a server or even if you're on a regular machine, you can do this on a Windows 10 machine. He can go and say You want toe. I don't remove features Well, it's actually turned Windows features on our off right, and then you want to enable Internet information services. So if you're using a Windows 10 machine A. Don't have a server to at least run this experiment. If that's fine, you can go ahead and look in your windows. 10. Just hit. Start typing windows features on. Then it should give you the option to get to this. It's a dialog box that allows you to enable Internet information services. But I'm going to go there. You notice that there black boxes. So I'm actually going to go through that entire installation, right? No. But I want you the server. But it's the same set off options regardless. All right, So if you're on the server and you have the server manager up for you, then you can goto ad rules and features. This will bring up a wizard, which he can just go ahead and click next. And I'm just thinking next through these because these really have no bearing on what terrible to do, right? So I don't know about your configuration, but there I don't need them for May. So at this point you get the screen, add arose and feature server rules, and then you'll see Web server. I asked this that there see what can go ahead and take that and click add features and then go to next on. Then we will be led to the same type off listening that you would have seen if you were using Windows 10. So from here, their fuel features that you definitely want enable. And if you already have dot net installed are not that framework. Install something, maybe take authority on you may not be able tow on. Take them. But pretty much Whatever you see here has sticked on my screen. Please make sure that you also have them picked on yours if you want to add, um you know dot net from where 3.5 features you can on. I'm just mentioning that because I mean, if if this is the first time you're configuring the server than you need toe may be configured for different scenarios because not every application might be a dominant core applications. So you want to make sure that your eyes has all the more used to handle the latest as well as legacy applications? If you already have, I asked then I guess you don't have to muddy the waters by doing any off this second. Go ahead and click Next on, you click next again on, then we get the drill don't. So this would be more common between the Windows 10 allowed box or any other windows machine. Della box for insulting I s on the server installations. They want to make sure you have Web server ticked. Come on. Http. Features all of these need to be ticked. You can add more logging if you want, but at least just make sure that what I have ticked is also takes on your side. So I'm just going to go through slowly without going into too much detail as to what each one is. Four. And then we come down to this one. That's his application development. You want to take application development? Andi, I'm just literally I always just go crazy here and to stick everything right. But you want to definitely mean sure that you are adding all these features in because once again, you want your eyes configuration to be as inclusive two different versions as possible. All right, so I'm taking all of these except the web static Web socket protocol. If dp server, I don't need that for no on going to make sure that I have my management console also ticked. So I'm just going to go through solely once again on then you can just meet, double check and make sure And I mean, the more you tick is the more features you have. Really? So you know, you can pick, choose and refuse once again if you have Asare, the server that you're wouldn't use has eyes installed already. You probably don't need to go through all of this on then. This is seeing Do you want to specify? Well, you don't have to worry about that. Restarts are just restart automatically if necessary. Obviously, if this is your personal survey of that leverage if not, please fund soldier system administrator to make sure that you're doing this story a time when nobody's really accessing the server. And then you can go ahead and click install so the ass installation might take a while. Or maybe you're just finished already. Whichever it is, mine is actually still going. So understand, to continue with the other things that we need to do to get started on, that includes getting the hosting bundle. So we where this is a familiar page for us because we had to don't know the SDK. Initially on when we started our project. We were at where is on 3.1. So if you've bean doing the updates upon to know, then you would probably be at version 3.13 or maybe a certainly higher, Um, increment from this. By the time you're doing this part, it doesn't really matter, though. We're just going to get the latest hosting bundles on this speech were adjustment to pay attention to the SP that read Koran time on. We're looking at the windows and getting the hosting bundle so we can just go ahead and click on Download that hosting bundle, all right, and it's don't loaded, but it's telling me that ice needs to be enabled. So if you're still getting this message after you've completed the installation, then you know you might want to backtrack and make sure that it properly or make sure that it was actually completed so mine isn't completed. I'm getting this error on. That's fine. I'll just wait it out and resume once. Assist on All right. So no Isis finished and it may have taken a while. That's okay. We can close. My server didn't restart, so that's also good and then we can validate that it's working by going in your browser and just writing in local host. And then you should see this launching page. No need to bring up the management console shaking. Just go to start and maybe typing I s. Or if you're on the server, you can just use the server manager and go to tools and go to Internet Information Services manager. All right, so if you're on a regular PC, then you want to go to start in writing s and it should pop up in the search results. By the way, we're here. So we have the machine name servers. Name is SQL. So it has the SQL server installed on it, and that is where the database will be hosted for up. But when we get to that point, I will show you what happens when the database is not on the same server as the application . No, and I I s we're going to create a new website. So you see, on the the server you have what you call sites, and then we also have the default website, which is what was launched when you typed in local whole straight. So I'm going to create a new set. So we right click science goto add website And then I'm giving it a Scient name and I'm just calling it leave management. It would also create a new application pool, which we will go back and modify after this. Um, but then you can go ahead, say leave management. We're going to choose a physical path. So the default path for any, um I s website is generally in the c drive, then I nightclub www roots on Dwell. Everything in www routes would be right now defaults websites. I'm just going to put in w w route a new folder, and I'm just going to call it leave management. Right. So we go ahead and create that new folder, click OK, so anything that goes into this folder will be still be broadcasting on our new site. I'll leave management. I'm going to leave the binding as http on then the law. The horse name meaning hole will. What address will I used to get to this site? I'm going to make it simple. So the thing is once again in a production environment, you may have a system administrator who will provide some guidance as to what standards obtained with these addresses and setting up these s addresses and so on, but right. No, I'm just putting these here. This is my server sometimes showing you the steps either way. So I'm calling this leave management that internet dot com because really and truly, we build this application so that our coworkers can use each I can use it to approve. Leave on our Corporates can use it, apply 40. So it's something that the whole company, the whole office will need access toe on dso we're doing leave management, not internet dot com on We can just say start upset immediately click OK on, Then we get our site. So if I bro's to it, then it's going to try to go to internet dot com. So the point. So what we need to do know is modify the hosts fire because once again, this is something that is on the server. We don't want it going over. The Internet are attempting to go over the Internet, but that's what it's trying to do. So I'm going to go into my computer, and I went to bro. Still the folder in my C Drive Windows system. 32 drivers on then e. T. C. I guess that short for etcetera. And they were looking for this file called hosts. So this hosts file allows us to manage the server mapping, So I'm seeing several wrappings. If you're doing it locally, it's the same thing so we can open this up amusing notepad plus plus, and it's best open it up in administrator more because you know, this this file is very delicate, but what we're going to do is set up a local horse mapping. So you see the word low couple. So if you're not so familiar with servers, local host is the name that results that this I p, which is 1 to 7.0 dot 0.1. Right, So any time you see this, I p, it's synonymous with local hosts and local host or this I p really mean the machine you're on. All right, so remember that when you were running our application in B, but more duty local horse call on on some port number. It's the same thing you see in the machine. Your on call on some port number. Right? So our default port is Port 80. We could have changed that for our new site. What? I left it on Port 80 on. That's the default. Http broadcasting port eso. What I'm going to do is set up another local horse mapping to say that local horse or this local host I p address can also associate itself with our new website, which is leave. Manage meant that internet dot com. All right, So if I'm on the machine and I Ambrose, that this, then it will resolve to local host and look for the appropriate website. Right? So I understand toe save that once again, you have to be in admin mode on. Then I'm just going to copy this and then attempt to boast it again and nowhere seeing a narrow but have far more comforting error this time. So no, it's telling me that it's giving me an I I s era, which means it is indeed trying to hit the website that we just set up. So I'm goingto go to that website folder which remember, is phoned at Sea Islet pop www route and then leave management on. Then I'm just going to come here and I'm going to create a new fast so you may be restricted with some of the things you can do here. Once again, if you're administrator, you will be able to do everything I'm doing here where seamlessly otherwise, you may want to create the file and maybe my documents and then copied over. But I'm just going to put on index dot html file here on it's still a text document. They need to make sure that extension sees dot html. So I'm just going toe a file. Both of you finally, um, extensions their regard on takeoff the txt because I definitely wanted to be an html file on most servers. Most if not all servers look for index. That's the first piece they look for it. So understand, to modify this in the experience and I'm just going to say hello, I iss all right just to prove that it's actually working. So when I refresh this is going to look for the index file and then it's going to show me Hello, I s So we just set up or for a slip server, in case you know, this is your first time. I hope you're enjoying this exercise. Now. One more thing I'm going to do or will we have two more things to more very important things to do. We're going toe change our application pool. So I'm going to go back to the manager. I want to go to the application pools and then we'll see the leave management application pool that we just set up. Click it Goto advanced settings. What basic settings? Sorry. Basic settings on. Then I'm going to change this from .net CLR to know Manage cold. All right, and then I click. OK on, then. If you want, you can reset. I think it would have stopped and started at away. But you will show your home in the applications are running on all that You need to know. If you click out and back in, then you should see one. It means that we have one website or one web application running on that pool. So pools are like containers that alert to separate your websites and is the sea You can separate dotnet to applications from not met. 4.5 applications from you know, the default up, which comes with the default website on. Then we introduce a new site. So we get this one. But this one needs to be no manage court because it is going to be hosting our dot net core application. So that's the first off the two things we have left it with. The next thing we have left to do is to finish up our installation off for run time. So understand, to go back to my folder, get my run time on, then we see a different message where it says please restart after the installation completes. All right, that's fine on. So we can just agree to the terms and go ahead and install. All right, so this installation wouldn't didn't think much longer or it was a much shorter insulation than the I s one. But once that is done, we can just go ahead and refresh our side just to make sure we're still hitting the file on . We have no errors. So in the next video, we're going to look at the actual publishing off our fast from visual studio and moving them over to the server
66. Publish Application to IIS and SQL Server: you guys welcome back. So we just set up over I as server on our our server application on our actual machine, where our application will be hosted on DNO. We're going to be publishing the files from visual studio to the server. So this video is going to have me flipping back and forth between visual studio on the actual machine as there are some configurations that need to happen. We need to deploy the database that is needed to support our application on. We have a few little things that we need to do. So I'll be I'll do my best to be clear as to what I'm doing and why I'm doing it so that you have a full appreciation as toe what it takes to get an application up and running. You know what? I have hope here in visual studio. I got to. This is by right clicking the project I'm going to publish. And then we brought up this menu. So on the publish, we want to create a new profile on. Then we see that we have a couple options of the up service on as your where the as your virtual machine and, like I said, a virtual machine on us. Your is pretty much the same thing as a virtual machine on premises. I mean, a virtual machine is a virtual machine. So it's the same principle, right? So then you can also set up. I asked directly or FDP. I like doing the folder version on this full of version or the full door. Um, method, so to speak is good for the eyes on the virtual machine version, right? Because at the end of the day, it has to do with moving the physical published files from your machine to the server location. Right. So I like doing the fuller version on publishing locally because, you know, you may have permissions issues when you're trying to go to 1/3 party machine. Your user versus the user you're executing on the might not have the permission. He might not be running visual studio's administrator and stuff like that, and you get generic areas that can frustrate you. So I'm just advising that you published You can just leave this default for their on. Then we can go toe advanced, and then on the advance, we can just take a look at some of the advanced settings and have an appreciation for what these are seeing. So you have configuration released Stargate Framework. You don't have to change that deployment more. They don't have to change that target or in time. We don't have to change that so pretty much. You don't need to change anything here unless you have other ideas. Off course we go down to the fire published options, it says Remove additional fires that destination. Now, if you're publishing toe that local address, then you know you can almost safely take that. If you're publishing toe 1/3 party location, I advise that you be very careful with taking this because it means that it will erase all files in the location before it puts the new files on. Then if you're full of path is but and I have gotten in trouble with this in the past. But if you're full of past is bad, then that can lead toe, you know, detrimental effects on other applications that might be in the same location, right? So you want to just make sure your folder path is safe on Do you can take that somewhere to ticket. I've already given the disclaimer on the databases. No, we want to modify our connection strings. I'm going to take use this connection string at runtime and then I'm going to make some modifications here. So first of the server is no longer local db because, OK, DB is pretty much local. Tow your machine or whatever development machine you are using. As you could see, we could just flip over to it through visual studio in ah, production sitting. Your database may be on the same server as the Web application or it may be in another server, Um, somewhere else on the network. So you want to put in the server names? A nice, quick way to know the server name would be toe may be asking db a or your S a T B. A. Being database administrator is a being system administrator. Or, um, if you have the access, you can just go over to the server. So in my situation, my server will be or my database server will be on the same server as my Web server Or all right, so you have the Web server and the database server. Sometimes one is machine. A one is machine Be. Sometimes they're both machine. In my scenario, they're both machine A. So I'm I just went to the management studio, brought up the the SQL Monitor and Students Area, brought off the connection on then looking here, I see server name, and this is the name I need to put in. So that's the name off the machine with a backslash on. Then the name off the instance. So this may very because you might not be using SQL experiencing might be using maybe developer or enterprise, And so local host would probably be good enough for you or that local host I p address that we looked at. When we're sitting up, I I s, um in another situation, you might have a named incense. The point is, if you know, if you already know where to bowl you can find like this. If you don't, then you may want to seek assistance from your administrators. All right, someone to copy this server name because that is the server that I'm going to be deploying the data beast on. All right, So remember, this was a court first scenario the court will informed the data for the database. So that is where my data base would be set up. So I'm just going to copy this server name, then go back to visual studio and then inside off the parts between the equal sign after the word server and the semi colon, I'm going to put SQL backslash SQL Express. So that's my server. Alright, So server equals SQL Express on then the database somewhere to change a word database initial as i n i t I a l space catalogue see 80 a elegy. So I'm just spending it all to make sure we get the right spelling air on. Then we don't have to change anything else. No. On important thing to note is that some persons, my settle dedicated and very specific database related users, right, So that's one point of security. So on the In this scenario, the Windows user will be executing the application and as a result, it needs to also have executing writes on the database. In another setting, what people do is they create database users specifically for the application on Then you, the developer would have to include them in the connection strings to see that when you are running this application in time, me, too, connected a database that's your server on. Then you would have toe add user space I d equals on then whatever the user name is and we just write using name as a placeholder on, then semi colon, and then password equals whatever the password would be. An incident. Colon right? So that's what would have to be near connection string to facilitate an SQL user that has been created for your application added benefits off. That would be that, well, it's an SQL user, so that person has no domain access to anything on the network are not user. Syria has no domain access anything on the network Onda. Also, it would have access toe only that database that somebody got those credentials. They couldn't do much more damage than probably against the one application. So, you know, that's just under the security tidbit. But in my scenario, I'll just be using my system user to execute my application as well as do database operations. So once again, you want to modify this default connection and say, use this connection at runtime. So even though where the local db for local development. When we publish, this is what our connection string should look like. I'm also going to expand the Entity Framework Migration section on Dennis's apply this migration published on I'm just going to go ahead on and copy all off this control inside off the condition String control, see tick apply migration published on peace. All right, so what would happen is that the when you publish it will seek all the database in the connection string and then try to update it are rollouts updates. He will also generates the scripts for you so we'll actually have a little manual work where we're going to generate use the migration scripts that have been generated. That's how you know the history of everything that we've done throughout the duration off this project on. Then we will publish that on. Then we will see what happens. So enough about all off that after we set up all of the settings, we can click, save on, then create the profile or once of profile created. Whenever we're ready to publish, we just go ahead and click. Publish. All right, And then once that is done, they'll give us a direct link to the plastic in this. Hold on control and click this and it will launch the explorer. Follow with all of four published files. No, um, this is still on your machine. So we want to do is transported toe or destination. The quickest and easiest way to make sure we get all of us for me would be to just select. All right, click on at the archive. No, I have winter on my local machine, but the destination might not have with rocks on which is a generic. That zip extension on. Go ahead on archive all the files on Once that process is done, I can go ahead and grab that archive. Copy. Go over to my server on then. Peace. No, I'm already in the root full of four. My websites rights to call the index file. I'm already there. You may not have permissions to paste directly here. Right. So let me see if I do. Andi, If I do, then I do find. But if you don't, then I would advise a probably go to light documents and then paste the file there on. Then you move the file from documents to the root for that, because once again, permissions and so on. If you're not the system administrator, I have no control over those things. I'm just giving you the worker owned so that you don't have to be going to the system administrator every time you hit a roadblock. All right, so once you successfully moved the zip file to your route fall or leave management folder the website folder on as you can. No right click on just extract everything here on. I just go ahead and extract. That shouldn't take very long, Onda. Well, it went into a sub folder, Senator. Smooth them out. I don't want them in the support. I want them in the main folder. I want the matter route off this sport. There we go. Set us wanting to publish Control A control ex coming back. Control V using keyboard shortcuts got down a lot, so no, we have our files over here and he can take some time and just look through. You see all the deals, all of the reference files that would have added along the way we have a web conflict file on this Web conflict file allows us to configure loud, so I'm just going to go to a web config edit with more part plus plus on. Then this is something I like to do because sometimes you get errors on they don't tell the full story. Logs will tell you exactly what happened, right? So when we do this so we're just going to change this to true and save all right? Eso There are a few things that we need to do. One I need to make sure I have the database. So let me go back to the folder on then we can look inside off this folder E f ask your scripts and if I open this in notepad plus plus just quickly you see that it has on SQL it has the SQL scripts to generate off our tables. Right? And if you look closely, you see that you have the migration ideas. So each migration file that was generated in visual studio manifest itself in terms off on SQL statement to say these are changes that should happen right up onto the very last one. So I'm looking through here on day I would have inadvertently created are included the vert . The view models in my data sets DB sets, right? So, no, I have some VM tables, so I don't know if you detected it. I got feedback ability. Probably detected it on, fixed it already. I didn't. So this would be a good X experiment. No. For me to go back, fix them in the court, update the database, get the latest migration file and republish. But let's see where all of this will take so I can actually take this entire file. All right, on then I can go to my database server, right? So once again, did Toby a server? What? It's on the same machine are on another machine. You just want to log in on. Then I'm going to create a new database on going to call it leave on the score management because that's the database that our application is the connection string is looking for, right? Leave underscore management or key. So this work once again, your DB might do it. You might not have access like this, so But you know, you you probably would have to instruct him or her what? As to what they need to do. So I'm just giving you the clear cut instructions. So after you do that, you want to start up a new query with the leave management as the context off the query You based the F strips, right? And then you can go ahead and click Execute. Now, once that is done and it is done successfully, if you just stick, I look inside off the tables, you see all of the table. So here are some of the VM tables that I inadvertently included in this whole thing, but you look at it and it has the same structure as what you would have seen in the local DB. Um, set up. Right. So next up, we need to get our up working. All right, so in my bro's, I'm going to go ahead and trend bro's toe the address. Leave management that internet dot com and we see here we're getting this http pair of 500 right? So a number of things could be wrong this ever come on era. Now, the first thing that I would want to do is look at the logs. No, as you see there, no lot. So let me just I'm just throwing everything hurt. So back in the Web config where we enabled the log, it showed us that the old file would have been toe long slash STD haute. When we look in that folder, we don't see any log fire here. No, The first thing that's going to come to me is that there's a permissions issue, because if there is a permissions issue, where or if there's a situation where it should be writing a lot file and it hasn't written it, then chances are that whatever users executing didn't have the permission to modify this folder. All right, soul. I'm going to go about the IIS on. I'm going to look in my application pools on. Then I'm going to observe that the identity and I think I mentioned is before is application pool identity. No, your system administrator might need to modify the permissions off this user. I'm in charge here on my own system, administrating this situation, so I'm going to go ahead on Goto advanced settings on. Then I can select the identity. So by clicking identity and then the ellipses beside it, I can go to building our cones. And then when I dropped on. I'm seeing that. I have some other accounts, right? Some probably more powerful accounts. No, this is a very sensitive situation when it comes to security. So make sure that you were on this by your security administrator. However, this is my machine. I can do what I want. All right. So I'm going to tell it to run as local system. So I do that and click OK on, then. So local system no is a more powerful user than the default identity user. All right, And then I can just recycle just to make sure on, Then, if I go back on refresh, then Okay, I'm still getting that 500 error. But guess what? At least I'm seeing the logs folder. Alright. So unheard on. Another one to go. So that's why you see, it's an entirely different error. But I'm still getting the same. Http. 500 era, And this is literally all the help that Microsoft is giving you. And they're telling you, just check the Louds because it should tell the story. However, the first time there was no lock to check, right? So I'm just bringing it through some scenarios to help easier p and when you have to troubleshoot. So I'm just going to look into this log file and see what's happening on it is seeing that there was an arrow trying to connect to the database on the server, right? So we see that it's trying to connect to the cork server is trying to connect to the right database for that. It's telling me that it cannot open database requested by log in right on the logging field . So that's telling me that when I see in that work group slash SQL, that's the user is trying to use the log in. So you got a little system administrator training? No, we're going to look at some database administrator training. So going back to the data beast, What would have to happen is that whatever user is executing the application, meaning the user that we just set govern the application pool. Whatever identities there, that identity also needs toe have access to the database. So I did mention earlier that sometimes you set up a database user so you wouldn't have to worry a boat which identities executing you just use the database user in the connection string on that database user should have access to do everything, and you're good to go. However, in my scenario, I'm not using a database user using local systems have to make sure that the local system has access to the database. So then this these steps would oh neato happen regardless off the techniques. So I mean, creating a user is easy enough. I can just goto security so on the server, but the security click new log in. If you're creating a database using can just say, you know, admin or leave money's leave management use or whatever it is, give the sq user authentication to give the password. You probably don't want to enforce experience Shin all rights because you don't want the posturing expiring on that user on. You can enforce a policy to make sure you get a strong password. Right. But the common parts after you do all of this the common part that you know whatever user it is have has is that you have to go. So the database drill don't goto security. You're right. Click on over. Sorry you drilled on going to users, then you right click New user and then you can see a user with sq a log in or Windows User . All right on then. So that's one way to do it. Another way to do it would be to just find the users, in this case, anti authority backslaps system. That is the user that I selected when I said local system. All right, so I'm going to right click my user so you could have easily just right clicks that I'd mean use it that you just created, right, Right click, go to properties and then we're going to go toe, uh, user mapping on. Then we're going to select the database A C here. Anti system has no access to any off the databases, right? Andi? It's quite likely that whatever user you're using by default, it has no access to any off these databases either. Someone toe stick the leave management database and you see it says the user, is whatever it is on. Then I'm going to sit as DB owner because as the owner, you'll be able to read, write on everything. But obviously it's very poor, fully probably can get a bit more granular, but usually Billy owner is powerful enough to not have to worry about anything else on. Then you click. OK? And then once he's owner, he should be able to connect. So we're going to go again some winter. Refresh on, then. Here we go. We're now launching our application, and it looks good. Off course. You can use a little fixing off, but, hey, so I can go ahead and try to log in. So remember that we see that the admin user from the beginning. So that means once application launches, we have an empty database. It's it's has nothing from or development escapade. So indirectly can Goto s peanut users. We should see over default admin user there. All right, looking good. So I can go ahead and say admin at local host of calm and our default password as it were on down. We are in our applications. So from here, I can go to leave types on. I'm just going to go ahead and create a new leaf type, so no, it's first on the system. We have a little bit thr and say, hey, hr or you know, whoever please go ahead and start setting off the system. All right, so they can go in and start creating. So they're going to say sick leave gets 10 days for a year on. Then we create on. There we go. If we edit this on, I'm just going to do with some quick crow just to make sure that we see that it's working on. Duh. If I'm not satisfied, I can always delete on We're back toe Nothing. Right? So here we just deployed our application on the Internet directly. No, back in visual studio, I did say that I wanted to make some changes to the database. I'm just going to make sure that I don't have the illegal DB sets. All right, so they're not there. Right? So what happened was that, um I would have had DB sets leave type V m Right on then. That's generated the table. Leave types VM believe or leaf that gm's whatever it was. Those are I don't I don't want those. Right. So this is it. I'm going to run a new my agree shun. Alright. Some saying removed VM tables, all right? And that is done. And I just brought up my database view just to show that, you know, the VM czar. There's who have the employees VM on the leaf type via But I'm going to do an update database. So at the end off this update database, I would have updated my local databases. And if we look at the my Grayson, um, scripts, you see that we're dropping some of the tables and probably some feels. But that is what are opiates is supposed to do on. I can just validate. I can just refresh, go back and look and see their no vm tables. All right, so looking good. Now I'm going to publish again. So, you know, we mean, whatever changed, you know, you give it to HR. They said, you know, you need to adjust this in. It's just that we just go ahead on right click or project again, Go to publish on. We already have our profile. So once again, this folder published technique. I mean, over time it might get tedious, and they do have more automated with off doing this. But once again, this is the safest version for me. Even my past experience where I inadvertently removed some important files. So I just always published locally on then move across the network. All right, fellas are published, and I'm just going to once again archive them Onda a copy across the network. And then here's the tricky part. So, you know, um, what I have done in the past is whatever is there already I would probably just take a back up. So it's a like new folder on then maybe right on the dates, right? And then put all of those old files inside off that dated folders early sandal, that on this date, that was the last set off as I had. So I can always roll back its you know, they're they're more efficient ways to do this once again. But then in that's in a perfect world, you might not always be some just closing some facts that it's seeing can't move because they're open. So, you know, once again, in a perfect world, there are more efficient ways, but in an in perfect where you just have to know how to get the road right. So I'm teaching you the in perfect way so that when you get the perfectly, you'll be a bitter expert. So I just archived the last version. Ah, No, I'm just stopping over the new version on. Then I'll extract all but I'm just going to change the past here so that I don't send it over to the sub folder on. Then go ahead and extract andare. Files are extracted. We have our new into different words scripts, so I can just right click edit with no part. So if you look at if you look close Saleh scripts, if you are familiar with SQL already, then you know you would be able to see that it says, if not exists. Andi. So it's saying that if there is no history or if this doesn't exist already, then do this. So what happens is that it will only do the migrations are the changes that are not yet in the system, right? So, like we just added a migration about removing the VM tables. There we go. So when I take this whole script and executed against existing database one, the only way we're going to lose the it is if we did some changes, the columns and stuff like that, like maybe a changed the time from the time Sorry D created from being time to eat. Then you know there's going to be detail us and possibly corruption, Right? So whatever corruption Yudof experience during the development stage, making those kind of changes, expect that from your worst at the database. So they want to be careful whole year rolling all these migrations and the changes you make . So, in my situation, what I did was dropped some tables. So if those tables had pertinent information, this migration would say, dropped them. That would lead to loss off data either where I went to copy all of this. Andi, go over to my rescue. Well, management studio on going to Bay City inside off the query window. Make sure I have my data be selected. Click Execute on then it basically said one rule affected. Okay, when I refresh, then you will see that it made the changes. All right, so they're no longer in a VM table so that so you can roll out changes against the database also. All right, Onda. Well, I think I had only the users because they deleted the leaf type. But, you see, I still have my user data right on stuff, so it's always a good idea toe. You know, make sure that the script is run to make sure the database is up to date with your with your new publish. He also after you deploy new files, wanted at least recycle your application pool, so it, you know, refreshes itself. Andi starts pulling the first files on, then I'll just go back on bond. Refresh andare application is still open running. So once again, that s so you would have deployed an application to your local network in an Internet sitting. Um, but then this could also apply to a public setting because this server could have been like a VPs server that you're using to broadcast the Internets. The principles, I mean fairly the same with the database connectivity setting up eyes, making sure you have the hosting bundle installed on making sure that permissions are set up, Um, in a way that your application can execute against the machine as well as the databases in a clean and efficient manner.
67. Create Microsoft Azure Account: Hey, guys in this video will be creating or Microsoft as Europe cones. Like I said earlier, we can get started for free to get to this websites. We goto as you're not Microsoft dot com on. Then I guess they wrote you according to your reason or your language. But this is what the website looks. Are should look like and you can read through to see exactly what as there is all a boat, it's a bill being futuristic, allowing more collaboration on operating more seamlessly in a clothes space they're all over the world on. You usually would just choose the reason that is closest to you. So I'm actually in the car would be in reason. So my closest region is east us, our east us to but that that's not for this video. This video we're just creating their cones were not setting up anything about regions just yet. Eso to get started. We can just Well, if you have a live account already, then you can just go ahead and standing with that live account. Well, you can just click start free on here. They tell you that you can create a freak on today and you can get started with 12 months off free services, so that's a good deal to me. And if you scroll down, you see 12 months off free, popular free services plus $200 credit, which will expire in 30 days. So they give it $200 sake and create the virtual machines that can create resource is in the code and experiment until that money's up on, that's really just for one month. But then there are certain services that you just get four free for the rest off the year aren't and then you will have a few other services that are always free for it. So what we're going to do is just go ahead and click, start free on. Then they'll ask us to sign in with our live accounts. If you have a live account once again, you can go ahead and use that. If you don't have enough cones, then you can go ahead and create one on. This is a very recent option to sign in with get Hub. So I have a live a call that I used, but I'm just going to walk you through the create one first. No, the live a corn doesn't necessarily have to be at live or at all. Look, tachometer is I have to be, ah, traditional hot meal account. It can be a G. Millikan, so I can actually use maybe the same email address I used or ghetto board by the militarised that I use when I'm signing up for things. I can use that with these. Yeah, huji meal, hot meal, whatever it is. I'm just like next, and here it's already. It's telling me that I already have a Microsoft account. So that's just driving my point, though, that once you have an account on email address, it doesn't have to be, ah, hot meal or traditional live a calm boat there. Dis creating a Microsoft account for you with that email letters so you can go ahead. Andi, sign up. It's a pretty straightforward process now. Their conduct this it already existed. That's on account I was using to sign up for the free a cone, so I actually just went ahead and love being on, and because I really didn't set up much more, I think that your registration process is actually going to look very similar to this regardless. So once you get over the hurdle of putting in your email address on proceeding, then you're probably going to end up on a screen like this where you're going to be asked for your demographic information just for the record keeping, Um, my country and region is Jamaica on. I'm putting in my phone number than I treat next on. Then they said, Do you want a verifier? Added insisted by phone. Or do you want by card art? Someone to choose takes me by phone and I just got the text. It didn't take long at all, so I'm just going toe. Put in that chord on, then verify. Now here's a part that might deter you if you're not prepared for it. They will want to verify your identity by card so you won't be charged unless you upgrade, meaning they have different way. Call subscription plans so right? No, you're signing off for the free subscription plan. Once that free subscription plan is done, then you won't be ableto do much on the platform until you center for a new subscription plan. Which Cones has that upgrade? So, like I said, earlier. There is P as you go and then there's pay as you go have slash test, which is the one I'm on, which is like half the price off the regular P as you go. So I actually provided my card information when I signed up on by. Having done that, you can click next and take agreement if you don't have a card or you're not comfortable with providing your car details than you mean you can stop here. That's fine. Later on, when we're actually deploying toe as jury can still see what it will look like and see how beneficial it is to you. Um, but if you wish, then you can go ahead and provide your information on. Then stick on the agreement and accept the agreement terms on. Then you would be in on the platform. So I'm just going to sign into my real account, my quote unquote real icon, the one that I use on show you what as your looks like. Well, actually, I just stepped in portal dot as your dot com, hoping that he would ask him to log in. But I did that. Andi just rerouted, musing the same account that I was just setting up toward Williams at gmail dot com toe this dashboard. So this is the as your dashboard. At the very basic level. They have a panel to the side here listing order. Quite a few services that you can get. But then because we didn't complete a set up or because I didn't complete the set up, at least then when I go to subscriptions, I'm going to see that I have no subscription, right? So, like I was seeing the subscription is hold the re to as a customer with the Europeans, You go enterprise are are whatever. So if I later on decide that I want to provide my information, I can just come back and click. Add on, then that will bring me toe complete the sign off procedure where I actually had the subscription. So this is a free trial on that were sitting up. Just know you have pay as you go. You have developer support. Yeah, as you have quite a few off them. All right. So I would probably go with pay as you go, but that that's this is all in the in the steps off, signing up for as you're on. That is, if you wish to proceed with that. Um but then for this detour, really and truly, I just wanted you to get as far as the dashboard so that you can see that this is what a zero looks like. This is so your crowd management portal. You can set up your virtual machines, but for this course will be looking at up services.
68. Publish to Azure App & SQL Services: Hey, guys, Welcome back. We're going to continue learning about Microsoft Azure on the hosting Web application on it . So you would have already set up your account on. Do you probably are seeing. You probably are not seeing what I'm seeing right now, but this is my account. So this is my paid a cones. That my credit card information. I'm on the subscription for pay as you go slash dev test. All right, so basically that one. Andi, I just found it quickly. This one, Al Ozio. It spares. You could have slashed its Sorry. So this one, um it's very It's much cheaper than the regular pay as you go on. The premise behind it is that, you know, you just want to test things you're developing. You don't want to pay the full money for for these services. So they kind of slash certain prices for you. Andi, it's a bit more flexible for an individual to get by with parents. They can always just go ahead and click. Activate, and then you go through some, you know, coat uncle paperwork on. Then they activate you as the dev slash test environments, right? No, back to here we have all services. You can get virtual machines, up services, SQL databases and the tool that were very, very interested in would be the up services and the SQL databases. Virtual machines. You can have virtual machines. Um, but then, you know, if you're deploying toe as your depending on the model that you have or you want, you may want to deploy it a virtual machine that sperm they already kind of enclosed in your VP and and your entire company's network. And that's probably for insurance purposes or your deployment of virtual machine that will be public facing. So you have your own hosting. He set up a virtual machine he got here. There don't mean and put it to the public. I pee on the virtual machine. Andi, that's broadcasting to the Internet, and you're in charge off that, or you don't want the hassle of having to set up eyes and set up a virtual machine. You just want to build up, put it on a zero and be able to access it over the Internet. Then maybe the up service is best for you. Onda SQL database service So that's what we're going to be exploring Andi, so I'm just going to minimize this angle back to visual studio on. Then I have up my published profile, So this published profile is my father profile. This is what I used when I was doing it locally. But now we want to have a profile that pushes us to the up services in the cloud. So I'm just going to go ahead and click New on. They were going to select create new up service so up services selected and create news already selected on. I'll just go to advanced because I'm sure there are things here that I need to configure, so I don't need to set up the release we have published options on you can remove addition off the destination that's file databases on data context being discovered. But we don't have to change anything here, so you can just go ahead and click, create profile on. Then it will lead it to a point where it's asking you toe sign into your as your so unity that create one or sign in. So I really have a sign in some distant a select sign in on then this is a straightforward signing. So you just go ahead and put in your as your cones on. Once you've done that, some new options open up for you. So it may take a while because, you know, it's connecting. It's going to the cloud. I mean, you know, But, you know, I don't have to pick our own. We can just wait to tell to fear in the wrong you issue an error message. But once you're seeing something like this, you know you're in the right place, so they're asking you to give it a name. You can change that if you want. What subscription would you like to publish under, Um, what is the resource group? So based on my location, I would choose I have a resource group. What? So you can always create a new one? I think that they would give you one either way so we can create a new one on give itto Resource group somewhere to call it leave management on resource groups are like containers in the CLO to say, like all of these resource is in this resource group kind of work together, right? That's basically what a resource group is. So just like a group name. So I'm calling it Leave management the hosting plan? No, they do have a free hosting plan. So if you look at size, you see that these are the different sizes, but they do have free. So for educational purposes, we're going to select free if you are. Actually, we're looking to go public with something. You probably want to select one off these, um and then based on your traffic, you can scale up our don't off course in an enterprise sitting, you know, you would after the is with your I t manager, Just which one. But I'm going to go with free the location, always trying to choose a location that is close toe you. So based on my location east us, our east years to his best for me, right? Because being the Caribbean, that is the one that is usually recommended on this is a very stable location at the way on the hosting plan, I don't have to change anything there. So these names here, like hosting plan in the name off the up you change those according to your style, your convention. You don't have to use the default, but you don't have to change the default right then I click OK on, then additional services. So I do need additional services in the form of SQL Database because the up services on one side on literally all it's doing is hosting the Web application. There is no database that is going to be on the up service. I need a day. It'll be a service. The horse, my database. So this one costs, though I don't think that there's a free version for the database, but then database name. You can give it the name I believe. Well, this is really the art. Leave on the score management. So we're going to give you the same name. Leave on the score management. We need a server. So the database service is like you create a virtual server, and then you can have served databases on the dis server port. The reality is that your you don't have to go in and administrated the same way you do when you install it on your machine, right? Some went out to create a new server because I don't have any under my current subscription , someone to create a new server and then they're asking what is the server name? All right, so my server name I'm just going to call it, um SQL Server. Dash my name. Right. So this is a server. The location. I'm putting it toe east us once again. Onda after put in using human password Onda user name can't be generic like, admit our administrators. I'm just using my first name Right on. Then I'm just using the default password, which is p at San ssw. Already won the same posture that we've been using throughout application. But, you know, you want to use your proper password. So offers this step is if there is no server existing, safer doing with a company that already has an as your account. You probably don't have to go through this step as an individual. You probably do. So this is this is the server, right? So I'm just going to provision the server on then once the server is provisioned, knowing when to make sure that my database name is leave on the score management. In keeping with the database name we've been using all this time, it will fill in the details they're using in the password on the connection String name is default connection. So it's like it saying I know that I should override the existing connection called before connection, which right now is looking at a local BB, as at this point, will start looking at the new server with the credentials needed. Right, So click OK, aan den. So to the bottom, right. It shows you that it is setting up the desk. UAL the as your SQL database. Leave managements on the server that were just provisioning using this hosting plan with that up service. All right, on. We really don't need anything else. You can. I mean, the analytics application insides, which will give you real time log zest. What's happening? You can add that I think that you might cost somewhere money. So I'm trying to reduce costs as much as possible. But then you can go ahead and click create. So once you click, created will start provisioning. All of the resource is needed so they can give it a little time. All right. And then once that exercises don't we will get a site. Where else? Oh, this waas the deforming that we left for the upf. You see, that was up name. I didn't changed from the default, so I hope you didn't fall on my butt. Example on that you change years. Either way, when we click the link into a leaders toe this landing page so it's letting us know that the observer is open running on. Then the next step is to deploy over court. Right, So we need to go ahead and click publish. So by clicking publish, it will package off the dependence is and push them their kids up service for us. So after published, we're getting our 500 errors. So that just tells me that there certain things wrong, No certain things to note would be that we don't have access to any fire system to go and look at the logs like we did the last time when we're in, I s if I go over toe as you're on looking up services that I will see my up service here and it is running. I can take it. So when we select it, we are looking at our up service and all off the diagnostics running on it. We can take a look at the configuration that was shows that the continent fiqh string. So I suspect that the show understand Advanced it on. I just suspect that the arrow is somewhere here. So this is what our default connection No looks like, right, Onda, We can get details as the whole week and connect store server. So it's looking for the initial catalogue. Leave management Trans log in with that user Andi with that password. But I am suspecting that this database just does not exist on the server leading to over 500 earth. So I'm going to try and get to that database. Justo, see if my suspicion is cart are nuts. So what I'm going to do is try to come into the server and I'm going to use a school server Dash. True that What? This whole address as the server name. Right. Be the source on. Then I'm going to use this user. I d on that posture. Soon you just spring up my management studio. So at the point of publishing, you're probably going toe. You know, if you're doing it on your own, you're going to have to get usedto knowing all of these moving parts and appreciating how they work together. So I'm going to copy that. And that is my server name Andi. I can tell you off the but that as your would have restricted the I p addresses that Chan fun it to the database. So I think that when I tried to connect is either went to deny me or let me know that I may have permission. So I click Connect. There we go. Your client i p address does not have access to the server. Sign in on create a new firewall rules so I can sign in here, create a firewall rule for this public idea dress that I have. But the reality is that based on the I S P that I p address my change. So what I'm going to do instead is go back toe as your on going to go over toe my database server. So I might just go back to all services on that. I went to bring up my SQL databases on If you're not quite seeing things the way I am seeing them, you can always use the pills. So the left and you'll see all the services listed there. C c SQL databases up services just the same way. All right, so I'm goingto go ahead, click the server. So Well, this is actually the data bees. All right, so the database does exist. Andi, I'm going to from the overview Goto Ah, server. So this is the database itself. But I want to go to the server because I want to free up some off the firewall rules, so I'm going to be very loose on them. We're just going toe. Hello? All I p's right. So I can go down toe firewalls and virtual networks on. Then what I'm going to do is configure rule. So you see, it is denying public network access. No, on. Then you can see a low services to access the server. Yes or no. But then the i p. I'm going to say all for the rule name, and then I'm just going to put in a full read. So that 0.0 so 0.0 dot 0.0 meaning from any i p address. Still the biggest one from the smallest, it's a 255.55 that 255 So this is ever reach every I P address that is conceivable, at least right now falls between zeroes onto five fives. So we can just go ahead and save that. And once that rule is in, I should be able to try and connect again on actually get access. There we go. So we see here that we can drill down into the database and I'm seeing leave management believe management has no tables, so the database is created, but it stabilised. All right, so we're going to take a little step back. We've made good progress. We see that we provisioned, or as Europe service we have, or as your database. But we have a little easy with the date of bees and the contents off the database. So I'm going to take a step back, and we're going to change some configurations here in our hood or local projects so that the next time we publish, we won't have certain disadvantages again. All right, so the first thing I'm going to do is modify my upsetting. Is that GS on file and I'm actually going toe create another connection string. So this is default connection. I'm going to call this one as your connection. All right, so for here, we're going to be using the connection string on the connection string will be using will be in our port. Also go back to the database. So leave management on. We'll see connection strings there. So taking connection strings brings up the ideal .net driver. All right, so we can just stay this text, understand? To copy. That's a clipboard on. Then I'll go back to my upsetting. Is that Jason on my A zero connection string is going to be that string. All right, so I'm just replacing it on the password was not their employees in text. So you have to put that in. All right, On the Yeah. Just making sure everything is okay. All right. Good. All right. So that is our connection String toe azure. When to modify the start of Nazi s to make it a bit more selective. So right now, it's saying that when the application starts up, it should use the connection string D for connection, and that's fine. That's why we're local. But then I'm going to both of this a bit on. I'm going to see a son was going to cut this and I want to see if and we have a variable here called Environment. And to use environment, you have to include system safe environments dot get environment variable on, then inside off that we just have the quotation marks and work on the ISS be net core on the score environment. So I'll also explain what all of this means. So I get in the variable and we're seeing Does it have the value on We're looking for the value pro milk son. All right, so if we're in the production environment that we want to use one thing else, we want to use something else, and I'm going to put back the court that we just caught in the l section. So if we're not in production and we're using over before loca settings, But then if we are in production that I don't want to use default click connection, I want to use my A zero connection. So you see, um, as your connection for our production. All right on then, after that, I'm going to put one more line to say services. Sorry, services dot Build service provider on. Then I want to say that get service on, then get service. Embassy in the application db context. All right, take old traditional spaces on, then open and close Quotation marks, dots. And I think I have on air OFI guess that. And then we see theater basis dots my grades. So this line off court should execute the migration against whichever contexts are, you know, databases able to be used. Now, let's focus on this environment variable. All right, So when we talk about environment variables and you see, I have about filled Explorer here so you can use the code experts of connect, um, to certain objects, but then they all kind off leading back to the port of its Understand to close this on. Then I'm going toe, um, right click on the project. Go to properties on then. The first age has environment variables on their UCSB net core environment. So that was the name we typed, right? SB net core on the score environment on the value that we're looking for its production. However, the value here is developments understand? Toe paste right there. So I'm changing into production, all right. And from here you can have other environment variables as you me need. But then I'm just going to run a test here, so I'm just gonna run locally, All right? Andi Art. So what this test is going to prove is that our migration just happened against the as your SQL database. So we just looked at as their SQL database you saw that it was empty. All right, on what we did was to structure on the environment. Variable to production will also introduce a new connections through which they use as your connection on in the start up. We said that Well, once you're starting up, then please execute the migrations against our from application db context, which would obviously be against whichever connection string is selected. So since my environment variable is no set to production, the premise is that once I click start, the application will boot up locally, but it will connect to the clothes SQL Server on the fact that art So we we pass one hurdle with it actually appearing on day. I'm going to. So here's our up thrilling locally. So that's good. So far, I'm going to go back to my management studio and refresh on there. You see? All off the tables that were not there before. So this is our as your SQL server. I know all the tables aren't there. So that configuration is basically ensuring that once we do a publish on the application is about to run, it will make sure to do the migration toe the destination data bees like. Well, it wasn't doing it initially, right? So know that I have that little her lot off the way. And no, I know that my database exists. Yes, we are able to connect with using the application. Yes. I am going to just do another publish just to make sure that everything is OK. Now, once we publish again, we will see our log in screen coming up and based on previous experience, it's always a good thing to see over log in screen so I can just try and log in Andi, ensure that it is talking to the courts database and everything on then I sign in. Then we see that our admin user works. All right, so I'm just Internet tests just to make sure that we're talking to the right database, just, you know, coverall basis. I went to go to leave types on. I'm going to create a new record on this one is going to be sick. Leave Onda 10 days. Go ahead to create Alright, it's created. So I'm just going to go back to my management studio. I'm going to select star from leave type. So this is the SQL server in the clothes. Just been to select top 1000 Onda Uh, there we go. Sick leave is there Created All right, so we just deployed our SP donna core application toe as your This is not as your training . This is just to get you through. Um it may have had its, you know to sen turns, but it's just a matter of configurations and an understanding hold the little things work together to give you the end result off hosted application talking toe. Ah hosted database. Everything is easy, Nazir. We looked at how we can connect to the as your instance off the database regardless using our management studio on. We also see that we can do it from our visual studio using or Flowed Explorer. If I go to view, you should see Code Explorer. There we go and you can see your your resource is that are in the code just the same way. Um, we also looked at Toto Auto, meet the seeding off the database are not seeing the migration off the database using this line in our start about CS, which just, you know, just forward engineers the date of this based on all the migrations, that's where there on We also looked at the fun. We can have multiple connection strings and using an environment variable, we can, you know at runtime determine which one we want to use. So if it is that I want to start using the development one again, I can just go back into the property's right click, go to properties on then From there, I can change the environment variable from production back to development or whatever it is that I wanted to be at that point in time
69. Setup Automated Build/Release Pipeline using GitHub and Azure DevOps: Hey guys, Welcome back at this point were battle hardened developers, and we've dipped our toes in the pool off a little server administration and IT database administration. But I'm sure we've done enough to settle or server on our local machine as well as our database. Or we have deployed to the code and we have or zero it up service running alongside over SQL service running. No, I may have alluded toe on a number of occasions, especially when we were talking about that IIs deployment, that there is actually a much more seamless way to do it. Then you know, publishing and then taking it and copy in Toto the server and so on on. The reality is that we just might not have that kind off access to all of these machines. If you're a senior developer, you probably really don't want to develop us to have to go through that each time. But you want a more seamless way to make sure that it's quality called that is being published each time. So we had been using get home as our source control provider on Get Hope does provide what they call actions that you know, put in some build actions and automation, some amount of it into dot net core ab sport. In my opinion and experience, ghetto is more geared towards Lord and by fun things not necessarily document things, but Microsoft has as your develops, which gives us access to a number off tools that are amazing. Um, for automating building on publishing dot net applications so you can get here by going toe . Zero dot Microsoft dot com On go to products, services and as your dev ups and you can see you can start free, start for you with get top so you can send in with your ghetto account. But if at this point you already signed up with Microsoft Azure, then you can go ahead and use the life account toe register on this site or well, you technically would already have on our phones on. Once again, you can start free as an individual. It is great. It's like get a job, but with a little more to it because they have the TFS engine. If you've ever used Team foundation server. If not, that's fine. It's just a really powerful tool that they had for years on. They reported it to the Web on. They give you all of those a job planning tools. See, I see the Seo is here, CIA and see, that's continuous integration or continuous development on sorry deployments, Right. All of those tools are built in. You can have as many repose free as you want. What they will be private gets up gives you as many free public ones. I think no, the private ones are free. Also, he can deploy test plans. If you do unit testing artifacts you can be deployed on, they can automate that whole what we call release pipeline. So that's what we're going to be doing. We're going to be exploring doing a release pipeline on top, off the the application or the website that we already built. All right? No, I'm switched over to the Web server. And just as a quick reminder, we have our website deployed to our with our application deployed toe over I I i s website called leave Management on. We get through the address, leave management that internet dot com on justo refresh ourselves on the as configuration, we have the application pool dedicated to the Web application on. We also have the website leave management. So No, What we need to do is set up a release pipeline. Such that are not This is a server. This could be a server on your local machine. Are once again it could be the clothes, but it is a dedicated server on it is hosting our application. No, we're going to do is set up a release by a plan from a zero develops which is in the cloud such that when we, you know, build something. Maybe you have both fix and we check it in. It does an automatic build. Make sure make sure that we didn't break anything on. Then it will automatically do the deployments. So I'm going to do it manually on then we're going to look at how we can automate it are based on, like a a nightly build schedule or a nightly release schedule so that, you know, you do the both fix today you vet it on. Then by tomorrow morning it's in the system without you having to do much more so once again, to get started, you can sign in with your as your contrary alive account or you can just continue with their ghetto account. So since we've been using get up, I'm going to go ahead with the ghetto back on. I'm going to be using my as your cones, but mine is already set up and it's been in use. I'm going to just do this from the basics so that we're in this particular struggle together. So I'm just using my ghetto account. I go ahead and sign in on. Then it's going to let me know that I already have an account. I just continue on down. It's going to just confirm that I want to link my credentials on Dennis editing me. Know that my credentials have been added to the market. The get off credentials have been added to my Microsoft account next time I signed and I can choose to use the existing Microsoft co sponsored or just signing like I'm sending in to get hope. So I don't say got it and move along all right, and I just had to provide a few more details and click next, and there I am. I'm inside my as your develop. So I had a student already who one summer I did me to his organization for a project that he did really good project also. But that is why I'm seeing that there. So you might not see it. What you want to do is go and click New organization on then organization is like creating a T. Right. So you just want to do that? We can opt in. Ah wrote off getting promotional, um, articles from them. You choose your you're using them. Some dissented with my beasts. Use the name and I'm going toe put my projects to be hosted in. Well, central us is the only Well, that's the best one for me. So I leave the central us, but they're letting me know that it's already taken, so probably just add something to it and continue. All right. And then we're here in our organization. So the organization's name is Trevor Williams one? No. From here, I'm going to have to create a project name. So the project name is leave management, and I'm going to name it. The same thing is called on. Get off leave Dash Management. I can choose what I wanted to be public or private, so I want to leave this oneness, Private andan, I'll go ahead and creates project on. Then we have a fresh project so you can just take a while and look. You see, you have a few more things than get UB shows you at least at face value. If you hover boards you see work. I attempts you can do sprints, backlogs everything here reports show your files your comments. At the end of the day, the words are pretty much the same because this is also using I get engine so get off his based on get as your develops Their primary engine is also get So you're going to see a lot off words on phrases in common between the two. Know what I want to do is link this particulate project to my get top project. Right, So this is an empty project. I don't want Oh, have to go, Andi, start feeling it again. You see, it's empty here, right? So I don't want oh have toe separate projects. I want this project to be linked to the get up project on The great thing about Microsoft owning both is that they made that very possible second Goto project settings on, then select ghetto connections from the menu lcz boards, the secret of connections on. Then they're saying connector, get top occult, someone to go ahead and connect my Collins on because I'm already signed in as get up, it's going toe. Let me know that I just need to authorize that on dime. I'm just going toe until the So Okay, I guess I'll leave that for another time then. So I just go ahead and authorize as your boards on. Then it will do its magic on. Then fetch the entirely stuff All my repositories. So some off these our minds off them. I have been invited toe. But the point is that I have access to all my repositories. So I'm going to go with leave management and then click save on. Then I'm going to have to go ahead and approve and install and authorize again. So all of these checks are Just make sure you know exactly the risks and what you're doing , so you can take time to read if you wish. But I'm just pressing ahead. All right, So know that we've set up this connection. What this allows us to do is kind off, manage our tasks and issues from develops as your develops relative toward get over positive. So it's a powerful connection on what our objective is once again is to set up ah, build pipeline and release fire plan so that when we check in to get hope, it will not, as your dumb also automatically take it. Build it, Andi, you know, vetted before lets it move forward. So from here, what I'm going to do is go over to pipelines that it's a rocket, understand to click it on, then it's Prompting are still create or first pipelines understand to create pipeline on. Then this allows me to select what kind of pipeline would I like? So if the court was residents than I would do on a zero repose get. But if you look inside off as once again, there's nothing there. But the files are over in get hope. So once again create pipeline on. I'm going to be selecting guitar so I choose. Get up on, then is going toe prompt me to select the repository. So I'm just going to select my leave management repository, an interesting provided A that's have the permissions on Then I loaned me to approve once again. All right, I know it's warning me that I'm using a public repository, but this is not a public project. So get off this public. But this is private. So I guess there prompting me to say, Hey, just make sure both off them have the same level of visibility off course in an organization. Off sitting your code Probably it was not probably your cord wouldn't and shouldn't be public. Alright, What? I'm just going to switch this one from private to public just so that I can get that start getting a promise. I just clicked project settings which brought up the project details and I switched it all from private to public on I'll save on so I can continue so I can just take that off. I just did the change. I can take off the warning on DSO I'm going to go ahead and select SB net dot net core and that's going to create what we call y Mellor gmo file. So if you look at the file, it's you notice that you have like, a BCE and then you have, like, dash um on some. It's basically a nice clean configuration file. It's very popular. They use them in doctor. It's hard for me to cannot describe the the layout, but it's a really clean layout on. If you just pay attention, you can see that it's doing certain things at certain steps. So I want to add on one more step to this. We're at the end off all of these tasks, and you can add more tasks. You can add more steps if you want, because if you have, like unit testing to do before, you can approve the build than you want to add in a step to make sure that happens and so on. But I want to add a task where I tell it to publish on artifacts. I just said Dash task colon publish Build artifacts at sign one. All right, so this is basically saying that after you've done a successful build, I want you toe publish this, build our put together the package with that new builder and all the published files, so that would save me the trouble off. Going back to visual studio on, then right clicking and clicking, publish and putting it somewhere. And this and that and the center. Right? So I'm just going toe. Go ahead, Andi, save and run. This said a slick save and run on. Then it's just going to give me a commit message. And I can just say, see, vendor on, once again, going to need a futile create the pipeline. And then once that is in progress, you see that you can go ahead and quit the job on. Then you see the school command prompt so we can sit down and watch the while and you see all the court coming up. But in the meanwhile, actually, I'm going to change the steam cause I don't like the white someone to change this over to the dark field. All right, that's simple. So you just go to the little him being here with the gear on you select theme, and then you can switch the dark theme. All right. So we can give that a few, you see, so it gives you all off the steps that is going through. It's going to run the new get command, get all off. The binaries are the packages that were included in your project along the way to a build Run the unit tests and then publish the artifacts, so we'll just give it a few to finish up on. We'll get a nice indicator once we have a successful build. So if something broke in the court than this step would not have happened, all right, So are we still wouldn't have completed. So the next thing So this is the built, you know, what I want to do is set up a release spire place. I'm going to go over to releases. And then I went to see I want a new pipeline on. Then from here, they will give me a few templates so they'll see what kind of template you want. Do you want the up service deployments? So that means you check in your chord, they do the build, and then they just deployed as you're automatically. Or do you want the I I s website and SQL database deployments in this situation? That's the one we're interested in. Because remember, we want toe ought to meet the publishing from our repository toe our actual VM with our database on die, I s someone to click this one and then click, apply, and then we have some configurations that we have to do. So they're just showing you that, you know, this is the artifact. So remember that we just put in a steptoe, publish artifacts, right? And then this is our These are the stages. All right, So I'm going to click on artifact firstly on, then I can choose to add an artifact based on a build, or I can choose the ad one based on the repository, or choose that one Beeson ghetto. So just choose in the repository, get of means or anything that's checked in. Just call it an artifact. But I don't really want to that I want the build toe happen with any special configurations . Maybe that we put in on then that is going to be the artifact. Only when it's successful should be released. All right, so I'm going toe ad so that using this drop down, you should see that name off the bill pipeline. Based on the one that we just created. We just created a pipeline with the build, and that's that name there on. Then we can go ahead on cleat so you can see here the artifacts published by each person will be available for deployment in release pipelines. The last successful build was published, published the following artifacts. All right, so I can just go ahead on at. So at least we have an artifact. You can also Stadio say, See, you can schedule a release trigger to say that I'm just going to go ahead and enable it that every time at these times, want toe release a new build or release a new artifact for potential. Release her. So I'm not going to any oblique? No, we're doing it manually. No, but I'm just showing how you can go both automating it next. The stage would be, um you know, you can off you 80. You can have production chewy, etcetera. So that's what stage really means. They can add many stages to say that. Okay, When the artifact is released on, then it's passed through. We can move from this environment. This environment etcetera. Right now I'm just doing one. So we're just moving from the build tool, the deployment on the server, and then we have to pay some attention to this. So I'm just going to call this one VM deployment. All right, so that's a stage name on then. I'm just going to walk you through each off these fields and explain why we may or may not need them. No, this pipeline allows you to actually build the I I s website from scratch. So we just went through. All of those steps went in, we build the website, we'll build our application pool. We set up our database and everything. This they are these steps rather alot us toe automate all off that now most of it is done Someone to actually not need most of these steps. Right? So the configuration time I saw upside to can you that they were going to see create our opiate, So I already have it created. So I'm just going to click start because I don't want to make any changes. Create are open. It means that if it doesn't exist, create it, obviously, or I'm going to put new settings in there, so change them. But I just wanted to start. I don't want to change anything. That's there. The website name was leave management. All right. That was name that we give for upsetting. I s on then we can specify where we want. Our databases are backpack. So they have this thing called the park right, Which is, like a deployment fast. Specify the way in which you want to deploy the DB. We can use that pop our SQL script. So I'm just going to go ahead on and leave it as that park on. Put in the database name, which is leave underscore management. All right. So desperate. In front of those, if you're naming was a school, says my and one without an underscore one with just be careful that you're putting the right names that right places. So for each section, we are going to see if we need toe, you know, putting more details. So if I just like the ass deployment to see more details, more attention is required is going to talk about a deployment group. So I don't have any deployment groups. I guess I'm going to have to create one so I can go to the year on then that is going to bring up that deployment group section on that section shows is that we don't have any groups, So the deployment group is basically and here it is. It defines a logical group off target machines for deployments. All right, so you can deploy to multiple machines with one release. It's just a matter off setting off the deployment group so we don't have one machine. It's understand toe a deployment group. I'm going to call this one fraud on golf course loosely. So I'm not here to teach you about your release pipeline And the specifics there in I'm just showing you how to settle a basic pipeline and then your business rules will govern Which environment gets it first, right? So then the next thing I know is that they're going to see well in orderto facilitate communication between this flowed application and the machine that the deployment will be happening on, which would be our server. We need to run this script. So it's a powershell script. In case you've never heard of Porsche, this is what it is already. Maybe you heard of attainable site before. This is what it looks like. You don't really have to understand this. I'm hoping to really try and explain it to you, but I'm just going to take use a personal access token in the script for authentication. And then I went to copy this script. And then it's seeing run from an administrator. Portia Command trumped. So once again, this copy descript. Then we hop over to our server on then on the server. I'm going to have to bring up my power shell windows. Every server, our Windows seven upwards machine should have Portia on it. The key is that you just right click on Did you see Run as administrator. Once you're in, you're going toe based the script and press enter on. Then it's going to deploy a zero agents issuing the directory c and then see Izzy. Agent Andi, give it some time. After a while, you're going to get this prompt on. I think I pressed enter a few times too many, but then it's just, um yeah, so it's going to give you these few lines, and then it's registering an agent connecting to the server and then seeing inter deployment group talks for agent. I'm just going to see why for yes, um oh, well, you chant into them, so I really don't need to, but understand, to see a weapon db that's fine. Comma separate them on. I'm looking in the director where the agent is being created or all the supporting facts are being deployed. Then it says, Enter user cone for the service percenter for anti authority systems. Remember that. That is a very powerful user. I'm just going to use that user so that anything that needs to happen can happen on permissions are granted at No, our agent is sit. Oh, so when I go back toe zero, I can go over to the targets tub on. I would know, See that machine listed and those are the tugs that they were asking about. So they were really optional, but hey, all right, so once I see the machine, I can feel confident that that step is done. So I'm going to go back to my release by plan, And then I can just refresh this deployment group, and you see, I'm working with multiple tabs because I don't like stopping and going back and so on. So when I dropped down, I see prod, That's good. So, no, I have my deployment group and that era goes away. I'm going to look inside off this one on this one is peculiar because there's really nothing to change your all that it was taken. Antic any eyes. So any bias means if check this if you want in style it on the machines. If it was a very first deployment, he wasn't on the machine. I guess you check it. We don't need it because I ice is already there. Everything is already set up on. Then we go down to the SQL deployment on. Then we once again select Prague because that's our target machine. So here's a situation now where if the database is on a different machine, they would have to set up another targets machine or deployment group. So this would probably be like proud Web versus product BB rights. But then they're both on the same machine. So I'm just using the same deployment group on. Everything will look the same way If I drilled on into the db deploy, we will have Teoh to provide some, um, details on the server. So remember that our server or my server is that local host, but its SQL Express box slash sorry SQL back slash sq express. Right, So the same kind off servant and there you put inside of the connection string. You have to make sure you're targeting that same data. Bees, authentication. We can leave as windows authentication based on hold. We deployed it before on DSO on. So what I'm showing is a guideline. I don't really know your situation, but at least I'm giving an idea off what it's possible. So once we've done that and we've cleared out all off the red lines, at least in this section, then we can click, save on die, Just like Okay, Don't have to change that. All right, So what I'm going to do is trigger a manual release, right? No. Right. So I can just do that and I can just click, create release. So I'm just going toe, take a mental note off all the files that are currently in the leave Management Fuller on the time stamps to see if maybe any off them. I changed after the release, but I'm going to go ahead on go backs and it just come out off the virtual machine, create release on, then we can see that to the side. They're just confirming, um, it's a Veum deployment on. We can choose the artifact and we can't even put in a release description. You know, just to say this really speaks this bog, etcetera. We go ahead and click, create, and then you see that the job has begun so I can click release on. Then it's going to bring me toe screen. That's going to show me a little progress on They were so kind. They're trying to show you that they made some improvements, but I don't need to see that on. Then they're going to show me that I manually triggered this build. This is the artifact on then I can treat deploy on. Then once I do that, I think deploy. So I'm saying that I want you to deploy toe the VM so I can click on that deployment on, then click on the playable, nor on that semi circle on. Then it will bring me to a screen that is showing me the progress off the deployment on. Then that is done right? So it took 38 seconds still put in that release. Now let me go back to my virtual machine on Look back in the fold over the files on while everything seems to be there on is quite fine. No, I'm going to make a tangible CI. And so I'm going toe, maybe make a change to the log in screen to see a log in here. Something like that. Um, on. Then we'll see how we check it in the build release and then look for the opiate. All right, so very minor change. And I'm just doing this for, you know, showing sake. You probably don't have to do all of that, but I'm just going toe, go ahead on and commit this change test for release. That's all I'm doing as a note on. Then I'm going to commit all Onda sink on dso when I go over toe ghetto as your develops, I'm seeing that it is in the process off doing a build. All right, so I just checked something in, and it's already doing a bill because it detected that something you happen didn't get up. So it is no building to make sure that whatever changes made it was okay. I can view the two changes just to make sure that it is building right so there will test for release. So it got the change Andi. It's just doing its job automatically, right? So we can always click on job to see the progress on. We give that sometime on. Once that build is completed, we see that we have a new artifact. So when I go with the releases, I can trigger a manual release. If I want Andi I'm seeing here. That's something failed. I'm wondering if this was my previous release. That field. Okay, so by going in, I see that the SQL deployment part of it feels so We would probably have to do a bit more work than just deploying the sq like this. Or maybe we need to use not a backpack, but on SQL script. Either way, let's focus on the web part for knowing that we can figure out the sq apart. So I want to go back to releases. All right, so this is this is the thing with the setting of the pipeline. You can river technical at first, but then once you get it automated, it's not something you have to do every day. All right, So I'm going to create a new release. No, Once again, if I edit the pipeline, if I ended the release pipeline on Guy go and steady lit. Then I can schedule a release trigger into the deployment. Right. So that means I can do a nightly release or a no early release, whatever it is. But right now I'm doing it manually because I'm not in a production sitting. I don't need to sit down a schedule. All right, So I'm doing I'm creating the release and then I go ahead and hit, Create on, then it's going to start the release. So I guess it's going to feel once again on the database leg. But let us at least validated that the Web leg was done successfully. So by going and I see that it did, the I Spire trial is the first part off eyes changes. It's doing the actual deployment. No, all right. And I'm getting on her here, seeing that it feel to deploy because it cannot modify the file automobile. Dll It's locked in by some process. So something interrupted this release on the server on. I'm probably just going to have to go in on make sure that there all the release, all the resource is our free for the release toe happen. All right, all right. So I went on the server and I just restarted the web up or websites. I just clicked it and in a restart also adjusted a recycle on a pool on. Then I'm going to try again, all right? So sometimes releases feel because off these things. So, yes, you all to meet its. But then you can always you know, this failure is almost, I guarantee, at some points, someone to just go ahead and create another release. So I have to field releases so far. I'm just going to go ahead, create another one on then you see, it's in progress. We click. It's just still, watch it. Go on, then let's see if the resource is have been freed up. All right, and there we go. We have a successful release on bond. Well, this time it just succeeded. There is no error whatsoever. So if I go back to releases, then oh, it's still going through another phase. So there it field on the SQL deployments that I, as the climbing was good on the SQL deployment field, were you know that that one might have field, but let's go back to our server on to see if we can spot any major differences. All right, And there we go. So all that it was adhere, remember? Did say would change log into logging here. So I did that change. Checked it into ghetto asses. Your develops automatically did a build validating one needed to be validated. Once again, those steps are very basic out of the box, but you can add more validations, teach build, especially if you're a senior developer and you want more quality control over what goes into the into the environment. But at the basic level it didn't build on it held the artifact on. Then we set up that release. So once again, if you wanted to automate that because that was a very manual process having to go to release, then create release and then started, we can it it the pipeline. So that's going to releases and they say, edit on. Then we can do a schedule where we say every day at maybe 3 a.m. You do eso you see only steady releases if the source or pipeline has changed. So that means one. Somebody checks in cord and it has passed through the build on it is successful and so on. Artifact, once it's different from what obtains, then automatically door release. My objective today was to show you how you can start and used to automate between checking in court and releasing it into your environment.
70. Publish Review: you guys. This is just an overview video for this section. So in this section, we looked at whole toe publish our absent we looked at Well, two, maybe three scenarios. Based on how you perceive the first scenario where we're publishing toe, I I s Andi I asked would be on your local machine. He could be on a machine on the server or it could be a virtual machine in the clothe. A point is that it's ah, Windows machine running the information, Internet Information services application or eyes for short on hole. We can go about setting off the environment for the dot net core application to be hosted there. Andi, further accessible. We looked at permissions issues that can arise both for the file execution or application execution as well as database connectivity. Onda, we looked at all to just configure a server little things to look out for Andi, you know, troubleshooting tips. We also looked at how we can go boats deploying toe as you're so we saw the danger in just deploying because it created the database. The connection string was okay. Everything was okay, but no tables were created, so we had two choices we could have either trying to get an SQL a script that represents the migrations and then trend. Do them manually on the cloud server or, um, we resort, attracting some custom code toe searching all the environment variable on choosing which connection string to use at the time, as well as including this line that would forward engineer all off the migrations automatically. All right, so the end result of this section is that you will know have on intern it, um, by a source. Did version of your application on you also have a cloud hosted version of the application . I winter both scenarios because one must be practical for your context. Right on, def. There's another context that you have. Then you know, you can feel free to reach out to me and let me know on day I will try my best to help you through that