using Data.SeaHavenIndustries; using Microsoft.EntityFrameworkCore; using SeaHaven.DataServices.Interfaces; namespace SeaHaven.DataServices.Implementation { public class VendorDocumentDataService : IVendorDocumentDataService { private readonly ApplicationDbContext _context; public VendorDocumentDataService(ApplicationDbContext context) { _context = context; } public Task GetLatestForDispatchAsync(int dispatchId, CancellationToken cancellationToken) { return _context.VendorCompletionDocuments .Where(document => document.DispatchId == dispatchId) .OrderByDescending(document => document.Version) .FirstOrDefaultAsync(cancellationToken); } public Task GetForVendorDispatchAsync(int documentId, int dispatchId, int vendorId, CancellationToken cancellationToken) { return _context.VendorCompletionDocuments .FirstOrDefaultAsync(document => document.Id == documentId && document.DispatchId == dispatchId && document.VendorId == vendorId && (document.IsDeleted == null || document.IsDeleted == false), cancellationToken); } public async Task AddAsync(VendorCompletionDocument document, CancellationToken cancellationToken) { await _context.VendorCompletionDocuments.AddAsync(document, cancellationToken); } public Task SaveChangesAsync(CancellationToken cancellationToken) { return _context.SaveChangesAsync(cancellationToken); } } }