Files

51 lines
2.1 KiB
C#
Raw Permalink 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 Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using PARR.Core.Repositories.Interfaces.JobGroupRepositories;
using PARR.Domain.Entities.JobGroupEntities;
namespace PARR.TemplateDistributor.Services
{
internal class ValidatorService : IValidatorService
{
private readonly IServiceProvider serviceProvider;
private readonly ILogger<ValidatorService> logger;
public ValidatorService(IServiceProvider serviceProvider,
ILogger<ValidatorService> logger
)
{
this.serviceProvider = serviceProvider;
this.logger = logger;
}
public async Task<bool> IsValidJobGroupAsync(Guid jobGroupId)
{
using (var scope = serviceProvider.CreateScope())
{
var service = scope.ServiceProvider.GetService<IJobGroupRepository>();
if (service == null)
throw new Exception($"Не найден сервис: {nameof(IJobGroupRepository)}");
var jobGroup = await service.Get().Include(t => t.DistributionConfig).FirstOrDefaultAsync(t => t.Id == jobGroupId);
if (jobGroup == null)
{
logger.LogError($"Не найдена группа работ с Id: {jobGroupId}", jobGroupId);
return false;
}
if (!jobGroup.IsAutoDistributionEnabled || jobGroup.DistributionConfig == null)
{
logger.LogError("Для группы работ {jobGroupId} отсутствуют настройки автораспределения. " +
"IsAutoDistributionEnabled: {IsAutoDistributionEnabled}, есть настройки в таблице {DistributionConfig}, {existConfig}", jobGroupId, jobGroup.IsAutoDistributionEnabled, nameof(JobGroupDistributionConfig), jobGroup.DistributionConfig != null);
return false;
}
return true;
}
}
}
}