A simple product catalog featuring:
- Backend – ASP.NET Core Web API + Entity Framework Core
- Frontend – Plain HTML, Bootstrap 5, and vanilla JavaScript
Copy‑and‑paste this README into your project root so teammates can run either side entirely from the command line.
| Tool | Check Installed | Install (if needed) |
|---|---|---|
| .NET SDK 6 or later | dotnet --version |
https://dotnet.microsoft.com/download |
| EF Core CLI | dotnet ef --version |
dotnet tool install --global dotnet-ef |
| SQL Server / LocalDB | Optional | https://aka.ms/sql-latest |
Repo layout (update if yours differs):
/backend ← Web API .csproj lives here /frontend ← index.html, script.js, etc.
# 1 – open a terminal at repo root
dcd backend
# 2 – restore packages
dotnet restore
# 3 – create or update DB (if first run)
dotnet ef database update # applies existing migrations
# └─ or ──> create a fresh migration:
# dotnet ef migrations add Init
# dotnet ef database update
# 4 – run API
dotnet runBy default Kestrel listens on:
https://localhost:7000 (HTTPS)
http://localhost:7001 (HTTP)
EF Core seeds three demo products in ApplicationDbContext.OnModelCreating(). Comment them out or change as you wish.
| Verb | Endpoint | Description |
|---|---|---|
| GET | /api/products |
List all products |
| GET | /api/products/{id} |
Get single product |
| POST | /api/products |
Add product (JSON body) |
| PUT | /api/products/{id} |
Update product |
| DELETE | /api/products/{id} |
Remove product |
Example POST payload:
{
"name": "Sample Phone",
"description": "A new phone",
"price": 49999,
"stock": 25,
"imageUrl": "https://example.com/phone.jpg"
}- Any modern browser
- (Optional) VS Code with the Live Server extension
# 1 – open second terminal at repo root
cd frontend
# 2 – simple Python web server (choose one)
python -m http.server 8080 # Python 3.x
# OR Live Server from VS Code (Recommended)Then visit http://localhost:8080.
Edit script.js:
const API_URL = 'https://localhost:7000/api/products';Change port if you altered Kestrel’s launch settings.
script.js already includes an onerror handler that swaps to a placeholder if an image fails to load.
# Run backend tests (if you add any)
dotnet test
# Add new EF migration
dotnet ef migrations add <Name>
# Re‑create the DB from scratch (destructive!)
dotnet ef database drop -f && dotnet ef database update| Issue | Fix | |
|---|---|---|
| Port 7000 already in use | Edit Properties/launchSettings.json or run `netstat -ano |
findstr :7000` and kill the process. |
| CORS error in browser | Ensure builder.Services.AddCors + app.UseCors("AllowFrontend") are enabled and that your frontend origin appears in WithOrigins(...). |
|
| EF precision warning | Price field is configured with HasPrecision(18,2)—no further action necessary. |
Bharath Kumar Bellam