.NET Core Employees Management System|| Create ASP.NET Core Web Application With SQL Server Database

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome to macro code so if you are new to this channel consider subscribing so on today's video we're going to do a continuation of employees management system so there is a video that we did about a crude operation on a speed.net core and some of you guys requested that we proceed with the continuation of that video so we are going to proceed with the continuation of that video and if you are new to this channel consider subscribing and let's get started so we had created a crude app for creating and adding employees so we are going to announce this application so to begin with we are going to start so you can see on our project we have a context application class here with our employees uh table then we have our models for employees so you can see then we have a program.cs we are using sqm so you can see that and we have our nuggets so if you want to see how we started this project we are going to paste down below there a link to our previous uh video so let's try and modify some things here our first name let's make this required so we can do that you can make these required you can make these required then we can have a our full name so how do we do that we can do that then you can remove these then you can say full name then you can do this is equals to then do that dollar sign and then we can have our first name then our middle name then our last name then email address you can have these are the required field then phone number so you can close this so employee can have first name middle name last name email address phone number what else can we add here so we can have a country but really let's have a address so I'll show you how we need to update some things so if we had this so this table we had created it and we only had these uh Fields so for the address one we are going to update our views so come to views uh huh we are going to add now the address so here we'll do address so copy these copy this that way so on uh edit you can also have the address so address copy that copy this copy this then on index we are going to display phone number then we can have the address here as well so we'll need to showcase our address on our table data or you can do address so our edits you can have so you're using photos for the view we can have it as I then some space for the delete you can have a trash then that is fine so to update our field remember you have updated our model with the new class with a new field and which is the address so we need to add migrations so add migrations and to do that guys you come to tools then nugget packet then package manager console then add migration then you provide the migration name you can say added address so if we press enter it's going to create the migration so it is done you can see it has added this field it does added the address field in our employees table with the type point so it has created these uh added address in our folder called migrations you can see we have that folder here so to update this to our database we do updates database then it is able to that is done so if we run our application there we are so you can see we have these uh employees management so as you can see on our table headers the first name middle name actually uh together so if if you want to separate this there's something that we can do on our models so come to employees then here you can say display name then you do this then you say fastener so you can do the same so we it will actually give us this name now so this is what will be displayed in our form display this is the name that you want to displayed on our view last name so so you can have that last name you can have also these full name then you can also have these as email address then you can also have a phone number or number you can also have address so if we run this so you can see first name middle name is actually now separated so it is showing what we had provided so we can add a new employee you can say Jack arom s then tests you can provide the phone number seven and our address so it you can see it has created so it is not adding our address so what could be the issue so let's come to our model uh controller so come to controllers then employees so on the controllers you can see it is actually specifying the field so you can actually remove this uh you can also remove this binding let me just leave the model there so this is how the let me zoom in so this is how it is so I think that is now okay so if we try again so there you are we can add another employee ejector that's probably these are the test one gmail.com so I'm providing some numbers so you can see a valid is not a valid phone number so it has the maximum integers so you can save so you can see it is actually saving now the the address so assuming you want to validate some Fields here so let's validate some Fields so we can do that in our model so for our phone number you can actually add from so it will actually take uh in a phone number for the email you can also do that so you can say this email address so that is how you validate and you can also put in some uh some you can actually put in the length of the string in case you need but this one is good to actually use so you can do this from email address and you'll be able to validate that so you can also try to run this so you can also add jet3 check three object three practice three at gmail.com so you can add the phone number one two three four five so you can see it's not a valid so it is now validating a phone number so you can see one one two three four five so you can do that the value is not a valid phone number let me try to save it so what is the phone number field is not a valid phone number so what does it expect the expecting and data field value is well from the phone number so it's expecting let's do that thank you so this is formed so you can have foreign [Music] so if we do this so so let's add a new let's say Jack three so this one you can say Jack at gmail.com phone number then or just it is actually saving so let's try to put in some UI here on employees management we we actually spaced these so to space that how you find it you come to to share layouts then you'll be able to see that text here so this is the ones so you can do this as employees management system then on our footer you can also do that employees management system so guys if you're watching this video remember to subscribe and uh turn on the notification because you will be actually exploring more with these uh Solutions so we can run our application you can see we have now employees management system we have index so this index you can change it to our employees list so come to employees then index then you can save you can say this is employees employees list so that is it then we can we can call these employees please change the title so that is fine so you can run this um there you are so you can see I have employees list employees management system and the employees management system down here so you can also try to have it down here under shared and the footer you can have these as all rights reserved exam and try to run this foreign there you are so you have already reserved copyright is 2023 employees management system so let's do something interesting so we want to build a complete employees management system so let's start with the setups so we want to add countries so assuming some of our employees come from different countries so we can add uh let's have a table for countries how do you do that remember we are using Code fast approach so come to models add a new class called this country then add it so our country will be having the key so we can actually leave it or you specify it with the word key then you can for a country we can have uh you can have a string then you can have the country code you can have the country code and we can also have the country name so these two fields are required so you can actually annotate with that you can do that and you can also do this guys so you can actually do required at the top in case you you want it that way but that is an old way of doing things but you can also do that so I also prefer doing that but for now if you do required intellectually make that feel compulsory so you can also do required so you're using.net7 then the country code we can have this as continue so guys so take this country code we need to add it to our application rdb context so come here then application DB context you can have it here you can say this is country you can say this is countries Okay so in a in a in our country we usually have uh counties so we're going to add another County assuming we have an employee coming from different countries counties so we can have County so these are County class so you can also have publicans you can specify this as a key then you can do public public stream stream games let's say name so this is required so you can call this County call so this is our County codes then we can have occur then you can have the county name so in case you want to play that we can now map this to our you can copy that then we can have our County then counties so these another table guys so defect these changes we can do we can add migrations now so come to our console then you can say add you can say add migrations then you can say your locations your look Go locations then try to press enter then you can say updates database update database so we will press that it will be able to update our database so we can try to see our database we are using SQL Server management Studio SQL Express Edition for development so you can install that and get started so we'll just see so we are using so you have a database called employees so on our tables you'll see we have now the countries counties we have our employees table that we created and we have a user so for the countries if we do this we don't have anything so we want to add some countries and the counties in our system so let's scaffold so to scaffold these click on controllers then add new then new scaffold item then MVC controller with views using Entity Framework then you'll get the screen so select the model class you want to create a crude form for the countries then we are using application DB context so it will create a controller called a country's controller so we are okay with that then click add so it is generating our crude forms that is for the create read update and delete so these are this is an easy way to do that guys so you can see it is done so we have a controller scroll uh countries and when you come to views you'll be able to see a folder called countries so you can see here we have countries so so we need to add our countries to our view so if we click our app you can see we have we have only ohms employees and privacy so we need to add our countries so come to Shared layout then on our menus so we can change the Privacy to countries then controller is countries then it can take us to the index page so this is our action so we can also do the same for counties add then new scaffold then MVC then we can choose account County so it will create we are using application DB context then it will create a controller called counties controller so we can also add another table for Department remember employees belongs to departments so then we will see how we can map our employees to counties and departments that we have created so you can see we have created our controller called counties and it has added a new folder called counties so we can also add the same to our trip to our navigation so this is counties so this is a counties so if we if we do this so if we run our application [Music] so you can see we have home employees countries and counties so if we click on countries you can see we have index country code and country name so we can actually try to make that cleaner so come to our model and the country then you can specify the display name so you can use these then you do this then you say County Country this country country code so you can also do country name so we can also do the same for the county we have the copy that then we say County code then we have the county name sorry so if we come to our index Let's do let's add the let's add the let's add a bootstrap so I'm gonna have edit can have this is delete you can also have a view I can do that for the others so we will copy this then here you can remove these ones then we say so this one can be so this one is edit so you can have this as a button so BTM vtn primary then edit then you can have a icon so a class here you can have it as using fontosam so you can have this as pencil so we can delete this uh let's just leave it you can copy this then this one will be details this is for the viewing then you can say this View then primary you can have this as secondary secondary then on view you can have an eye icon there then you can copy these then you can say this is delete and uh our button here we can see this is danger you can see this is trash so we can remove these try to format it so we have our icons and uh class there so you can actually copy this and replicate it to our countries so you can do this you can also copy the errors which are these one and paste it under index so at the top here you can have we say countries we can we can count these so that is it so if we run our app it is running so there we are so if you click on countries you see we have uh countries country news so we can create a new them country you can say ke which is a can there you are we have a country there guys India i n d i don't know if that is the correct uh guys you can tell me uh ug that is for Uganda Uganda then you can you can click click you can create more guys so you can also create accounting so these account is in Kenya so we have a ug [Music] C Edition so these are some of our counties Nairobi so Nairobi is actually a city and a County let me have one case [Music] Sumo just doing this but I'll confirm if these are the correct chords guys so you have a we have uh so I've created some of these chords so you can actually create more guys so assuming I want to link our employees if I'm creating an employee I want to choose the country that they are coming from and the account so what I need to do these are now relationship guys so we need to relate our employees to the countries and the counties so what we need to do the first thing first come to our employees model come to employees model we need to store the we need to store the country and the county so these will be the country so here you will say country ID then to make our code understand that this is a relationship we'll have a country here and we have this as a country so put in the country class then country then so our field should be the country which is the name of this one of the class with an ID in front of it so it will actually have this as a relationship and this one you can say can be nullable so you can copy the same and do it for the county so say County ID then remember this will be count and these will be Counting so that is it guys so we will be able to see that we can now add our counties to our table so what we need to do is to update this on our database so we'll say add migration say employees jio locations your locations updates so it is done so I can update our database so before that let's see our table how it looks so if we run our employees table you see we don't have the county ID and the country code and remember guys what we have added on employees table you see it has the country plus so it will only append these fields these two Fields so we will not be having these two uh I mean the four ones the four Fields it will only take the country ID and it will understand that this is a relationship that should be tied to the county and this is one that sheet is tied to account so this is actually a one to one uh relationship so say update update database database so if we run that so if you have any comment guys remember to subscribe and comment down below you can see it is there the alter statement conflicted with the foreign constraint so you can see this it will understand that the county it is actually the primary key in our County uh table thank you country IDs are actually a primary key in our country uh table so to update this let's do add migration so you should actually add this so that we are able to pick a country and the county while adding an employee so we'll say add add migrations then you say employees video locations so you will add migration it will add these two fields in our employees table you can see so let's update so when you come to our employees table you'll see that you don't have those two fields so we only have first name middle name and so I've actually cleared the data so you can do update database database so when you run that it is done so if we refresh our table uh can select you can see we have the address country ID and the county ID so we need to now specify these uh fields on our create on our create a view so that when you are creating our employees we are able to choose there we're able to choose the able to choose the county and the country so what we need to do will come to our we'll come to our our create class then we need to specify we need to specify the drop down list in our create class so let's come to so we need to specify so guys for us to pick the country and the accounting when we are creating our employees uh list so we will need to come to our employees we need to come to our employees View then under create we need to specify a list a drop down list from the employees table so let's copy that then we need to provide the label for the country so we'll say this is country ID then this is the country ID but now our input we need to specify it as a drop down so this one will be so you can have these as a so it is usually good for you to specify this before creating uh your your your your your your views because it will actually give you the correct uh thing or you can actually do this guys then for us typing you can actually delete this folder foreign just delete it and delete our delete our controller employee then you can regenerate again you can scaffold so come here then new item then scaffold then I'm using MVC then come and say employee then employees then add so it is scaffold with the new drop down list of the country and the county so that is how you are able to do or you can actually type it assuming you had actually done a lot of things so you can actually uh type it but because we have not done much we can prefer that so you can see if we come to our create we'll have all those details with now our drop down remember the drop down that I had showed and we were trying to kill it is now here guys so let's copy something that our customizations for the views because we had done for the country so we can copy this and we can provide it on our index so you can do that then you can say this is edit you can copy this you can have these as View and these as delete then it all right then you can have these as employees employees list so then here you can also have some icons which is a class then file so we are using font awesome then you can say this is a plus and you can have these as add new employee so this is how you do it guys so come to a controller then you need to remove the field bindings you can remove these ones then can also go away with these ones then that is it so you will come to our our create you'll see it has actually it is actually populating at least so this is a drop down lists four it is actually providing us a drop down list for the country and the county so if we run our app remember we have modified it we have added we are trying to add a county and the country when creating an employee so you need to choose it so we have it here so if we add say check so down here you see it is requesting as the country and the county so is that the correct name should be count yeah these ones will be count so we have not created this guy so we need to create that before we do anything so let's do that let's say ke okay now so I can clean this so you can do another one ug Anda so this is the countries then counties we can create counties we say ugac [Music] so you can also create a new one say nine Nairobi then so we have our countries and the countries so when you're creating an employee you see we now have a drop down list but now our drawdown list is giving us the IDS so we need to provide the description so what we need to do come to the come to our controller employees and then uh we we want here we want the country say here you want the country country name so these should be the county name so that is what we want so this one should be so we can actually copy this and not really let's just replace that done so here country you need the country name to be showing and this one you need the counting you can also do the same here County you can also do it here so here again and so I can do this and provide the county that is it so if we run our app so when you click that you can see now we have the count the country names showing and the county name so you can create our our employee here phone number then we can select the Kenya the Nairobi so it is saying I'll count our we can try to see our controller create controller our create controller does it say let's see the uh yeah so let's do something here so come to our model so then on our this one you can do this as empty it's expecting some values so then a run so make that as a nullable then try to create an employee all right just you can see it does now it has now created our our employees list so you can see we have now the country County as our so you can add another employee can do that can add another one foreign so you can see it is it is good we also have our countries and we have our counties but now something interesting you can see our countries it is showing the primary keys but you want this to be showing the names so come to our index employees index then under the country we give the country name here we give the county name so if we run our app this should be fine yes guys so you can see the countries it is now showing the name and the county showing the name so guys so remember to subscribe so on our next video we are going to see how we are going to integrate the template that you can be able to reuse so we are going to integrate our employees management system with our template so we are going to see that in our next video so remember to subscribe and share so see you and bye
Info
Channel: Macro Code
Views: 2,767
Rating: undefined out of 5
Keywords: C#, AmigosCode, Classes, .NET, .NETFramework, .NETCORE, Sundeep, Saradhi, freecodeCamp, ProgrammingWithMosh, MikeDane, IamTimCorey, TeddySmith, FireShip, DaniKrossing, Stefan Mischook, ASP.NET CORE, Coder Foundry, Jose Montemagno, .NET 7, .NET 6, Visual Studio, Nick, Nickchapsas, Jake Wright, Keep On Coding, QuestPond, Comrades Flavour, Nicholas Kioko, Amigos, Developer Filip, TechWorld With Nana, Techworld, GotoConferences, CRUD, ASP.NETCORE, SQL, SERVER, BoostMyTool, .NET 7.0, dotnet, kudventkat, Bro Code
Id: UXTDwXX-6Tw
Channel Id: undefined
Length: 43min 9sec (2589 seconds)
Published: Sat Feb 25 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.