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
|
|
|
|
|
|
|
|
|
|
public Task<List<UnitInUnit>> GetByParentIdAsync(Guid parentId)
|
|
|
|
|
|
{
|
|
|
|
|
|
return dataContext.UnitInUnits
|
|
|
|
|
|
.Where(u => u.ParentUnitId == parentId)
|
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-19 19:15:58 +10:00
|
|
|
|
|
2025-12-09 16:50:35 +10:00
|
|
|
|
public Task<List<UnitInUnit>> GetByChildIdAsync(Guid childId)
|
|
|
|
|
|
{
|
|
|
|
|
|
return dataContext.UnitInUnits
|
|
|
|
|
|
.Where(u => u.ChildUnitId == childId)
|
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
}
|
2025-12-15 11:50:12 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<List<UnitInUnit>> GetParentLinksByChildIdsAsync(IEnumerable<Guid> childUnitIds)
|
|
|
|
|
|
{
|
|
|
|
|
|
var set = childUnitIds.ToHashSet();
|
|
|
|
|
|
return await dataContext.UnitInUnits
|
|
|
|
|
|
.AsNoTracking()
|
|
|
|
|
|
.Where(uinu => set.Contains(uinu.ChildUnitId))
|
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<List<UnitInUnit>> GetChildLinksByParentIdsAsync(IEnumerable<Guid> parentUnitIds)
|
|
|
|
|
|
{
|
|
|
|
|
|
var set = parentUnitIds.ToHashSet();
|
|
|
|
|
|
return await dataContext.UnitInUnits
|
|
|
|
|
|
.AsNoTracking()
|
|
|
|
|
|
.Where(uinu => set.Contains(uinu.ParentUnitId))
|
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
}
|
2025-12-09 16:50:35 +10:00
|
|
|
|
}
|
|
|
|
|
|
}
|