Live Dashboard API for Enterprise Cycle Store in ASP.NET Core


Introduction

Modern enterprise cycle stores require real-time insights into inventory, sales, customer orders, product availability, and revenue. A Live Dashboard API allows web applications, mobile apps, POS systems, and admin portals to display updated business data instantly.

In this tutorial, you'll learn how to build a Live Dashboard API using ASP.NET Core Web API that can serve live business metrics to an enterprise cycle store.

Whether you're building an ERP, inventory system, or admin dashboard, this guide will help you create scalable REST APIs using ASP.NET Core.

What You'll Build

By the end of this tutorial, you'll have an API that returns:

  • Total Cycles
  • Available Stock
  • Sold Cycles
  • Total Customers
  • Today's Orders
  • Monthly Revenue
  • Low Stock Products
  • Top Selling Brands
  • Recent Orders

Technology Stack

  • ASP.NET Core 8 Web API
  • Entity Framework Core
  • SQL Server
  • LINQ
  • Swagger
  • Dependency Injection

Project Structure

CycleStore.API
│
├── Controllers
│      DashboardController.cs
│
├── Models
│      Cycle.cs
│      Order.cs
│      Customer.cs
│
├── Services
│      DashboardService.cs
│
├── DTOs
│      DashboardDto.cs
│
├── Data
│      AppDbContext.cs
│
└── Program.cs

Step 1: Create ASP.NET Core Web API

Create a new project.

dotnet new webapi -n CycleStore.API

Run the project.

dotnet run

Open Swagger.

https://localhost:5001/swagger

Step 2: Install Required Packages

Install Entity Framework Core.

dotnet add package Microsoft.EntityFrameworkCore.SqlServer

dotnet add package Microsoft.EntityFrameworkCore.Tools

Step 3: Create Database Models

Cycle.cs

public class Cycle
{
    public int Id { get; set; }

    public string Brand { get; set; }

    public string Model { get; set; }

    public decimal Price { get; set; }

    public int Stock { get; set; }

    public bool IsAvailable { get; set; }
}

Customer.cs

public class Customer
{
    public int Id { get; set; }

    public string Name { get; set; }
}

Order.cs

public class Order
{
    public int Id { get; set; }

    public decimal TotalAmount { get; set; }

    public DateTime OrderDate { get; set; }

    public int CustomerId { get; set; }

    public Customer Customer { get; set; }
}

Step 4: Configure DbContext

public class AppDbContext : DbContext
{
    public AppDbContext(DbContextOptions<AppDbContext> options)
        : base(options)
    {
    }

    public DbSet<Cycle> Cycles { get; set; }

    public DbSet<Customer> Customers { get; set; }

    public DbSet<Order> Orders { get; set; }
}

Step 5: Register Database

In Program.cs

builder.Services.AddDbContext<AppDbContext>(options =>
    options.UseSqlServer(
        builder.Configuration.GetConnectionString("DefaultConnection")));

Step 6: Create Dashboard DTO

public class DashboardDto
{
    public int TotalCycles { get; set; }

    public int AvailableStock { get; set; }

    public int TotalCustomers { get; set; }

    public int Today'sOrders { get; set; }

    public decimal MonthlyRevenue { get; set; }
}

Step 7: Create Dashboard Service

public class DashboardService
{
    private readonly AppDbContext _context;

    public DashboardService(AppDbContext context)
    {
        _context = context;
    }

    public DashboardDto GetDashboard()
    {
        return new DashboardDto
        {
            TotalCycles = _context.Cycles.Count(),

            AvailableStock = _context.Cycles.Sum(x => x.Stock),

            TotalCustomers = _context.Customers.Count(),

            Today'sOrders = _context.Orders
                .Count(x => x.OrderDate.Date == DateTime.Today),

            MonthlyRevenue = _context.Orders
                .Where(x => x.OrderDate.Month == DateTime.Today.Month)
                .Sum(x => x.TotalAmount)
        };
    }
}

Step 8: Register Service

builder.Services.AddScoped<DashboardService>();

Step 9: Create Dashboard Controller

[ApiController]
[Route("api/dashboard")]
public class DashboardController : ControllerBase
{
    private readonly DashboardService _dashboard;

    public DashboardController(DashboardService dashboard)
    {
        _dashboard = dashboard;
    }

    [HttpGet]
    public IActionResult Get()
    {
        return Ok(_dashboard.GetDashboard());
    }
}

Step 10: Test the API

Request

GET /api/dashboard

Response

{
  "totalCycles": 350,
  "availableStock": 1210,
  "totalCustomers": 430,
  "todayOrders": 24,
  "monthlyRevenue": 358900
}

Step 11: Add More Dashboard Widgets

You can expand the API with additional endpoints such as:

  • Top Selling Cycle Brands
  • Low Stock Products
  • Daily Revenue
  • Weekly Sales
  • Monthly Sales Graph
  • Pending Orders
  • Completed Orders
  • Cancelled Orders
  • New Customers
  • Out of Stock Products

Step 12: Improve Performance

For enterprise applications:

  • Use asynchronous APIs (async/await).
  • Add response caching.
  • Optimize database queries with indexes.
  • Use pagination for large datasets.
  • Implement authentication with JWT.
  • Apply role-based authorization.
  • Add logging using Serilog.
  • Monitor API health with Health Checks.

Step 13: Secure the Dashboard API

Security best practices include:

  • JWT Authentication
  • HTTPS
  • Role-based authorization
  • Rate limiting
  • Input validation
  • SQL injection prevention through Entity Framework Core
  • API versioning

Expected Dashboard Output

A typical enterprise dashboard can display:

  • Revenue
  • Sales
  • Inventory
  • Customers
  • Orders
  • Best Selling Products
  • Brand-wise Sales
  • Monthly Reports
  • Product Availability
  • Order Status

Conclusion

A Live Dashboard API is the backbone of any enterprise cycle store management system. By leveraging ASP.NET Core Web API and Entity Framework Core, you can build scalable, secure, and high-performance APIs that deliver real-time business insights.

As your application grows, consider integrating SignalR for live updates, Redis for distributed caching, and background jobs for analytics processing. These enhancements will provide an even richer dashboard experience for administrators and business managers.

0 Comments Report