Lab Manual - DotNet (CS-406) May 2025
Lab Manual - DotNet (CS-406) May 2025
JABALPUR
LAB MANUAL
(CS-406)
NAME:
ENROLLMENT NUMBER:
SESSION: 2024-25
Page 1 of 56
Subject Name: Programming Practices (b) (DotNet)
Subject Code: [CS-406]
Index
S. Experiment Date of Sign Remarks
No. Performance
Page 2 of 56
Evaluation Sheet
Student Name :
Student Roll No.:
Subject Name :
Subject Code:
Practical
Record Execution & Record
Completion Result Viva Submission
(6 marks) (6 marks) (4 marks) (4 marks)
Complete Record Record
4 Total
Proper Output Answer
S. with correct 6 for all program 6 Correctly 4 submitted in
Name of Experiment syntax time out of
No Complete Record Proper Output Answer Record not 20
with improper 4 for some 4 Satisfactori 2 submitted in 2
syntax program ly time
Partially Complete Unable to Record Not
Record 2 Partial Output 2 Answer 0 Submitted 0
Output not
Incomplete Record 0 shown 0
Create Web Application as Login
1 page in [Link] using database
connectivity.
Create a Registration Page on
[Link] to insert, update, delete
2 and search a record using Data
controls.
Create a Windows Based
3 Application using .Net framework
Create a project on Console
4 application of Employee
Management System.
Create a [Link] core application
5 for supporting multiple platform.
Create a Razor page web
6 application available in [Link]
core templates.
Create a Quiz Application with
7 [Link] MVC in [Link] core
Grand Total
Marks out of 20
Page 3 of 56
Experiment-1
[Link] Web Application for a Login Page using C# with SQL Server Database
Connectivity.
Features:
Code Implementation
Page 4 of 56
Replace YOUR_SERVER_NAME with your actual SQL Server name.
</head>
<body>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-4">
<h2 class="text-center">Login</h2>
<asp:Label ID="lblMessage" runat="server" ForeColor="Red"></asp:Label>
<div class="mb-3">
<label>Email</label>
<asp:TextBox ID="txtEmail" runat="server" CssClass="form-
control"></asp:TextBox>
</div>
<div class="mb-3">
<label>Password</label>
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password"
CssClass="form-control"></asp:TextBox>
</div>
<asp:Button ID="btnLogin" runat="server" Text="Login" CssClass="btn btn-
primary w-100" OnClick="btnLogin_Click" />
</div>
</div>
</div>
</body>
</html>
5 [Link]
using System;
public partial class Dashboard : [Link]
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserEmail"] == null)
{
[Link]("[Link]");
}
else
{
[Link] = Session["UserEmail"].ToString();
}
}
protected void btnLogout_Click(object sender, EventArgs e)
{
[Link]();
[Link]("[Link]");
}
}
How It Works
Page 7 of 56
Experiment- 02
Create a Registration Page on [Link] to insert, update, delete and search a record using
Data controls.
[Link] Web Application with a Registration Page that allows users to insert, update,
delete, and search records in a SQL Server database using C#.
Features
Run this SQL script to create the Users table in SQL Server:
<connectionStrings>
<add name="MyDB" connectionString="Data
Source=YOUR_SERVER_NAME;Initial Catalog=UserDB;Integrated Security=True"
providerName="[Link]"/>
</connectionStrings>
Page 8 of 56
Replace YOUR_SERVER_NAME with your actual SQL Server name.
<!DOCTYPE html>
<html>
<head>
<title>Registration Page</title>
<link rel="stylesheet"
href="[Link] />
</head>
<body>
<div class="container mt-5">
<h2 class="text-center">User Registration</h2>
<asp:Label ID="lblMessage" runat="server" ForeColor="Red"></asp:Label>
<div class="mb-3">
<label>Full Name</label>
<asp:TextBox ID="txtFullName" runat="server" CssClass="form-
control"></asp:TextBox>
</div>
<div class="mb-3">
<label>Email</label>
<asp:TextBox ID="txtEmail" runat="server" CssClass="form-
control"></asp:TextBox>
</div>
<div class="mb-3">
<label>Password</label>
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password"
CssClass="form-control"></asp:TextBox>
</div>
<div class="mb-3">
<label>Phone</label>
<asp:TextBox ID="txtPhone" runat="server" CssClass="form-
control"></asp:TextBox>
</div>
Page 9 of 56
<asp:Button ID="btnSearch" runat="server" Text="Search" CssClass="btn btn-
secondary" OnClick="btnSearch_Click" />
<div class="mt-3">
<h4>Users List</h4>
<asp:GridView ID="GridView1" runat="server" CssClass="table table-bordered"
AutoGenerateColumns="False" DataKeyNames="Id">
<Columns>
<asp:BoundField DataField="Id" HeaderText="ID" />
<asp:BoundField DataField="FullName" HeaderText="Full Name" />
<asp:BoundField DataField="Email" HeaderText="Email" />
<asp:BoundField DataField="Phone" HeaderText="Phone" />
</Columns>
</asp:GridView>
</div>
</div>
</body>
</html>
// INSERT RECORD
protected void btnSave_Click(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection(connString))
{
string query = "INSERT INTO Users (FullName, Email, Password, Phone)
VALUES (@FullName, @Email, @Password, @Phone)";
Page 10 of 56
SqlCommand cmd = new SqlCommand(query, conn);
[Link]("@FullName", [Link]);
[Link]("@Email", [Link]);
[Link]("@Password", [Link]);
[Link]("@Phone", [Link]);
[Link]();
[Link]();
[Link]();
// UPDATE RECORD
protected void btnUpdate_Click(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection(connString))
{
string query = "UPDATE Users SET FullName=@FullName,
Password=@Password, Phone=@Phone WHERE Email=@Email";
SqlCommand cmd = new SqlCommand(query, conn);
[Link]("@FullName", [Link]);
[Link]("@Email", [Link]);
[Link]("@Password", [Link]);
[Link]("@Phone", [Link]);
[Link]();
int rowsAffected = [Link]();
[Link]();
// DELETE RECORD
protected void btnDelete_Click(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection(connString))
{
string query = "DELETE FROM Users WHERE Email=@Email";
SqlCommand cmd = new SqlCommand(query, conn);
[Link]("@Email", [Link]);
[Link]();
Page 11 of 56
int rowsAffected = [Link]();
[Link]();
// SEARCH RECORD
protected void btnSearch_Click(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection(connString))
{
string query = "SELECT * FROM Users WHERE Email=@Email";
SqlCommand cmd = new SqlCommand(query, conn);
[Link]("@Email", [Link]);
[Link]();
SqlDataReader reader = [Link]();
if ([Link]())
{
[Link] = reader["FullName"].ToString();
[Link] = reader["Password"].ToString();
[Link] = reader["Phone"].ToString();
[Link] = "User found!";
}
else
{
[Link] = "User not found!";
}
[Link]();
}
}
Page 13 of 56
Experiment- 03
Prerequisites
Page 14 of 56
<add name="MyDB" connectionString="Data
Source=YOUR_SERVER_NAME;Initial Catalog=UserDB;Integrated Security=True"
providerName="[Link]"/>
</connectionStrings>
</configuration>
Replace YOUR_SERVER_NAME with your actual SQL Server instance name.
namespace WinFormsCRUD
{
public partial class Form1 : Form
{
string connString =
[Link]["MyDB"].ConnectionString;
public Form1()
{
InitializeComponent();
LoadUsers();
}
// Insert Record
private void btnInsert_Click(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection(connString))
{
string query = "INSERT INTO Users (FullName, Email, Phone) VALUES
(@FullName, @Email, @Phone)";
SqlCommand cmd = new SqlCommand(query, conn);
Page 15 of 56
[Link]("@FullName", [Link]);
[Link]("@Email", [Link]);
[Link]("@Phone", [Link]);
[Link]();
[Link]();
[Link]();
[Link]("User added successfully!");
LoadUsers();
}
}
// Update Record
private void btnUpdate_Click(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection(connString))
{
string query = "UPDATE Users SET FullName=@FullName, Phone=@Phone
WHERE Email=@Email";
SqlCommand cmd = new SqlCommand(query, conn);
[Link]("@FullName", [Link]);
[Link]("@Email", [Link]);
[Link]("@Phone", [Link]);
[Link]();
int rowsAffected = [Link]();
[Link]();
[Link](rowsAffected > 0 ? "User updated successfully!" : "User
not found!");
LoadUsers();
}
}
// Delete Record
private void btnDelete_Click(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection(connString))
{
string query = "DELETE FROM Users WHERE Email=@Email";
SqlCommand cmd = new SqlCommand(query, conn);
[Link]("@Email", [Link]);
[Link]();
int rowsAffected = [Link]();
[Link]();
[Link](rowsAffected > 0 ? "User deleted successfully!" : "User not
found!");
Page 16 of 56
LoadUsers();
}
}
// Search Record
private void btnSearch_Click(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection(connString))
{
string query = "SELECT * FROM Users WHERE Email=@Email";
SqlCommand cmd = new SqlCommand(query, conn);
[Link]("@Email", [Link]);
[Link]();
SqlDataReader reader = [Link]();
if ([Link]())
{
[Link] = reader["FullName"].ToString();
[Link] = reader["Phone"].ToString();
[Link]("User found!");
}
else
{
[Link]("User not found!");
}
[Link]();
}
}
// Load Users into DataGridView
private void LoadUsers()
{
using (SqlConnection conn = new SqlConnection(connString))
{
string query = "SELECT Id, FullName, Email, Phone FROM Users";
SqlDataAdapter da = new SqlDataAdapter(query, conn);
DataTable dt = new DataTable();
[Link](dt);
[Link] = dt;
}
}
}
}
Page 17 of 56
6. Run the Application
1. Start the application (Press F5).
2. Enter user details → Click Insert to add.
3. Enter email → Click Search to find a user.
4. Modify details → Click Update.
5. Delete a user by entering email and clicking Delete.
Features Implemented
✔ Insert new users
✔ Update user details
✔ Delete user records
✔ Search users by email
✔ Display all users in DataGridView
Page 18 of 56
Experiment- 04
Features
✅ Add Employee
✅ Update Employee Details
✅ Delete Employee
✅ Search Employee
✅ Display All Employees
This project uses C# and a SQL Server database for storing employee records.
Page 19 of 56
3. Add Database Connection
<configuration>
<connectionStrings>
<add name="MyDB" connectionString="Data
Source=YOUR_SERVER_NAME;Initial Catalog=EmployeeDB;Integrated
Security=True" providerName="[Link]"/>
</connectionStrings>
</configuration>
class Program
{
static string connString =
[Link]["MyDB"].ConnectionString;
switch ([Link]())
Page 20 of 56
{
case "1":
AddEmployee();
break;
case "2":
UpdateEmployee();
break;
case "3":
DeleteEmployee();
break;
case "4":
SearchEmployee();
break;
case "5":
DisplayEmployees();
break;
case "6":
return;
default:
[Link]("Invalid choice. Try again.");
break;
}
}
}
[Link]();
[Link]();
[Link]();
[Link]();
int rowsAffected = [Link]();
[Link]();
Page 22 of 56
[Link](rowsAffected > 0 ? "Employee updated successfully!" :
"Employee not found.");
}
}
[Link]();
int rowsAffected = [Link]();
[Link]();
[Link]();
SqlDataReader reader = [Link]();
if ([Link]())
{
[Link]("\n--- Employee Details ---");
[Link]($"ID: {reader["Id"]}");
[Link]($"Name: {reader["Name"]}");
Page 23 of 56
[Link]($"Age: {reader["Age"]}");
[Link]($"Department: {reader["Department"]}");
[Link]($"Salary: {reader["Salary"]}");
}
else
{
[Link]("Employee not found.");
}
[Link]();
}
}
static void DisplayEmployees()
{
using (SqlConnection conn = new SqlConnection(connString))
{
string query = "SELECT * FROM Employees";
SqlDataAdapter da = new SqlDataAdapter(query, conn);
DataTable dt = new DataTable();
[Link](dt);
Page 24 of 56
Features Implemented
Page 25 of 56
Experiment- 05
Features
Prerequisites
Page 26 of 56
2. Install Dependencies
Modify [Link]:
"ConnectionStrings": {
"DefaultConnection":
"Server=YOUR_SERVER_NAME;Database=MultiPlatformDB;Trusted_Connection=Tr
ue;"
}
4. Create Models
Page 27 of 56
5. Create Database Context
[Link]([Link]("DefaultConnection"))
);
[Link]();
var app = [Link]();
[Link]();
[Link]();
[Link]();
Page 28 of 56
Edit Pages/Users/[Link]:
using [Link];
using [Link];
using [Link];
using [Link];
public class IndexModel : PageModel
{
private readonly ApplicationDbContext _context;
public IndexModel(ApplicationDbContext context)
{
_context = context;
}
public IList<User> Users { get; set; }
public async Task OnGetAsync()
{
Users = await _context.[Link]();
}
}
Edit Pages/Users/[Link]:
@page
@model [Link]
<h2>Users List</h2>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
</tr>
@foreach (var user in [Link])
{
<tr>
<td>@[Link]</td>
<td>@[Link]</td>
<td>@[Link]</td>
</tr>
}
</table>
Page 29 of 56
8. Running the Application
Cross-Platform Support
✅ Works on:
Features Implemented
Page 30 of 56
Experiment- 06
This guide will walk you through building an [Link] Core Razor Pages Web
Application using C# and Entity Framework Core (EF Core) for database operations.
Features
Prerequisites
Modify [Link]:
"ConnectionStrings": {
"DefaultConnection":
"Server=YOUR_SERVER_NAME;Database=RazorAppDB;Trusted_Connection=True;
MultipleActiveResultSets=true"
}
Modify [Link]:
Page 32 of 56
using [Link];
var builder = [Link](args);
// Add Database Context
[Link]<ApplicationDbContext>(options =>
[Link]([Link]("DefaultConnection"))
);
[Link]();
var app = [Link]();
[Link]();
[Link]();
[Link]();
[Link]();
Modify Pages/Employees/[Link]:
using [Link];
using [Link];
using [Link];
using [Link];
public class IndexModel : PageModel
{
private readonly ApplicationDbContext _context;
Modify Pages/Employees/[Link]:
Page 33 of 56
@page
@model [Link]
@{
ViewData["Title"] = "Employees";
}
<h2>Employee List</h2>
<a asp-page="Create" class="btn btn-primary">Add Employee</a>
<table class="table">
<tr>
<th>ID</th>
<th>Name</th>
<th>Position</th>
<th>Salary</th>
<th>Actions</th>
</tr>
@foreach (var employee in [Link])
{
<tr>
<td>@[Link]</td>
<td>@[Link]</td>
<td>@[Link]</td>
<td>@[Link]</td>
<td>
<a asp-page="Edit" asp-route-id="@[Link]" class="btn btn-
warning">Edit</a>
<a asp-page="Delete" asp-route-id="@[Link]" class="btn btn-
danger">Delete</a>
</td>
</tr>
}
</table>
Modify Pages/Employees/[Link]:
using [Link];
using [Link];
using [Link];
public class CreateModel : PageModel
{
private readonly ApplicationDbContext _context;
_context.[Link](Employee);
await _context.SaveChangesAsync();
return RedirectToPage("Index");
}
}
Modify Pages/Employees/[Link]:
@page
@model [Link]
<h2>Add Employee</h2>
<form method="post">
<label>Name:</label>
<input asp-for="[Link]" class="form-control" />
<label>Position:</label>
<input asp-for="[Link]" class="form-control" />
<label>Salary:</label>
<input asp-for="[Link]" class="form-control" />
<button type="submit" class="btn btn-success">Create</button>
</form>
Features Implemented
Page 35 of 56
Experiment-07
Creating a Quiz Application using [Link] Core MVC with C# involves setting up a
web application that allows users to take quizzes, view questions, submit answers, and
view results. Below is a basic walkthrough to get you started.
Tech Stack:
Project Structure
QuizApp/
│
├── Controllers/
│ └── [Link]
│
├── Models/
│ ├── [Link]
│ ├── [Link]
│ └── [Link]
│
├── Views/
│ └── Quiz/
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ └── [Link]
│
├── Data/
Page 36 of 56
│ └── [Link]
│
├── [Link]
├── [Link]
└── [Link] (or inside [Link] in .NET 6+)
1. Create Models
[Link]
public class Quiz
{
public int Id { get; set; }
public string Title { get; set; }
public List<Question> Questions { get; set; }
}
[Link]
public class Question
{
public int Id { get; set; }
public string Text { get; set; }
public int QuizId { get; set; }
public Quiz Quiz { get; set; }
public List<Answer> Answers { get; set; }
}
[Link]
public class Answer
{
public int Id { get; set; }
public string Text { get; set; }
public bool IsCorrect { get; set; }
public int QuestionId { get; set; }
public Question Question { get; set; }
}
2. Set Up DbContext
[Link]
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) :
base(options) {}
Page 37 of 56
public DbSet<Quiz> Quizzes { get; set; }
public DbSet<Question> Questions { get; set; }
public DbSet<Answer> Answers { get; set; }
}
3. Configure Database in [Link] or [Link]
[Link]<ApplicationDbContext>(options =>
[Link]("Data Source=[Link]")); // or UseSqlServer
4. Create QuizController
[Link]
public class QuizController : Controller
{
private readonly ApplicationDbContext _context;
Page 38 of 56
[Link] = score;
[Link] = [Link];
return View("Result");
}
}
5. Create Views
Views/Quiz/[Link]
@model IEnumerable<Quiz>
<h2>Available Quizzes</h2>
@foreach (var quiz in Model)
{
<div>
<h3>@[Link]</h3>
<a asp-action="Start" asp-route-id="@[Link]">Start Quiz</a>
</div>
}
Views/Quiz/[Link]
@model Quiz
<form asp-action="Submit" method="post">
@foreach (var question in [Link])
{
<div>
<h4>@[Link]</h4>
@foreach (var answer in [Link])
{
<input type="radio" name="answers[@[Link]]" value="@[Link]" />
@[Link] <br />
}
</div>
}
<button type="submit">Submit Quiz</button>
</form>
Views/Quiz/[Link]
<h2>Quiz Completed!</h2>
<p>Your Score: @[Link] / @[Link]</p>
<a href="/">Back to Quizzes</a>
6. Database Migration
dotnet ef migrations add InitialCreate
dotnet ef database update
Page 39 of 56
Experiment-08
Creating a Web API (REST Service) using [Link] Core and C# is a common way to
expose data and functionality over HTTP for frontend apps, mobile apps.
Project Overview
Models/[Link]:
namespace [Link]
{
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
}
}
Data/[Link]:
using [Link];
using [Link];
namespace [Link]
{
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options) {}
// Register EF Core
[Link]<ApplicationDbContext>(options =>
[Link]("Data Source=[Link]"));
// Register services
[Link]();
// Middleware
[Link]();
[Link]();
[Link]();
// Create DB on startup
using (var scope = [Link]())
{
var db = [Link]<ApplicationDbContext>();
[Link]();
}
[Link]();
Controllers/[Link]:
using [Link];
using [Link];
using [Link];
using [Link];
namespace [Link]
{
[Route("api/[controller]")]
[ApiController]
Page 41 of 56
public class ProductsController : ControllerBase
{
private readonly ApplicationDbContext _context;
[HttpGet]
public async Task<ActionResult<IEnumerable<Product>>> GetProducts()
{
return await _context.[Link]();
}
[HttpGet("{id}")]
public async Task<ActionResult<Product>> GetProduct(int id)
{
var product = await _context.[Link](id);
if (product == null)
return NotFound();
return product;
}
[HttpPost]
public async Task<ActionResult<Product>> PostProduct(Product product)
{
_context.[Link](product);
await _context.SaveChangesAsync();
return CreatedAtAction(nameof(GetProduct), new { id = [Link] }, product);
}
[HttpPut("{id}")]
public async Task<IActionResult> PutProduct(int id, Product product)
{
if (id != [Link])
return BadRequest();
_context.Entry(product).State = [Link];
await _context.SaveChangesAsync();
return NoContent();
}
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteProduct(int id)
{
var product = await _context.[Link](id);
if (product == null)
Page 42 of 56
return NotFound();
_context.[Link](product);
await _context.SaveChangesAsync();
return NoContent();
}
}
}
• Postman
• curl
• Swagger (enabled by default in new projects)
Page 43 of 56
Experiment-09
Create a Blazor Web App that support both server side rendering and client
interactivity.
To create a Blazor Web App that supports both server-side rendering (SSR) and client-
side interactivity, you’ll use the Blazor Web App template introduced in .NET 8. This
combines the power of Razor Components (SSR) with the interactivity of Blazor
WebAssembly (WASM) using Blazor Server + WebAssembly Hybrid (Auto mode).
Prerequisites
• .NET 8 SDK
• Visual Studio 2022 (v17.8+) or VS Code
Project Setup
1. Create the Project
dotnet new blazor --name BlazorHybridApp --output BlazorHybridApp
cd BlazorHybridApp
Page 44 of 56
Key Features
[Link]
Pages/[Link]
@page "/"
<h1>Hello from Blazor Web App!</h1>
<HelloWorld />
Components/[Link]
<h3>Hello from a component!</h3>
@code {
private int count = 0;
This component is server-rendered on first load and becomes interactive on the client.
Page 45 of 56
.AddInteractiveServerComponents()
.AddInteractiveWebAssemblyComponents();
[Link]();
[Link]();
[Link]<App>()
.AddInteractiveServerRenderMode()
.AddInteractiveWebAssemblyRenderMode();
[Link]();
You can modify [Link] or rendering modes in [Link] to control how each
component renders.
Page 46 of 56
Experiment-10
Creating a User Staff Registration System in [Link] Core MVC (C#) and
deploying it to a web server involves:
Project Overview
Features
Models/[Link]:
using [Link];
[Required]
[Display(Name = "Full Name")]
public string FullName { get; set; }
[Required]
[EmailAddress]
public string Email { get; set; }
[Required]
[Phone]
public string Phone { get; set; }
[Required]
[Display(Name = "Department")]
public string Department { get; set; }
}
Data/[Link]:
using [Link];
Page 48 of 56
4. Configure [Link] for DB Access
[Link]<ApplicationDbContext>(options =>
[Link]("Data Source=[Link]")); // Or use SQL Server
Controllers/[Link]:
using [Link];
using [Link];
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(Staff staff)
{
if ([Link])
Page 49 of 56
{
_context.Add(staff);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
return View(staff);
}
[HttpPost]
public async Task<IActionResult> Edit(int id, Staff staff)
{
if (id != [Link]) return NotFound();
if ([Link])
{
_context.Update(staff);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
return View(staff);
}
Page 50 of 56
}
[HttpPost, ActionName("Delete")]
public async Task<IActionResult> DeleteConfirmed(int id)
{
var staff = await _context.[Link](id);
_context.[Link](staff);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
}
Views/Staff/:
• [Link]
• [Link]
• [Link]
• [Link]
Deployment Options
Page 51 of 56
Option 1: Deploy to IIS
Page 52 of 56
Experiment-11
To create a User Staff Registration system using [Link] Core (C#) and deploy it
on IIS, covers project creation, code implementation, database setup, and IIS
deployment.
Project Overview
Features:
Models/[Link]:
using [Link];
[Required]
[Display(Name = "Full Name")]
public string FullName { get; set; }
[Required]
[EmailAddress]
public string Email { get; set; }
[Required]
[Phone]
public string Phone { get; set; }
[Required]
Page 53 of 56
public string Department { get; set; }
}
Data/[Link]:
using [Link];
[Link]:
[Link]<ApplicationDbContext>(options =>
[Link]("Data Source=[Link]")); // Or UseSqlServer()
Also add:
[Link]();
Controllers/[Link]:
using [Link];
using [Link];
[HttpPost]
[ValidateAntiForgeryToken]
Page 54 of 56
public async Task<IActionResult> Create(Staff staff)
{
if ([Link])
{
_context.Add(staff);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
return View(staff);
}
[HttpPost]
public async Task<IActionResult> Edit(int id, Staff staff)
{
if (id != [Link]) return NotFound();
if ([Link])
{
_context.Update(staff);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
return View(staff);
}
[HttpPost, ActionName("Delete")]
public async Task<IActionResult> DeleteConfirmed(int id)
{
var staff = await _context.[Link](id);
_context.[Link](staff);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}}
7 Setup Database
Run migrations:
dotnet ef migrations add InitialCreate
dotnet ef database update
9 Deploy to IIS
Prerequisites
Browse Site