using Data.SeaHavenIndustries; using Microsoft.EntityFrameworkCore; using SeaHaven.DataServices.Interfaces; namespace SeaHaven.DataServices.Implementation { public class QuotesDataService : IQuotesDataService { private readonly ApplicationDbContext _context; public QuotesDataService(ApplicationDbContext context) { _context = context; } public async Task GetByIdAsync(int id) { return await _context.Quotes.FindAsync(id); } public async Task> GetAllAsync() { return await _context.Quotes.ToListAsync(); } public async Task> GetByWorkOrderIdAsync(int workOrderId) { return await _context.Quotes .Where(q => q.WorkorderId == workOrderId) .ToListAsync(); } public async Task AddAsync(Quotes quote) { await _context.Quotes.AddAsync(quote); await _context.SaveChangesAsync(); return quote; } public async Task UpdateAsync(Quotes quote) { _context.Quotes.Update(quote); await _context.SaveChangesAsync(); } public async Task DeleteAsync(int id) { var entity = await GetByIdAsync(id); if (entity != null) { _context.Quotes.Remove(entity); await _context.SaveChangesAsync(); } } public async Task ExistsAsync(int id) { return await _context.Quotes.AnyAsync(q => q.Id == id); } public async Task UnlinkFromWorkOrderAsync(int workOrderId) { var quotes = await _context.Quotes .Where(q => q.WorkorderId == workOrderId) .ToListAsync(); foreach (var quote in quotes) { quote.WorkorderId = null; } await _context.SaveChangesAsync(); } } }