mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 11:53:12 +00:00
39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
using Data.SeaHavenIndustries;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Api.SeaHavenIndustries.Controllers
|
|
{
|
|
[Authorize]
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class DashboardController : Controller
|
|
{
|
|
private readonly ApplicationDbContext _db;
|
|
|
|
public DashboardController(ApplicationDbContext db)
|
|
{
|
|
_db = db;
|
|
}
|
|
|
|
[HttpGet("Stats")]
|
|
public async Task<IActionResult> GetStats()
|
|
{
|
|
var query = _db.workOrders.Where(w => w.istemplate != true);
|
|
|
|
var total = await query.CountAsync();
|
|
var open = await query.CountAsync(w => w.Status == "Open" || w.Status == "In Progress" || w.Status == "On Hold");
|
|
var notDispatched = await query.CountAsync(w => (w.Status == "Open") && (w.AssignTo == null || w.AssignTo == ""));
|
|
var completed = await query.CountAsync(w => w.Status == "Done");
|
|
|
|
return Ok(new
|
|
{
|
|
total,
|
|
open,
|
|
notDispatched,
|
|
completed
|
|
});
|
|
}
|
|
}
|
|
}
|