prjOne https://www.youtube.com/watch?v=6r9OSQdaAb4
Instance = (localdb)\MSSQLLocalDB
1. Asp.net core web app (razor pages ) using .net9.0
2. Add Model Folder
3. Sql query UserManagementCrudApp
CREATE TABLE Users (
Id INT IDENTITY(1,1) PRIMARY KEY,
FullName NVARCHAR(100) NOT NULL,
Email NVARCHAR(100) NOT NULL UNIQUE,
Role NVARCHAR(50) NOT NULL,
PhoneNumber NVARCHAR(20) NULL
);
Sql Query
List tables in db
SELECT name
FROM sys.tables;
Drop Table
DROP TABLE Users;
Model class
- Purpose: Imports attributes like [Required], [StringLength], and [EmailAddress] used for validation and data rules in the model.
using System.ComponentModel.DataAnnotations;
- Purpose: Declares a public class named User that will map to the Users table in the database and represent each row as an object.
public class User
{
}
- Purpose: Primary key for the table. Auto-incremented by SQL Server (IDENTITY(1,1) in SQL).
public int Id { get; set; }
4. Mvc razor pages crud
- select model class
- add dbContext class
5. Tools>nu-getManger>terminal
- add-migration initial
- update-database
#
6. Modify Index.cshtml insie User route folder to have boostarp layout such that rather than Index
X. Todo: since now all crating user , reading and updating and deleting can be don by anyone i want to add auth mening fist on index page of Users route user is crated modify MOdle class to have colum password then i will agian migrate and update after that so that after craeting user one can login on index page then