
Develop a secure, scalable e-commerce web API with ASP.NET Core, featuring JWT authentication, role-based authorization, and CRUD services for contacts, products, orders, and users using SQL Server and Entity Framework.
Create an asp.net core web api project with dotnet nine, enable open api, and explore the project structure including controllers, program.cs, appsettings.json, and the middleware pipeline.
Run the secure web api, verify the listening port, set it to 4000, test with postman, display weather forecasts in an html table, and enable cors in program.cs.
Enable OpenAPI support and generate API documentation, define document names like v1 or doc, access via OpenAPI/v1.json, and visualize endpoints with Postman and the weather forecast example.
Generate and visualize API documentation for ASP.NET Core web APIs using OpenAPI, Swagger, and Swagger UI, and learn to configure endpoints and run documentation locally.
Configure OpenAPI Swagger to add the authorize button in Swagger UI, set up identity API across projects with Entity Framework Core and SQL Server, and create identity tables via migrations.
Configure OpenAPI to add the authorize button to Swagger UI, define an HTTP bearer security scheme, apply security requirements, and test with login tokens across multiple web API projects.
Create a users api controller with get all users, get user by id, and add, update, delete actions, operating on a private static list via id-based routes.
Use IActionResult to return diverse responses from ASP.NET Core Web API actions, handling list data, get by id, add, update, and delete with ok, not found, or no content results.
Create a user dto model in a models folder, define first name, last name, email, phone, and address, and enable create and update operations in an ASP.NET Core web API.
Apply data validation attributes to the user model via data annotations namespace, including required, email address, and minimum and maximum length with messages; controller enforces them on post and put.
Enforce custom data validation by checking email authorization at the start of add and update user methods, returning a bad request when the email equals user at example.com.
Disambiguate get user by id and get user by name endpoints using constraint route parameters, applying :int to the id route so both routes coexist without conflicts.
Explore how to use optional parameters to drive search queries in a get info action and return data when parameters are provided in an ASP.NET Core Web API.
Learn to define keys in appsettings.json and read them in Program.cs using builder.configuration, then display app name, language, country, and log settings.
Learn to read appsettings data in an ASP.NET Core web API controller by injecting IConfiguration via DI, and optionally [FromServices] for action-level access to app name, language, and log.
Create a time service with get date and get type, register it in the service container with add scoped, and inject it into a controller to display date and time.
Create and use inline middlewares in ASP.NET Core, placing them in the request pipeline to run before and after the controller and log the request duration to the console.
Create a class middleware in ASP.NET Core, wire it into the pipeline at the start, measure request duration, and observe console output for routes before and after the controller.
Create and register an action filter in ASP.NET Core that runs with every request like middleware and logs the current time in milliseconds.
Learn to implement a debug filter attribute in ASP.NET Core, decorate an action to execute the filter only for specific requests, and verify before and after controller execution.
Connect to a SQL Server database using Entity Framework and ASP.NET Core by creating an application DbContext, adding domain models and DbSet properties, then run migrations to update the database.
Contrast data transfer object models with domain models to show that dto handles client-server data exchange while domain models map to database tables, including id and Createdat.
install sql server express edition and locate the instance name to connect to sql server when building a secure web api for e-commerce with asp.net core.
Create a new ASP.NET Web API project, name it Best Store API, delete the default controller and model, and update launchSettings.json to set the https port to 4000.
Connect to SQL Server in Visual Studio, create a new database named Best Store via Server Explorer, and retrieve the connection string from the new database.
Install Entity Framework Core packages for SQL Server, add migrations, update the database, and enable Swagger support in a secure web API built with ASP.NET Core.
Create and configure the application db context as a service by adding a DbContext subclass in a services folder, wiring it to SQL Server via a connection string from appsettings.json.
Create domain models for contact and product with their properties, then add DbSet<Contact> contacts and DbSet<Product> products to the application db context to map the tables.
Create and migrate database tables for contacts and products in an ASP.NET Core api project, using the package manager console to add migrations, set price precision, and apply data annotations.
Delete and recreate database tables by running update-database 0, remove migrations, then add a new migration and update-database to restore contacts and products.
Compare code first and database first approaches for building a secure Web API for e-commerce using ASP.NET Core.
Implement CRUD operations for contacts by creating an API controller, injecting the application db context, and exposing routes to read all contacts and a contact by id.
Create a http post action in contacts controller to accept a validated contact DTO, map to a domain contact, handle nullable phone with ??, save changes, and return the contact.
update a contact via http put using route id, fetch contact from contacts table, handle not found, update fields from the contact dto, save changes, and return updated contact.
Implement a delete contact action using http delete with an id, removing the contact and saving changes, and compare two-query versus single-query approaches with not found handling.
Test the contacts controller endpoints with Swagger, creating, reading, updating, and deleting contacts. Validate responses, handle not found errors, and verify updates to email and phone fields.
Review the contact dto model in swagger's schema, used by the post and put endpoints, and inspect its properties defined in the models folder as the Contact Detox class.
Demonstrates exposing a subjects endpoint in an ASP.NET Core web API and validating contact submissions against an allowed subject list with proper error handling.
Define a subjects domain model and DbSet, convert contact subject to a navigation property with subjectId, and validate against the database for create, update, and retrieval using EF.
Learn to update the database with EF navigation properties by adding a subject id foreign key, seeding subjects, and using include to load subject data in contacts.
Explain adding pagination to the ContactsController in ASP.NET Core: introduce optional page, calculate total pages, order by id, apply skip and take, and return a paged result with page size.
Add email sender to the ASP.NET Core service container and inject it in the controller constructor. Configure API key, sender email, and sender name in appsettings.json using IConfiguration.
Create a products controller to read products via http get, using the application db context to return all products or a product by id.
Learn to implement a product DTO model in ASP.NET Core by recreating product properties for create and update, enforcing required fields, optional description, max length, and image uploads with IFormFile.
Enable static file serving in ASP.NET Core by configuring app.UseStaticFiles in program.cs, exposing the public three root folder and its images/products for front-end access.
Implement a post endpoint to create products in the products controller, validate optional image uploads, save images to the server, and persist the product via form data.
Delete a product via http delete by id, read product to delete its image, return not found if missing, delete from database, save changes, and verify by deleting id 2.
Define authorized categories list in the products controller and expose it via a categories endpoint. Validate create and update requests against this list, returning a bad request for invalid categories.
Implement and test the ProductsController search by composing a query with optional keywords, category, and price range filters, and verify results after populating the products table.
Demonstrates adding optional sort and order parameters to the ProductsController to sort products by name, brand, category, price, or date (created at), with defaults and validation, and introduces pagination.
Implement an optional page parameter that defaults to the first page, validate the page, use a five item page size, and return an object with products, total pages, and the requested page.
Understand json web tokens as three-part tokens (header, payload, signature) with claims, created after login, stored securely in the browser, and used by the server to authenticate and authorize roles.
Create a user domain model and a users table to enable authentication and authorization, with encrypted password, unique email, max-length constraints, add a DbSet in the context, and run migrations.
Create an account controller to register and authenticate users, issue a json web token with user id and role, signed from appsettings, and provide a test endpoint.
Define user dto and user profile dto to handle account creation: receive clear text password, store encrypted, and return a password-free confirmation to the client.
Registers a new user via a post endpoint in account controller, validates unique emails, hashes passwords, creates a client user, issues a JWT, and returns the user profile.
authorizes users via login endpoint in account controller by validating email and password, returning a json web token and user profile on success.
Configure swagger to enable oauth two authentication and use json web token authentication via an options block in program.cs, then authorize with a bearer token to protect a route.
Add user authorization to a new protected route in an ASP.NET Core API by using the authorize attribute and configuring JWT bearer authentication in program.cs.
Enable role-based authorization in an ASP.NET Core web API for e-commerce by securing routes with admin and admin or seller roles, enforcing JWT role claims and testing with tokens.
Learn to read JWT claims from request by using the authorize attribute and casting the user identity to claims identity, collecting name-value pairs into a dictionary returned as the response.
Explore reset password flow: the front end requests a forgot password link by email, the server issues a token, and the user submits the token with a password and confirmation.
Create a password resets table by modeling password reset with id, email, token, created at. Make email unique with an index, connect to the application db context, and migrate.
Create a password reset endpoint in the account controller that accepts an email, validates the user, generates a random token, saves it, and emails it with the email sender.
Create an http post action in the account controller to reset a password with a token and new password; validate token, update the password, delete the token, and return success.
Create a protected profile endpoint in account controller that reads the authenticated user's ID from the JWT claims, fetches the user from the database, and returns a user profile object.
Create a dedicated user profile update dto and a protected http put action that reads the user id from claims, updates name, email, phone, and address, and returns updated profile.
The lecture shows how to implement a protected put endpoint to update a user's password in ASP.NET Core, including user validation, authorization, password encryption, and saving changes.
Protect endpoints in the contacts and products controllers by applying the authorize attribute with the admin role, enforcing admin-only create, update, and delete actions while allowing public reads where appropriate.
Create an admin-only UsersController in an ASP.NET Core API with a read users endpoint that returns profiles without passwords, ordered by id descending (newest first).
Add pagination to the users list by introducing a page parameter and a fixed page size of five; implement skip/take to return the requested page along with total pages.
Create a get action in the UsersController to read a user by id, find it in the database, and return a user profile or not found.
Move the private get user id method to a new static service class GW reader in the services folder, exposing get user id, get user role, and get user claims.
Build an order helper with a static method that converts a hyphen separated product id string into a dictionary of id and quantity, and define shipping fee and payment options.
Define cart item dto with product details and quantity, and a cart dto with a list of items, subtotal, shipping fee, and total price for the cart summary.
Create a cart controller with a get cart endpoint that converts a product identifiers string to a dictionary via order helper and returns a cart summary.
Add an http get endpoint in the cart controller to fetch the acceptable payment methods from the order helper for the front end to display with cart totals.
Define domain models and database tables for contacts, subjects, products, users, password resets, and for orders and order items, including foreign keys, navigation properties, and unit price.
Create order item and order domain models with properties and navigation, configure EF Core mappings, add db sets, and generate a fifth migration to update the database.
Create a CartDto model to receive order data, with product identifiers, delivery address, and payment method, all marked as required and constrained by length where applicable.
Build a secured create order endpoint in ASP.NET Core, validating payment methods with the order helper, using the user id from JWT, and persisting orders with items to the database.
Protect the read orders api with authorize, and implement admin versus client access using jwt reader to fetch user id and role, loading related orders, users, items, and products.
Implement pagination for the orders endpoint by adding a page parameter, validating it, and returning a paged result with skipped orders, total pages, page size, and the current page.
Implement a protected read order by id action via http get, using a route parameter id and json web token based roles to include user, order items, and products.
Explains building a secure update orders endpoint in ASP.NET Core, protected by admin only authorization, updating payment and order states via HTTP PUT with validation and database save.
Secure delete order endpoint with authorize attribute for admin in orders controller, accepting order id via http delete; deletion cascades to items, saves changes, and returns an empty success response.
Learn to implement user registration, authentication, and role-based authorization in ASP.NET web APIs using identity API and bearer tokens.
Create an asp.net core web api project named 'My store', enable https and controllers, configure swagger, set up a sql server db and identity with entity framework, run migrations.
Add identity services to the service container and enable identity endpoints in the pipeline, configuring program.cs after adding the dbcontext and testing register, login, and user details with tokens.
Configure public and private endpoints in an ASP.NET Core API, using bearer authentication to access the user profile and return identity details.
Test the login form by posting the email and password to the API and confirm an access token on success, or an error on failure after enabling a CORS policy.
Create roles and implement role-based authorization by replacing the identity user with a custom application user, seed roles and a default admin, and test login with tokens.
Register custom users by defining a register dto with required first name, last name, email, and password, plus optional phone and address, and expose a /signup endpoint that assigns roles.
Demonstrates role-based authorization in a secure web api by protecting routes in the account controller, exposing admin and client routes that return hello admin and hello client using access tokens.
Create a sql client workflow to perform CRUD operations and build an asp.net core web api by creating a web app database and a products table with id primary key.
Create an api controller for product CRUD operations, read appsettings connection string via IConfiguration, and define product dto and product models with required fields: name, brand, category, price, and description.
Create a post endpoint that adds products via a product D2 object, inserting into the products table with sql and returning bad request on errors.
Create an http get action named getproducts to read all products from a database, map each row to a product object, return the list, and use try-catch for errors.
Implement a SqlClient read-by-id endpoint in an asp.net core web API for e-commerce, using http get, route parameter, sql connection, and data reader with not found and bad request handling.
Create a put endpoint to update products in the ASP.NET Core Web API, using the product id and object to update name, brand, category, price, and description.
Implement a delete product endpoint in an asp.net core web api using sql client, with http delete and id route, parameterized delete query, and error handling.
Learn dapper basics in an ASP.NET Core Web API to perform product CRUD, install Dapper and SQL Client packages, and configure a connection string for mapping tables to C# objects.
Create domain and data transfer models for a product using dapper in asp.net core, including properties for id, name, brand, category, price, description, and created at, with validation attributes.
Create a new api controller with dapper to perform CRUD on products, reading the connection string from appsettings.json, handling create with http post and returning the created product.
Build a read endpoint with Dapper that returns all products via Http get, handling SQL connection, query execution, and exceptions to return a success response with the products.
Read a product by id via an http get endpoint, read from the database using Dapper's query single or default, and return the product or not found.
Update a product via http put by reading id from the url and returning the updated product after updating name, brand, category, price, and description with Dapper and SQL.
Implement a delete product endpoint with http delete and a url parameter id, using Dapper to execute a delete from products and return not found if none deleted.
This course is for Beginners to ASP.NET having some knowledge of C# or similar programming languages.
In this course, you will learn how to build a complete Web API using ASP.NET. I will show you how to build a secure and professional backend application for E-Commerce.
We will use Visual Studio 2022 to connect to the SQL Server. So we don’t need to install SSMS (SQL Server Management Studio).
In this course, you will learn:
- How to create an ASP.NET Web API
- How to connect to SQL Server using Visual Studio 2022
- How to create API Controllers
- How to Create Endpoints and action methods
- How to create and use Middlewares
- How to create and use Filters
- How to validate forms using attributes and how to add custom validation
- How to send emails using ASP.NET and SendGrid
- How to Implement Authentication, Authorization and Role based Authorization using Json Web Tokens (JWT)
- How to reset user password
- How to perform CRUD operations (Create, Read, Update and Delete) on the database using Entity Framework and other frameworks
- How to implement pagination, search and sort functionalities
- How to upload images to the server
To follow this course, you need to install the following tools
- Visual Studio 2022
- Microsoft SQL Server