Files
parr_api/PARR.TemplateGeneratorWorker/Services/ValidatorService.cs

52 lines
1.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
}
}
}