
Explore building a .NET 7 web API with Entity Framework Jumpstart, covering MVC structure, async/await, DTOs, CRUD operations, code-first migrations, authentication with hashed passwords and JSON web tokens, and relationships.
Install Visual Studio Code and the .NET SDK, choosing the correct operating system, and download dotnet 7 to prepare for creating a new web API.
Install the .NET SDK and Visual Studio Code, create a web API project with dotnet new web API, and explore Program.cs, Swagger UI, and basic middleware to handle HTTP requests.
Start a dotnet web api with watch and hot reload, access Swagger and the weather forecast get call, test routes, and view results in browser and developer tools.
Explore the model-view-controller pattern and plan controllers and models for RPG characters, then convert synchronous calls to asynchronous, and use data transfer objects to align the API with best practices.
The MVC pattern divides logic into model, view, and controller. The web API creates, updates, and deletes data, while the view renders results via UI and Swagger UI.
Create models for roleplaying game, a character class with id, name, hit points, strength, defense, intelligence, and an RPG class enum with knight, mage, cleric; then add controller and get.
create a new api character controller, derive from controller base, add api controller and route attributes, and implement a get method returning a mock knight character for swagger testing.
Learn first steps with attribute routing in a .NET 7 web api, building a characters list, creating get all and get single endpoints, and testing with swagger.
Define a route parameter for the single character endpoint and retrieve a character by ID using first or default with a lambda, tested in swagger.
Discover how http request methods map to crud in a .net 7 web api: use get for reading, post for creating, put for updating, and delete for removing, soft delete.
Add a new character with a post request by sending a JSON body to the API, then return the full character list to verify the update.
Structure a web api by delegating logic to services, injecting dependencies into controllers, and using DTOs to shape client data with mapped models, optionally via AutoMapper.
Create ICharacterService and CharacterService in a services folder, inject with add scoped in program.cs, and verify via swagger that get all characters returns Frodo and Sam.
Fix possible argument null exceptions by using first or default to fetch a character, check for null, return when found, or throw character not found, tested in swagger.
Discover how asynchronous calls free threads during tasks, and learn to implement async, Task, and await in the character service and controller, preparing for database queries with entity framework.
Wrap service results in a generic wrapper service response using generics to type the data, including data, isSuccessful, and message for clear front-end interceptors and error handling.
Create and use data transfer objects for RPG characters, including get character DTO and add character DTO; map between model and DTOs with AutoMapper in controllers and services.
Install AutoMapper extensions, register AutoMapper in program.cs, inject IMapper into services, and configure a profile to map character to get character DTO and add character DTO.
Implement a put-based update for an RPG character by adding update character to the interface, service, and controller, using update character DTO and id, with null checks and not-found handling.
Learn how to update a character using AutoMapper by mapping the updated character to the character object and using the map overload. Configure an update map in the AutoMapper profile.
Implement the delete character operation across the interface, service, and controller to remove a character by id and return the remaining characters, noting first versus first or default behavior.
Create a dot net web api with CRUD operations (get, post, put, delete). Use the mvc design pattern, dependency injection, asynchronous calls, and data transfer objects for Entity Framework.
Explore object-relational mapping, where characters and skills map to tables and relationships in relational databases, and use code-first migration with entity framework to generate the database from your models.
Install essential EF Core packages, then install and verify the EF command-line tools globally to enable migrations in a net seven project.
Download SQL Server Express, the free edition ideal for development and production for desktop, web, and small server apps, and install SQL Server Management Studio to view and modify databases.
Configure the connection string in appsettings.json under the connection strings section, register the DbContext in the program, and use SQL Server with the Default Connection for migrations.
Create the initial migration with dotnet ef migrations add initial create, then apply migrations to build the dotnet rpg database and the characters table with id, name, and hit points.
Inject the data context via dependency injection into the character service, access context.Characters, use ToListAsync to map to character dtos for the service response; seed data and test with swagger.
Add a new RPG character to the database using context.Characters.Add and SaveChangesAsync, letting SQL Server generate the ID. Return all RPG characters after insertion and test with Swagger.
Fetch the character from the data context asynchronously, modify its properties, and save changes asynchronously using the put method, with the id remaining fixed.
Delete implementations demonstrate removing a character via entity framework as part of create, read, update, delete operations, replacing static list with context, calling remove, saving changes, and testing api.
Implement create, read, update, and delete operations with entity framework, use code-first migration and SQL Server, configure db context and connection string, and prepare for user-owned characters and authentication.
Build user authentication by creating accounts, defining a user model, linking multiple RPG characters to each user, and implementing JSON web tokens to verify access for selecting and updating characters.
Define a user model with id, username, and password hash and salt, register a DbSet in the data context, and create a relationship where users can have multiple rpg characters.
Explain one-to-one and one-to-many relationships using a user and RPG character, note many-to-many with skills, then add model properties, run a migration, update the database, and implement authentication.
Explore authentication through the repository pattern, leveraging entity framework and a data context to decouple data access from the domain model and enable dependency injection.
Create an authentication repository with register, login, and user exists methods, implemented in the data layer, returning user IDs, JWT tokens, or booleans via service responses.
The user exists method checks username duplicates using any async with a case-insensitive comparison, returning true or false; the register flow uses a service response to flag 'user already exists'.
Learn to build an authentication controller in a .NET 7 web API, inject an auth repository, and implement a register endpoint using a user register DTO to return the user id.
Implement token authentication with JSON web tokens to securely authorize web API requests, storing tokens in the browser, using claims, expiration, and server-side signing.
Configure app settings token and build a JWT with claims, a symmetric security key, and HMC SHA 512 signing. The token supports login, swagger testing, and authorization via middleware.
Secure web API calls with the authorize attribute and a JWT bearer authentication scheme in program. Enable token validation and authentication middleware, then test with swagger using a bearer token.
Enable bearer token testing in swagger by adding a security definition and operation filter using swashbuckler, configure authorization header, and demonstrate authorize and allow anonymous controls on secured controllers.
Leverage claims principle to extract the authenticated user's id, then filter character data by that user id in the Entity Framework service, test with swagger, and establish user-character relationships.
Explore advanced relationships in Entity Framework, start with a one-to-many link between users and characters, then add weapon and skill models to illustrate one-to-one and many-to-many patterns.
Learn to relate RPG characters to the authenticated user by injecting the http context accessor, extracting the user id from claims, and updating character service methods accordingly.
Assign the current authenticated user to a new character by mapping the add character dto, then filter results to return only that user's characters.
Enforce access control for get, delete, and update by filtering characters where the user id matches the current user, leveraging entity framework predicates.
Update entities safely by validating the current user with null checks, and use Entity Framework include to load the character's user before applying changes.
Add a weapon model to implement a one-to-one relationship with characters, using a character id foreign key, and run migrations to create the weapons table.
Implement a weapon service to add weapons to RPG characters, update the get character DTO via mapping, and expose a secure controller that uses the current user context.
Implement a many-to-many relation between characters and skills with entity framework, adding a skill model and navigation properties, and create a join table with a composite key via migrations.
Perform data seeding by configuring on model creating with has data, then run dotnet ef migrations and update the database to attach skills to characters.
Add character skill support by introducing character skill DTO and get skill DTO, map them to a character DTO with skills, and update the service and controller to attach skills.
Fetch the authenticated user and display each user’s own characters. Implement a one-to-one weapon relationship and a many-to-many skills relationship with entity framework joining tables, and build services and controllers.
Develop a service that lets RPG characters attack with weapons or skills, then have characters fight by themselves until one loses hit points, ranking victories as a high score.
Map relationships among characters, weapons, and skills, add fights, victories, and defeats to the character model, and implement a fight service and controller for upcoming attack simulations.
Implement a weapon attack system in a .NET 7 web API: define weapon attack DTOs and attack results, implement fight service and controller, and test with Frodo vs Wrestling.
Add a skill attack dto for attacker, opponent, and skill id; wire it through the interface and controller, validate the skill, apply skill damage via attacker intelligence.
Implement a fight system in net 7 web api, introducing fight request dto with character ids and fight result dto with a log, enabling rpg death matches and battle summaries.
Implement a high score feature by adding a high score DTO, mapping with AutoMapper, and exposing a GetHighScore method to rank fighters by fights, victories, and defeats.
Build a secure .NET 7 web API with CRUD operations, store changes in SQL Server via Entity Framework code-first migrations, and protect data with authentication and JSON Web Tokens.
Learn to build a .NET 7 web API with entity framework core, using the model-view-controller pattern, data transfer objects, async/await, authentication with JSON web tokens, migrations, CRUD, and relational databases.
Create a new web api with dotnet new web api, open the folder in Visual Studio Code, install recommended extensions, and explore the weather forecast controller and swagger.
Start the app with dot net watch run, open localhost, test the weather forecast endpoint via its route, then inspect results in the network tools, demonstrating the web API call.
Create and initialize a git repository, use a dotnet new gitignore to exclude unnecessary files, commit changes with clear messages, and push the project to GitHub.
Extend a .NET Web API project by adding a new controller and models for RPG characters, convert synchronous calls to asynchronous, and implement data transfer objects for practices in MVC.
Explore the mvc pattern by detailing the model, view, and controller and how the controller uses a web api to create, update, and delete data, persisting changes in the database.
Create a models folder with a character model and an RPG class enum (Knight, Mage, Cleric). Add properties id, name Frodo, hit points, strength, defense, intelligence, and a get endpoint.
Create a new api controller in a .net 7 web api, implement a get method returning a mock character, configure routing, return types, and json enum formatting for swagger.
Learn first steps with attribute routing in a .NET 7 web api by building a character list and implementing get all and get single endpoints using http methods and swagger.
Explore routing with parameters by retrieving an RPG character by id, wiring a get single method to match the route parameter, and test with urls like /characters/0 and /characters/1.
Explain how HTTP methods GET, POST, PUT, and DELETE map to CRUD operations, including how a soft delete can be implemented and how the backend updates a database.
Create a web API endpoint that adds a new character via HTTP POST, receiving a JSON body and returning the updated character list for testing in the API interface.
Separate the business logic into services to keep controllers simple. Inject dependencies to reuse services and map models to data transfer objects for client communication.
Implement a dedicated character service with ICharacterService and CharacterService classes, wire it to the controller via dependency injection, register as scoped in program.cs, and verify via swagger.
Enable asynchronous calls to improve responsiveness by returning task-based signatures. Apply async in the AI character service and controller, enabling Swagger-ready endpoints for future database queries with entity framework core.
Implement a generic service response pattern by wrapping results in a type T with data, success, and message for robust frontend handling.
Create dto classes for RPG characters, map model properties to get and add character dtos, and enable client-server data exchange using AutoMapper within the service and controller.
Learn how AutoMapper streamlines mapping in a .NET 7 Web API by installing the package, configuring profiles, injecting IMapper, and mapping character to get character DTO and add character DTO.
Implement a put update for a role-playing game character by adding update character dto and interface, map to get character dto in the service, and wire through the controller.
Learn to update a character with AutoMapper by mapping the update character DTO to the character and using partial versus full property updates, via the put method.
Implement a delete character operation by updating the interface, service, and controller, removing the character, mapping to DTOs, testing with swagger, and persisting with EF Core and SQL Server.
Build and explore a dotnet web api with full crud operations, leveraging mvc structure, dependency injection, asynchronous calls, and dto-based service responses, paving the way for entity framework core.
Learn to connect your web API to a database using Entity Framework Core, perform asynchronous CRUD operations, and persist RPG characters with code-first migrations on SQL Server Express.
Explore object-relational mapping by modeling characters and skills as code objects, while entity framework creates and updates database tables and relationships through code-first migration.
Install the entity framework core sql server provider and the dotnet-ef global tool, then add Microsoft.EntityFrameworkCore.Design to enable migrations, preparing the project for sql server.
Define a data context by creating a DbContext subclass with a DbSet<Character> to query and save RPG characters, embodying a unit of work and repository pattern.
Add a connection string in appsettings.json under the connectionStrings section named default connection, then register the db context in program.cs with useSqlServer using that string and start the first migration.
Use dotnet ef migrations add initial create to scaffold first migration, then run dotnet ef database update to create the database and the characters table with an id primary key.
Learn to wire a data context with dependency injection in the character service, fetch characters with EF Core and ToListAsync, map to a service response, and test endpoints in swagger.
Learn how to implement a post create endpoint in a .NET 7 web API using entity framework to add RPG characters, generate IDs, persist changes, and return all characters.
Use a put method to locate a character with FirstOrDefaultAsync from the data context, modify properties such as hit points, strength, and class, and save changes async; verify via swagger.
Replace the static characters with the context characters, delete the character, await the first async operation, save changes, and verify the deletion in swagger and the database.
Master CRUD with entity framework core, persisting changes via code-first migrations to a SQL Server database, and prepare to relate RPG characters to users with authentication.
Build a secure authentication flow by creating user accounts and RPG characters, using JSON web tokens to authorize character access and updates, and introduce the new user model.
Create a user model with id, username, password hash and salt as byte arrays, add it to the data context, and set up the relationship to RPG characters.
Explore three relation types and implement a one-to-many link between users and RPG characters by adding navigation properties, a user_id foreign key, and migrations to update the database, with authentication.
Explain how authentication uses hashed passwords and salt to avoid plain text storage; register by creating and storing salt and hash, then log in by hashing with the stored salt.
Explore how authentication uses the repository pattern with Entity Framework, injecting a data context through a repository interface to handle register, login, and user existence checks.
Register a new user by adding them via the data context, check for existing users, hash the password with h mek sha 512 and salt, and return the user id.
Implement an async user existence check with Entity Framework Core, using AnyAsync and case-insensitive username comparison, returning a 'user already exists' message in the register flow.
Create an authentication controller with a post /register endpoint that accepts a user register DTO, uses an auth repository to register a user, and returns 200 or 400.
Build a login flow that verifies passwords with stored hash and salt using hmac sha-512, returning a user id on success and detailed errors via a service response.
Learn how token authentication with JSON web tokens enables stateless web APIs to verify users via claims, using a private key, expiration, and secure browser storage.
Learn to implement JSON web tokens (JWT) for authentication in .NET 7 Web API, including configuring app settings, building claims, signing tokens, and validating expiration.
Enable Swagger to use bearer token by adding a security definition and an operation filter. Test protected endpoints by logging in to obtain a token and authorizing requests in Swagger.
Extract the authenticated user's id from the claims principal and fetch that user's RPG characters using a filtered EF query, tested via swagger with a bearer token.
Implement secure authentication in a .NET 7 web api with password hashing and salts, a one-to-many user to RPG character relationship, and JWT bearer tokens with claims.
The .NET framework is getting better and better and more important in the web development world nowadays.
Almost every request I get for new web development projects is asking for knowledge in .NET, including Web API and Entity Framework.
So, knowing the fundamentals of back-end web development with .NET can be highly beneficial to your career. And that’s where this course comes in.
In a short period of time, you will learn how to set up a Web API, make restful calls to this Web API and also save data persistently with Entity Framework, Code-First Migration, a SQL Server database, and all three types of relationships in this database.
We will get right to the point, you will see every single step of writing the necessary code and by the end of this course, you will have what it takes to say ‘yes’ to all the .NET project requests from any recruiter.
The only tool you need in the beginning is Visual Studio Code which is available for free.
We will use Visual Studio Code for our implementations and make calls to the Web API with the help of Swagger UI - an interface that lets you consume the API out-of-the-box, thanks to the latest version of the .NET framework.
Later, we will also utilize SQL Server Express and the SQL Server Management Studio to manage our database. These are also available for free.
The back-end application we’re going to build is a small text-based role-playing game where different users can register (we’re going to use JSON web tokens for authentication) and create their own characters like a mage or a knight, add some skills and a weapon, and also let the characters fight against each other to see who is the best of them all.
What You Will Learn
Introduction
Create your first Web API call in less than 10 minutes
Initialize a Git repository for your source control
Web API
The Model-View-Controller (MVC) pattern
Create models and controllers
Attribute routing (with parameters)
The HTTP request methods GET, POST, PUT & DELETE
Best practices for your Web API like a ServiceResponse class and Data-Transfer-Objects (DTOs)
Map your models with AutoMapper
Entity Framework Core
Object-Relational-Mapping
Code-First Migration
SQL Server Express
How to use a DataContext and a proper ConnectionString
All previous HTTP requests with Entity Framework Core to save your data in a SQL Server database
Data Seeding: Insert data with a migration programmatically
Authentication
Token Authentication with JSON Web Tokens
Claims
Secure controllers with the Authorize attribute
Add roles to the users
Advanced Relationships with Entity Framework Core
One-to-one relationships
One-to-many relationships
Many-to-many relationships
Include entities with Entity Framework Core
Get the proper relations between entities
More Than Just CRUD
Start automatic fights
Filter and order RPG characters by their highscore
This course has been completely re-recorded with .NET 7.
The lectures with the older versions of the .NET (Core) Framework - .NET 6, 5 & .NET Core 3.1 - are still available for reference.
Your Instructor
My name is Patrick and I will be your instructor for this course. I’m a web developer for over a decade now, I have worked for big corporations and small teams, as an employee and a contractor and I just love to see the way Microsoft is going with .NET and how important it gets day by day.
To this date, I was able to run ten courses on web development here on Udemy about ASP.NET, Blazor, single-page applications, Angular, and DevOps, with a total of over 75.000 unique students and more than 10.000 reviews.
If you have any questions, feel free to connect.
And if you still have any doubts, you have a 30-day money-back guarantee, no questions asked.
So, I hope you’re ready for your new skills and your new projects! ;)
I’m looking forward to seeing you in the course!
Course image: practicuum/Shutterstock