2025-12-09 16:50:35 +10:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
2026-04-30 10:35:31 +10:00
|
|
|
|
using PARR.Core.Repositories.Interfaces.Unit;
|
2025-12-09 16:50:35 +10:00
|
|
|
|
using PARR.DAL.Context;
|
2026-04-30 10:35:31 +10:00
|
|
|
|
using PARR.Domain.Entities.Unit;
|
2025-12-09 16:50:35 +10:00
|
|
|
|
|
2026-04-30 10:35:31 +10:00
|
|
|
|
namespace PARR.DAL.Repositories.Unit
|
2025-12-09 16:50:35 +10:00
|
|
|
|
{
|
2026-04-30 10:35:31 +10:00
|
|
|
|
internal class UnitInUnitRepository : IUnitInUnitRepository
|
2025-12-09 16:50:35 +10:00
|
|
|
|
{
|
|
|
|
|
|
private readonly DataContext dataContext;
|
2026-04-30 10:35:31 +10:00
|
|
|
|
private readonly ILogger<UnitInUnitRepository> logger;
|
2025-12-09 16:50:35 +10:00
|
|
|
|
|
2026-04-30 10:35:31 +10:00
|
|
|
|
public UnitInUnitRepository(
|
2025-12-09 16:50:35 +10:00
|
|
|
|
DataContext dataContext,
|
2026-04-30 10:35:31 +10:00
|
|
|
|
ILogger<UnitInUnitRepository> logger
|
2025-12-09 16:50:35 +10:00
|
|
|
|
)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.dataContext = dataContext;
|
|
|
|
|
|
this.logger = logger;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-12-19 19:15:58 +10:00
|
|
|
|
public IQueryable<UnitInUnit> Get()
|
|
|
|
|
|
{
|
|
|
|
|
|
return dataContext.UnitInUnits;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-09 16:50:35 +10:00
|
|
|
|
|
2026-07-31 10:46:48 +10:00
|
|
|
|
public async Task<List<Guid>> GetRelatedUnitIdsAsync(Guid unitId, CancellationToken ct = default)
|
2025-12-09 16:50:35 +10:00
|
|
|
|
{
|
2026-07-31 10:46:48 +10:00
|
|
|
|
return await Get()
|
2025-12-15 11:50:12 +10:00
|
|
|
|
.AsNoTracking()
|
2026-07-31 10:46:48 +10:00
|
|
|
|
.Where(link => link.ChildUnitId == unitId || link.ParentUnitId == unitId)
|
|
|
|
|
|
.Select(link => link.ChildUnitId == unitId ? link.ParentUnitId : link.ChildUnitId)
|
|
|
|
|
|
.Distinct()
|
|
|
|
|
|
.ToListAsync(ct);
|
2025-12-15 11:50:12 +10:00
|
|
|
|
}
|
2025-12-09 16:50:35 +10:00
|
|
|
|
}
|
|
|
|
|
|
}
|