mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 08:23:12 +00:00
40 lines
1.4 KiB
C#
40 lines
1.4 KiB
C#
using Data.SeaHavenIndustries;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using SeaHaven.DataServices.Interfaces;
|
|
|
|
namespace SeaHaven.DataServices.Implementation
|
|
{
|
|
public class DashboardDataService : IDashboardDataService
|
|
{
|
|
private readonly ApplicationDbContext _context;
|
|
|
|
public DashboardDataService(ApplicationDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public async Task<DashboardCounts> GetWorkOrderCountsAsync(
|
|
int? accountId,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
var query = _context.workOrders.Where(w => w.istemplate != true);
|
|
if (accountId is int scopedAccountId)
|
|
{
|
|
query = query.Where(w => w.AccountId == scopedAccountId);
|
|
}
|
|
|
|
var total = await query.CountAsync(cancellationToken);
|
|
var open = await query.CountAsync(w => w.Status == "Open" || w.Status == "In Progress" || w.Status == "On Hold", cancellationToken);
|
|
var notDispatched = await query.CountAsync(w => (w.Status == "Open") && (w.AssignTo == null || w.AssignTo == ""), cancellationToken);
|
|
var completed = await query.CountAsync(w => w.Status == "Done", cancellationToken);
|
|
|
|
return new DashboardCounts
|
|
{
|
|
Total = total,
|
|
Open = open,
|
|
NotDispatched = notDispatched,
|
|
Completed = completed
|
|
};
|
|
}
|
|
}
|
|
}
|