52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
using Microsoft.EntityFrameworkCore;
|
||
using PARR.DAL.Services.Interfaces.Job;
|
||
using PARR.DAL.Services.Interfaces.Unit;
|
||
|
||
namespace PARR.TemplateGeneratorWorker.Services
|
||
{
|
||
internal class ValidatorService : IValidatorService
|
||
{
|
||
private readonly ILogger<ValidatorService> logger;
|
||
private readonly IJobService jobService;
|
||
private readonly IUnitService unitService;
|
||
|
||
public ValidatorService(
|
||
ILogger<ValidatorService> logger,
|
||
IJobService jobService,
|
||
IUnitService unitService
|
||
)
|
||
{
|
||
this.logger = logger;
|
||
this.jobService = jobService;
|
||
this.unitService = unitService;
|
||
}
|
||
|
||
|
||
public async Task<bool> IsValidAsync(Guid jobId, Guid unitId)
|
||
{
|
||
|
||
var job = await jobService
|
||
.Get().AsNoTracking()
|
||
.FirstOrDefaultAsync(t => t.Id == jobId);
|
||
|
||
if (job == null)
|
||
{
|
||
logger.LogError($"Не найдена регалментная работа {nameof(jobId)}: {jobId}");
|
||
return false;
|
||
}
|
||
|
||
var unit = await unitService
|
||
.Get().AsNoTracking()
|
||
.FirstOrDefaultAsync(t => t.Id == unitId);
|
||
|
||
if (unit == null)
|
||
{
|
||
logger.LogError($"Не найден элемент конфигурации {nameof(unitId)}: {unitId}");
|
||
return false;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
}
|
||
}
|