using Data.SeaHavenIndustries; using Microsoft.EntityFrameworkCore; using SeaHaven.DataServices.Interfaces; namespace SeaHaven.DataServices.Implementation { public class WorkOrderPocDataService : IWorkOrderPocDataService { private readonly ApplicationDbContext _context; public WorkOrderPocDataService(ApplicationDbContext context) { _context = context; } public Task GetTrackedWorkOrderAsync( int workOrderId, int? accountId, CancellationToken cancellationToken) => _context.workOrders .Include(workOrder => workOrder.Locations!) .ThenInclude(location => location.Contacts) .Include(workOrder => workOrder.WorkOrderContacts!) .ThenInclude(contact => contact.POC) .FirstOrDefaultAsync( w => w.Id == workOrderId && w.istemplate != true && (w.IsDeleted != true || w.IsDeleted == null) && (accountId == null || w.AccountId == accountId), cancellationToken); public async Task> GetSiteContactsAsync( int? locationId, CancellationToken cancellationToken) { if (locationId == null) return Array.Empty(); return await _context.Contacts .AsNoTracking() .Where(c => c.LocationId == locationId && c.IsDeleted != true) .OrderBy(c => c.SiteContactOrder) .ThenBy(c => c.Id) .ToListAsync(cancellationToken); } } }