mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 09:33:13 +00:00
Require an authenticated ClaimsPrincipal at service entry and filter tracked work orders with board base scope so deleted/template rows surface as NotFound without disclosure.
44 lines
1.9 KiB
C#
44 lines
1.9 KiB
C#
using Data.SeaHavenIndustries;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using SeaHaven.DataServices.Interfaces;
|
|
|
|
namespace SeaHaven.DataServices.Implementation
|
|
{
|
|
public class WorkOrderMediaDataService : IWorkOrderMediaDataService
|
|
{
|
|
private readonly ApplicationDbContext _context;
|
|
|
|
public WorkOrderMediaDataService(ApplicationDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public Task<WorkOrder?> GetTrackedWorkOrderAsync(int workOrderId, CancellationToken cancellationToken)
|
|
=> _context.workOrders.FirstOrDefaultAsync(
|
|
w => w.Id == workOrderId && w.istemplate != true && (w.IsDeleted != true || w.IsDeleted == null),
|
|
cancellationToken);
|
|
|
|
public Task<WorkOrderAttachments?> GetTrackedAttachmentAsync(int mediaId, int workOrderId, CancellationToken cancellationToken)
|
|
=> _context.workOrderAttachments.FirstOrDefaultAsync(
|
|
a => a.Id == mediaId && a.WorkorderId == workOrderId && a.IsDeleted != true,
|
|
cancellationToken);
|
|
|
|
public void TrackAttachment(WorkOrderAttachments attachment)
|
|
=> _context.workOrderAttachments.Add(attachment);
|
|
|
|
public void SetExpectedWorkOrderVersion(WorkOrder workOrder, byte[] version)
|
|
=> _context.Entry(workOrder).Property(w => w.RowVersion).OriginalValue = version;
|
|
|
|
public void MarkWorkOrderModified(WorkOrder workOrder)
|
|
{
|
|
// Force a WO update so the RowVersion concurrency token is enforced when only
|
|
// attachment rows change (category-only Extra mutations).
|
|
var entry = _context.Entry(workOrder);
|
|
if (entry.State == EntityState.Unchanged)
|
|
entry.Property(w => w.Attachments).IsModified = true;
|
|
}
|
|
|
|
public Task SaveAsync(CancellationToken cancellationToken)
|
|
=> _context.SaveChangesAsync(cancellationToken);
|
|
}
|
|
}
|