Skip to content

Repository files navigation

Sample CRM App

A small customer relationship management (CRM) web application built with ASP.NET Core 8 and Blazor (interactive server). It supports multiple users (team or solo use): sign-in with email and password, then manage customers, opportunities, interactions, and support tickets with threaded ticket responses. Administrators can create additional users from the Users screen.


Interface

The dashboard gives a high-level overview with a sidebar for navigating between customers, opportunities, interactions, support tickets, and user administration.

Sample CRM dashboard showing summary cards and the navigation sidebar


Features

  • Authentication — Cookie-based sign-in backed by the Users table (passwords stored as PBKDF2 hashes via PasswordHasher).
  • Password visibility — On Sign in and on Admin → Users when creating a user, the password field includes an in-field eye icon to show or hide what you type. Toggle uses Blazor interactive server and inline SVG (no separate icon font required).
  • RolesAdmin and Agent (AppRoles). Admins see Users in the nav and can assign support tickets to agents on ticket detail; agents see a read-only note for assignment.
  • Dashboard — High-level counts (customers, open opportunities, open tickets, recent interactions).
  • CRM areas — Customers (CRUD + detail with related counts), Opportunities (CRUD, customer + optional assigned rep), Interactions (log and filter by customer), Support tickets (create, list, detail with status updates and responses).
  • Database — Entity Framework Core with SQL Server; schema matches the CRM ERD (GUID keys, nullable Interactions.OpportunityId, etc.).

Prerequisites

Requirement Notes
.NET 8 SDK Required to build and run the app. Verify with dotnet --version (8.x).
Docker & Docker Compose Used to run SQL Server 2022 locally. Optional if you already have SQL Server and a matching database.
SQL Server Default setup expects localhost:1433, database SampleCRMDB, login sa (see appsettings.json and docker-compose.yml).

Optional:

  • dotnet-ef — For creating new migrations. This repo includes a local tool manifest under .config/dotnet-tools.json; use dotnet tool restore then dotnet tool run dotnet-ef (see below).

Quick start

1. Start SQL Server (Docker)

From the repository root:

docker compose up -d

Wait until the mssql service is healthy. The mssql-init service creates the SampleCRMDB database if it does not exist.

Default SQL credentials (development only):

  • User: sa
  • Password: SampleCRM_Sa1!
  • Port: 1433
  • Database: SampleCRMDB

Change these in production and update ConnectionStrings:DefaultConnection accordingly.

2. Run the web app

dotnet restore
dotnet run

Or open the project in Visual Studio / Rider / VS Code and run the https or http profile.

Typical URLs (see Properties/launchSettings.json):

  • HTTPS: https://localhost:7273
  • HTTP: http://localhost:5179

3. Sign in

On first run, the app applies EF Core migrations and seeds a default admin if no users exist:

Field Value
Email admin@samplecrm.local
Password Admin123!

Click the eye inside the password box to reveal or mask the password. The same control appears when an admin sets a new user’s password on Admin → Users.

Use Admin → Users (admin only) to create more accounts (Admin or Agent).


Configuration

  • Connection string: ConnectionStrings:DefaultConnection in appsettings.json and appsettings.Development.json.
  • Cookie name / session: Configured in Program.cs (SampleCRM.Auth, sliding 8-hour expiration).
  • Authorization: A fallback policy requires an authenticated user; Login and Error allow anonymous access.
  • Sign-in page render mode: Login.razor uses @rendermode InteractiveServer so the password show/hide control can run Blazor events while the form still posts to AccountController for authentication.

For secrets in real deployments, prefer User Secrets, environment variables, or a secret store—not committed JSON files.


Database schema

The app uses SQL Server with database SampleCRMDB. Tables and columns are created by EF Core migrations; names and types below match the model in Data/ApplicationDbContext.cs and Data/Entities/.

Entity relationship overview

erDiagram
    Customers ||--o{ Opportunities : has
    Customers ||--o{ Interactions : has
    Customers ||--o{ SupportTickets : has
    Users ||--o{ Interactions : creates
    Users ||--o{ Opportunities : assigned_to
    Users ||--o{ SupportTickets : assigned_to
    Users ||--o{ TicketResponses : creates
    Opportunities ||--o{ Interactions : has
    SupportTickets ||--o{ TicketResponses : has

    Customers {
        uniqueidentifier CustomerId PK
        nvarchar FirstName
        nvarchar LastName
        nvarchar Email
        nvarchar Phone
        nvarchar CompanyName
        datetime2 CreatedAt
        datetime2 UpdatedAt
    }

    Users {
        uniqueidentifier UserId PK
        nvarchar Name
        nvarchar Email
        nvarchar Role
        bit Active
        datetime2 CreatedAt
        nvarchar PasswordHash
    }

    Opportunities {
        uniqueidentifier OpportunityId PK
        uniqueidentifier CustomerId FK
        nvarchar Title
        nvarchar Status
        decimal ExpectedValue
        date CloseDate
        uniqueidentifier AssignedRepId FK
        datetime2 CreatedAt
        datetime2 UpdatedAt
    }

    Interactions {
        uniqueidentifier InteractionId PK
        uniqueidentifier CustomerId FK
        uniqueidentifier OpportunityId FK
        uniqueidentifier UserId FK
        nvarchar Type
        nvarchar Subject
        nvarchar Details
        datetime2 Timestamp
    }

    SupportTickets {
        uniqueidentifier TicketId PK
        uniqueidentifier CustomerId FK
        nvarchar Subject
        nvarchar Description
        nvarchar Status
        nvarchar Priority
        uniqueidentifier AssignedAgentId FK
        datetime2 CreatedAt
        datetime2 UpdatedAt
        datetime2 ClosedAt
    }

    TicketResponses {
        uniqueidentifier ResponseId PK
        uniqueidentifier TicketId FK
        uniqueidentifier UserId FK
        nvarchar Message
        datetime2 Timestamp
    }
Loading

Database and EF Core

Add a new migration (optional)

cd /path/to/SampleCRMApp
dotnet tool restore
dotnet tool run dotnet-ef migrations add YourMigrationName --output-dir Data/Migrations

Design-time factory: Data/ApplicationDbContextFactory.cs (uses the same dev connection string as Docker defaults).


Project structure (high level)

SampleCRMApp/
├── Components/           # Blazor UI (pages, layout, routes)
│   ├── Layout/
│   ├── Pages/          # Dashboard, Customers, Opportunities, Interactions, Tickets, Admin/Users, Account/Login
│   └── Routes.razor    # AuthorizeRouteView + redirects
├── Controllers/        # AccountController (login POST, logout GET)
├── Data/               # DbContext, entities, migrations, seeding
├── Services/           # Auth state provider, IUserContext
├── wwwroot/            # Static assets (CSS, Bootstrap)
├── Program.cs          # DI, pipeline, cookie auth, Blazor
├── docker-compose.yml  # SQL Server + DB init
└── appsettings*.json

Security notes (important)

  • Default SQL and app passwords are for local development only.
  • Login uses anti-forgery tokens; MVC is registered with AddControllersWithViews() so [ValidateAntiForgeryToken] works on AccountController.
  • HTTPS is recommended; the dev profile enables both HTTP and HTTPS.

Troubleshooting

Issue What to check
Cannot connect to SQL Docker is running, docker compose ps, port 1433 not used by another instance, firewall.
Login / antiforgery errors Ensure you are on a current build; controllers use AddControllersWithViews().
Empty database / no tables Run the app once so DbInitializer runs migrations; check Docker logs for SQL errors.
Wrong URL Match launchSettings.json or the URL printed in the console when you dotnet run.

License

No license is specified in this repository; add one if you intend to distribute or open-source the project.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages