mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 18:53:12 +00:00
48 lines
1.7 KiB
C#
48 lines
1.7 KiB
C#
|
|
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<WorkOrder?> 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<IReadOnlyList<Contacts>> GetSiteContactsAsync(
|
||
|
|
int? locationId,
|
||
|
|
CancellationToken cancellationToken)
|
||
|
|
{
|
||
|
|
if (locationId == null)
|
||
|
|
return Array.Empty<Contacts>();
|
||
|
|
|
||
|
|
return await _context.Contacts
|
||
|
|
.AsNoTracking()
|
||
|
|
.Where(c => c.LocationId == locationId && c.IsDeleted != true)
|
||
|
|
.OrderBy(c => c.SiteContactOrder)
|
||
|
|
.ThenBy(c => c.Id)
|
||
|
|
.ToListAsync(cancellationToken);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|