Hands on tutorial on how to create a simple webapp with asp.net core. The app has an image upload feature and all the data is saved on a SQL Server Db using EntityFrameworkCore
2. This is a hand on
ASP.NET Core MVC application
built with Entity Framework Core
using the database first approach
3. What are we building ?
1
Create a SQL db
with defined
schema.
Create a ASP.Net
Core app and
scaffold the
models.
Add a bootstrap
cards display on
the home page.
Construct some
crud functionality,
including image
upload
2 3 4
6. 4
5
Name your new database,
preferably “RestaurantDelivery”
Once created, right click on it and
select New Query
7. 7
6
Copy the query block /*Creation*/
in the comments into the query
window and run it with “F5”
Next, copy and past the
/*Validation*/ block and check the
tables data. The result should be
close to this example ---->
13. 4 Next, choose “Web
application (Model-
View-Controller)”
option.
*make sure to mark ASP.NET Core 2.1 or
higher
14. 5
Next, right click on the
project and select
“Manage NuGet
Packages”
6
Click on Browse and look
for EnityFrameworkCore.
In the results, select and
install the package
Microsoft.Entity.Framewor
kCore.Tools
*select the highest version lower than 3.0
16. 1 Locate the Package
Manager Console on
the bottom of visual
studio window.
2 Paste the scaffolding
command and press
“Enter”
*Attention to the database name and
context name you give.
3 Check if the models
were created
17. 4 Adjust the Context class by removing the
code selected. The connection string will
be passed later.
19. 5 Right click on the project
and create a new folder.
Name it “Repository”
20. 6 Right click on
the repository
folder and add a
new interface.
Name it
“IRepository”
Code in the
comments.
*Adjust the namespace
accordingly
21. 7 Right click on
the repository
folder and add a
new class.
Name it
“RetaurantRepo
sitory”
Code in the
comments.
*Adjust the namespace
accordingly
22. 8 Go to the
Startup.cs file
and inject the
DbContext and
the new
Repository as
shown.
23. 9 Right click on the Controller folder
and add a new Controller
24. 10 Select the option show
11 Select Restaurant model class and your
context respectively, click Add
25. 13
Go to the
RestaurantsController
class and adjust it to use
the respository we
implemented before
*Code on the comments.
Adjust the namespace
12
Next, there will be a new
controller and some new
files on restaurants folder
26. 13 Add a new
menu item
on the nav
bar on the
_Layout file
14
Change your run
option to use kerstel
(your project name)
30. 2
Do it again but this
time name the new
file as
OrderRespository
*Code also in the
comments
3
Repository folder
should look like this:
31. 4 Right click on the Controller folder
and add a new Controller
5 Select Order model and your context
respectively, than adjust the
controller code with the one in the
comments to make it use the
respective repository
32. 6 Again, right click on the Controller
folder and add a new Controller
7 Select MenuItem model and your
context respectively, than adjust it
using the comments
33. 8 Check out your Controllers and
View folders, they should look like
this
34. 9 Open the Index file
on Orders folder
and fix navigation
properties
35. 10 On the _Layout file add
two more items on the nav
bar