Tutorial Aula 5
Tutorial Aula 5
Tutorial exercises
• From the Visual Studio, create a new project ASP.NET Core Web App (Model-
View-Controller). Name de project Aula05.
1st step:
• Create a model class (with right mouse button over Models folder in Solution
Explorer).
Web Engineering 2024/2025
Tutorial exercises
2nd Step
• Add a controller with the template “MVC Controller with views, using Entity
Framework”. This will add to project one controller class and all views code for
CRUD operations over the model data.
Web Engineering 2024/2025
Tutorial exercises
• Choose the Category model class choose an existing Data Context class or create a
new one.
As we still don’t have any Data Context in project, we need to create a new one. The
project can have multiple Data Context classes, but we also can add a new model set to
an existing data context (when the new data set is intended for the same database).
Now we are ready to prepare the database with some commands executed in
“Package Manager Console”.
Web Engineering 2024/2025
Tutorial exercises
Third step
The CoverPhoto and Document inputs, must be a button to select a file from the
computer.
Web Engineering 2024/2025
Tutorial exercises
Create two subfolders inside wwwroot folder (with right mouse button over wwwroot
folder in Solution Explorer) and name them Documents and Cover.
To access these folders in the disc of the server machine, is needed to use the
IWebHostEnvironment interface. The WebRootPath property gets the absolute path to
the directory that contains the application content files.
3rd Step
Download Files
The mimeType variable represent the mime type value of the file contents, who is
needed to pass to the browser to process it.
More info:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
Homework:
- Alter de view Create to show only allowed extensions when choosing the files.
- Alter de view Index to show the cover photo instead its filename.
- Alter the action Delete to also delete the corresponding files from the file system.