Skip to main content

Development Environment Setup

This guide will help you set up the Sistema de Seguimiento de Solicitudes project on your local machine for development.

Prerequisites

Required Software

1. .NET SDK 9.0 or later

Download: https://dotnet.microsoft.com/download Verify Installation:
dotnet --version
# Should output: 9.0.x or later

2. SQL Server

Options:
  • SQL Server Express (Free) - Recommended for development
  • SQL Server Developer Edition (Free)
  • SQL Server LocalDB (Lightweight)
Download: https://www.microsoft.com/en-us/sql-server/sql-server-downloads Verify Installation:
# Check if SQL Server is running
sqlcmd -S (local) -Q "SELECT @@VERSION"

3. IDE or Code Editor

Recommended: Alternative: Or:

Optional Tools

SQL Server Management Studio (SSMS)

Purpose: Database management and querying Download: https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms

Azure Data Studio

Purpose: Cross-platform database tool Download: https://docs.microsoft.com/en-us/sql/azure-data-studio/download

Postman or similar API client

Purpose: Testing API endpoints Download: https://www.postman.com/downloads/

Project Setup

1. Clone the Repository

git clone <repository-url>
cd "Sistema de Seguimiento de Solicitudes"

2. Restore NuGet Packages

# Restore all projects
dotnet restore
This will restore packages for all three projects:
  • Sistema de Seguimiento de Solicitudes (Frontend)
  • SolicitudesAPI (Backend)
  • SolicitudesShared (Shared library)

3. Database Setup

Option A: Using SQL Server Express/Developer

Step 1: Create Database
CREATE DATABASE SistemaSolicitudes;
Step 2: Configure Connection String Edit SolicitudesAPI/appsettings.json:
{
  "ConnectionStrings": {
    "DefaultConnection": "Server=(local);Database=SistemaSolicitudes;Trusted_Connection=True;TrustServerCertificate=True;"
  }
}
For named instance:
"DefaultConnection": "Server=(local)\\SQLEXPRESS;Database=SistemaSolicitudes;Trusted_Connection=True;TrustServerCertificate=True;"
For SQL Authentication:
"DefaultConnection": "Server=(local);Database=SistemaSolicitudes;User Id=your_username;Password=your_password;TrustServerCertificate=True;"

Option B: Using SQL Server LocalDB

Connection String:
{
  "ConnectionStrings": {
    "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=SistemaSolicitudes;Trusted_Connection=True;TrustServerCertificate=True;"
  }
}
Step 3: Run Migrations
cd SolicitudesAPI
dotnet ef database update
This will:
  • Create all database tables
  • Apply any existing migrations
  • Set up the schema
Troubleshooting Migrations: If migrations don’t exist:
# Create initial migration
dotnet ef migrations add InitialCreate

# Apply to database
dotnet ef database update
If dotnet ef is not recognized:
# Install EF Core tools globally
dotnet tool install --global dotnet-ef

# Or update existing
dotnet tool update --global dotnet-ef

4. Configure JWT Settings

Edit SolicitudesAPI/appsettings.json:
{
  "Jwt": {
    "SecretKey": "your-secret-key-min-32-characters-long",
    "Issuer": "SolicitudesAPI",
    "Audience": "SolicitudesClient"
  }
}
⚠️ Security Note: Change the SecretKey to a secure, random string. Never commit production secrets to source control.

5. Configure Frontend API URL

Edit Sistema de Seguimiento de Solicitudes/Program.cs:
// Update the BaseAddress to match your API URL
builder.Services.AddScoped(sp => 
    new HttpClient { BaseAddress = new Uri("https://localhost:7123/") });
Note: The port number (7123) should match your API project’s launch settings.

Running the Application

Option 1: Using Visual Studio

Step 1: Set Multiple Startup Projects
  1. Right-click on solution in Solution Explorer
  2. Select “Set Startup Projects”
  3. Choose “Multiple startup projects”
  4. Set both projects to “Start”:
    • SolicitudesAPI
    • Sistema de Seguimiento de Solicitudes
  5. Click OK
Step 2: Run Press F5 or click “Start Debugging” Both projects will launch:
  • API: https://localhost:7123
  • Frontend: https://localhost:7xxx (varies)

Option 2: Using Command Line

Terminal 1 - Start API:
cd SolicitudesAPI
dotnet run
Terminal 2 - Start Frontend:
cd "Sistema de Seguimiento de Solicitudes"
dotnet run

Option 3: Using VS Code

Step 1: Open workspace
code .
Step 2: Create launch configuration Create .vscode/launch.json:
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch API",
      "type": "coreclr",
      "request": "launch",
      "preLaunchTask": "build-api",
      "program": "${workspaceFolder}/SolicitudesAPI/bin/Debug/net9.0/SolicitudesAPI.dll",
      "args": [],
      "cwd": "${workspaceFolder}/SolicitudesAPI",
      "stopAtEntry": false
    },
    {
      "name": "Launch Frontend",
      "type": "coreclr",
      "request": "launch",
      "preLaunchTask": "build-frontend",
      "program": "${workspaceFolder}/Sistema de Seguimiento de Solicitudes/bin/Debug/net9.0/Sistema de Seguimiento de Solicitudes.dll",
      "args": [],
      "cwd": "${workspaceFolder}/Sistema de Seguimiento de Solicitudes",
      "stopAtEntry": false
    }
  ],
  "compounds": [
    {
      "name": "Launch Full Stack",
      "configurations": ["Launch API", "Launch Frontend"]
    }
  ]
}

Accessing the Application

Frontend (Blazor WebAssembly)

URL: https://localhost:[port]
  • Default port varies (check console output)
  • Opens automatically in browser

API (Backend)

URL: https://localhost:7123

API Documentation (Scalar)

URL: https://localhost:7123/scalar/v1
  • Interactive API documentation
  • Test endpoints directly
  • View request/response schemas

Creating Test Users

You’ll need to create initial users to log in.

Option 1: Direct SQL Insert

USE SistemaSolicitudes;

-- Insert admin user (password should be hashed in production)
INSERT INTO Usuarios (NombreUsuario, password, Rol)
VALUES ('admin', 'hashed_password_here', 'Admin');

-- Insert regular user
INSERT INTO Usuarios (NombreUsuario, password, Rol)
VALUES ('usuario', 'hashed_password_here', 'Usuario');
⚠️ Important: Use proper password hashing. Consider using BCrypt, Argon2, or ASP.NET Core Identity.

Option 2: Using API Endpoint

If you have a user registration endpoint, use Postman or curl:
curl -X POST https://localhost:7123/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "nombreUsuario": "admin",
    "password": "SecurePassword123!",
    "rol": "Admin"
  }'

Development Workflow

1. Make Code Changes

  • Frontend changes: Edit .razor, .cs files in Sistema de Seguimiento de Solicitudes
  • Backend changes: Edit controllers, models in SolicitudesAPI
  • Shared changes: Edit DTOs in SolicitudesShared

2. Hot Reload

Both projects support hot reload: Blazor WebAssembly:
  • Save file → Browser refreshes automatically
  • CSS changes apply instantly
ASP.NET Core API:
dotnet watch run
  • Automatically rebuilds on save
  • Restarts server with changes

3. Database Changes

Add new entity or modify existing:
cd SolicitudesAPI

# Create migration
dotnet ef migrations add DescriptionOfChange

# Review migration in Migrations/ folder

# Apply to database
dotnet ef database update

4. Testing API Endpoints

Using Scalar UI:
  1. Navigate to https://localhost:7123/scalar/v1
  2. Find your endpoint
  3. Click “Try it out”
  4. Enter parameters
  5. Execute and view response
Using curl:
# Login
curl -X POST https://localhost:7123/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"nombreUsuario":"admin","password":"password"}'

# Get expedientes (with JWT token)
curl https://localhost:7123/api/expedientes \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Troubleshooting

Port Conflicts

Error: “Address already in use” Solution: Change ports in launchSettings.json: SolicitudesAPI/Properties/launchSettings.json:
{
  "profiles": {
    "https": {
      "applicationUrl": "https://localhost:7124;http://localhost:5124"
    }
  }
}

Database Connection Fails

Error: “Cannot connect to SQL Server” Solutions:
  1. Verify SQL Server is running
  2. Check connection string
  3. Ensure Windows Authentication is enabled
  4. Check firewall settings

CORS Errors

Error: “CORS policy: No ‘Access-Control-Allow-Origin’” Solution: Verify CORS is configured in SolicitudesAPI/Program.cs:
app.UseCors("PermitirBlazor");

Migration Issues

Error: “No migrations found” Solution:
cd SolicitudesAPI
dotnet ef migrations add InitialCreate
dotnet ef database update
Error: “Build failed” Solution: Ensure the API project builds successfully:
dotnet build

Frontend Won’t Connect to API

Check:
  1. API is running
  2. BaseAddress in Program.cs matches API URL
  3. HTTPS certificate is trusted
  4. No firewall blocking connections

Next Steps

Build docs developers (and LLMs) love