using Microsoft.EntityFrameworkCore; using PowderCoating.Core.Entities; using PowderCoating.Core.Interfaces.Repositories; using PowderCoating.Infrastructure.Data; namespace PowderCoating.Infrastructure.Repositories; /// /// Typed repository for that provides domain-specific multi-level /// include queries that the generic cannot express. /// The base class handles all standard CRUD operations; this class adds the read queries /// that require ThenInclude chains for items, coats, and prep services. /// public class JobTemplateRepository : Repository, IJobTemplateRepository { public JobTemplateRepository(ApplicationDbContext context) : base(context) { } /// public async Task LoadForDetailsAsync(int id) { return await _context.JobTemplates .Where(t => t.Id == id && !t.IsDeleted) .Include(t => t.Customer) .Include(t => t.Items.Where(i => !i.IsDeleted)) .ThenInclude(i => i.Coats.Where(c => !c.IsDeleted)) .ThenInclude(c => c.InventoryItem) .Include(t => t.Items.Where(i => !i.IsDeleted)) .ThenInclude(i => i.PrepServices.Where(p => !p.IsDeleted)) .ThenInclude(p => p.PrepService) .FirstOrDefaultAsync(); } /// public async Task> GetAllActiveWithFullIncludesAsync() { return await _context.JobTemplates .Where(t => !t.IsDeleted && t.IsActive) .Include(t => t.Customer) .Include(t => t.Items.Where(i => !i.IsDeleted)) .ThenInclude(i => i.Coats.Where(c => !c.IsDeleted)) .Include(t => t.Items.Where(i => !i.IsDeleted)) .ThenInclude(i => i.PrepServices.Where(p => !p.IsDeleted)) .ThenInclude(p => p.PrepService) .OrderBy(t => t.Name) .ToListAsync(); } }