shoc-backend/SeaHaven.Services/Implementation/WorkOrderFieldLockService.cs

38 lines
1.2 KiB
C#
Raw Normal View History

using Data.SeaHavenIndustries;
using Microsoft.EntityFrameworkCore;
using SeaHaven.Services.Interfaces;
namespace SeaHaven.Services.Implementation
{
public class WorkOrderFieldLockService : IWorkOrderFieldLockService
{
private readonly ApplicationDbContext _context;
public WorkOrderFieldLockService(ApplicationDbContext context)
{
_context = context;
}
public async Task<bool> IsLockedAsync(int workOrderId, string fieldName)
{
return await _context.WorkOrderFieldLocks
.AnyAsync(l => l.WorkOrderId == workOrderId && l.FieldName == fieldName);
}
public async Task LockFieldAsync(int workOrderId, string fieldName, string? userId)
{
var exists = await IsLockedAsync(workOrderId, fieldName);
if (exists) return;
_context.WorkOrderFieldLocks.Add(new WorkOrderFieldLock
{
WorkOrderId = workOrderId,
FieldName = fieldName,
LockedAt = DateTime.UtcNow,
LockedByUserId = userId
});
await _context.SaveChangesAsync();
}
}
}