A complete code generation system for ASP.NET Core applications with Entity Framework, designed for exam scenarios without internet access.
# Start SQL Server container
./start-sql.sh
# The application will automatically create the database and tables on first run# Install dependencies
npm install
# Generate all models, controllers, and views
npm run generate:all
# Or generate specific parts
npm run generate:models # Entity models
npm run generate:context # DbContext
npm run generate:controllers # Controllers and viewscd AspPrep
dotnet runApplication will be available at https://localhost:5001
Default admin credentials are specified in generator/appdescription.ts under seedUsers.
Edit generator/appdescription.ts to define your entities, properties, and page operations:
const appDescription = {
entities: [
{
name: "Product",
table: "PRODUCTS",
properties: [
{
name: "Name",
type: "string",
required: true,
minLength: 3,
maxLength: 100,
regex: "^[A-Za-z0-9 ]+$"
},
{ name: "Price", type: "float", required: true, min: 0, max: 10000 },
{ name: "Category", type: "enum", required: true, options: ["Electronics", "Books", "Clothing"] }
]
}
],
roles: [
{ name: "Admin", setOnDefault: true }
],
pages: [
{
entity: "Product",
operations: [
{ type: "list" }, // Public access
{ type: "create", requiredRole: "Admin" }, // Admin only
{ type: "update", requiredRole: "Admin" },
{ type: "delete", requiredRole: "Admin" }
]
}
]
};- string: Text with min/max length validation or regex pattern
- int/float: Numbers with min/max value validation
- DateTime: Date and time picker
- boolean: Checkbox
- enum: Dropdown select with predefined options
Here are some regular expressions you can reuse in property definitions:
- Email:
^[^\s@]+@[^\s@]+\.[^\s@]+$ - Phone number:
^\+?[0-9]{10,15}$ - URL:
^(https?:\/\/)?[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#[\]@!$&'()*+,;=.]+$
- ✅ Entity models with data annotations
- ✅ DbContext with relationships
- ✅ CRUD controllers with role authorization
- ✅ Bootstrap-styled Razor views
- ✅ Client and server-side validation
- ✅ Pre-filled edit forms
- ✅ Confirmation dialogs for delete
# Add migration (if dotnet ef works)
cd AspPrep
dotnet ef migrations add MigrationName
# Or use the helper script
../create-migration.sh# Scaffold controller with views
dotnet aspnet-codegenerator controller \
-name ProductController \
-m Product \
-dc ApplicationDbContext \
--relativeFolderPath Controllers \
--useDefaultLayout \
--referenceScriptLibraries[Authorize(Roles = "Admin")]
public class ProductController : Controller
{
private readonly ApplicationDbContext _context;
public ProductController(ApplicationDbContext context)
{
_context = context;
}
public async Task<IActionResult> Index()
{
var products = await _context.Products.ToListAsync();
return View(products);
}
[HttpPost]
public async Task<IActionResult> Create(Product product)
{
if (ModelState.IsValid)
{
_context.Add(product);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
return View(product);
}
}// In controller or page model
var items = await _context.Products
.Where(p => p.IsActive)
.Include(p => p.Category)
.OrderBy(p => p.Name)
.ToListAsync();// Protect controller/action
[Authorize(Roles = "Admin")]
public IActionResult AdminOnly() { return View(); }
// Check user role in view
@if (User.IsInRole("Admin"))
{
<a href="/Admin/Dashboard">Admin Panel</a>
}# Scaffold Razor page
dotnet aspnet-codegenerator razorpage \
-name ProductPage \
-m Product \
-dc ApplicationDbContext \
--relativeFolderPath PagesCustom snippets are provided in AspPrep/.vscode/asp-prep.code-snippets:
- Type snippet prefix and press Tab
- Includes common controller actions, view templates, etc.
The application uses SQL Server by default. Connection string in AspPrep/appsettings.json:
{
"ConnectionStrings": {
"DefaultConnection": "Server=localhost,1455;Database=examen-paw;User Id=sa;Password=StrongPassword123!!!;TrustServerCertificate=true;"
}
}# Run with auto-restart on changes
cd AspPrep && dotnet watch run
# Build project
dotnet build
# Restore packages
dotnet restore
# View scaffolding help
dotnet aspnet-codegenerator --help├── AspPrep/ # ASP.NET Core application
│ ├── Models/ # Entity models (generated)
│ ├── Controllers/ # MVC controllers (generated)
│ ├── Views/ # Razor views (generated)
│ ├── Data/ # DbContext and migrations
│ └── wwwroot/ # Static files
├── generator/ # Code generation system
│ ├── appdescription.ts # Schema definition
│ ├── definitions.ts # Type definitions
│ ├── generate.ts # CLI generator
│ └── templates/ # Handlebars templates
└── start-sql.sh # SQL Server startup script
- Edit
generator/appdescription.tsto match exam requirements - Run
npm run generate:allto create all CRUD functionality - Use provided snippets for faster development
- All validation is automatically generated from schema
- Default admin user is pre-configured
- No internet required after initial setup
var humanCount = await _context.Participant
.CountAsync(p => p.AtelierId == item.AtelierId);
if (humanCount >= item.Atelier!.NrMaxParticipanti)
{
ModelState.AddModelError("AtelierId", "Atelierul a atins numarul maxim de participanti.");
return View();
}