1cb7a8ca4a
Phase 3 — eliminated ApplicationDbContext from all non-exempt controllers, routing all data access through IUnitOfWork. Added IPlainRepository<T> for the four platform entities (Announcement, BannedIp, DashboardTip, ReleaseNote) that intentionally don't extend BaseEntity and therefore can't use the constrained IRepository<T>. Added permanent-exception comments to the 18 controllers that legitimately retain direct DbContext access (Identity infra, cross-tenant platform ops, bulk streaming exports). Phase 4 — added EnforceDataAccessArchitecture() to Program.cs, a startup gate that reflects over every Controller subclass and throws at boot if any non-exempt controller injects ApplicationDbContext. The app cannot start with a violation. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
48 lines
2.0 KiB
C#
48 lines
2.0 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using PowderCoating.Core.Entities;
|
|
using PowderCoating.Core.Interfaces.Repositories;
|
|
using PowderCoating.Infrastructure.Data;
|
|
|
|
namespace PowderCoating.Infrastructure.Repositories;
|
|
|
|
/// <summary>
|
|
/// Typed repository for <see cref="JobTemplate"/> that provides domain-specific multi-level
|
|
/// include queries that the generic <see cref="Repository{T}"/> 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.
|
|
/// </summary>
|
|
public class JobTemplateRepository : Repository<JobTemplate>, IJobTemplateRepository
|
|
{
|
|
public JobTemplateRepository(ApplicationDbContext context) : base(context) { }
|
|
|
|
/// <inheritdoc/>
|
|
public async Task<JobTemplate?> 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();
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public async Task<List<JobTemplate>> 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();
|
|
}
|
|
}
|